Swapfile

You can start and check if swap space is already activated on your system.

$ sudo swapon --show

If you do not get back any output, this means your system does not have swap space available currently.

Use the dd command to create a swap file on the root file system, where “bs” is the block size and “count” is the number of blocks. In this example the swap file is 2 GB:

$ sudo dd if=/dev/zero of=/swapfile bs=1M count=2048

Update the read and write permissions for the swap file:

$ sudo chmod 600 /swapfile

Set up a Linux swap area:

$ sudo mkswap /swapfile

Make the swap file available for immediate use by adding the swap file to swap space:

$ sudo swapon /swapfile

Verify that the procedure was successful:

$ swapon -s

Enable the swap file at boot time by editing the /etc/fstab file:

$ sudo vi /etc/fstab

Add:

/swapfile swap swap defaults 0 0

Enable swap:

$ sudo swapon -a

Check it with:

$ sudo swapon --show