User Tools

Site Tools


os:linux:create_swap_file

This is an old revision of the document!


Table of Contents

Linux: Create Swap File

Short

fallocate -l 1G /swapfile
mkswap /swapfile
swapon /swapfile
vi /etc/fstab
swapfile swap swap defaults 0 0

Long

Create File (eg. size 1GB).

root@server:~# fallocate -l 1G /swapfile

Set permissions.

root@server:~# chmod 0600 /swapfile

Set up swap space.

root@server:~# mkswap /swapfile
mkswap: /swapfile: insecure permissions 0644, 0600 suggested.
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
no label, UUID=2903a264-5dc1-484c-8e1d-b0b6f687e65a

Activate Swap space.

root@server:~# swapon /swapfile

Edit fstab

root@server:~# vim /etc/fstab

add:

/swapfile          none            swap    sw                0       0
os/linux/create_swap_file.1517994228.txt.gz · Last modified: 2018-02-07 10:03 by root