In this example, we will create and activate 1G of swap. To create a bigger swap, replace 1G with the size of the desired swap space.
First create a file which will be used for swap:
sudo fallocate -l 1G /swapfile
If fallocate is not installed or you get an error message saying fallocate failed: Operation not supported you can use the following command to create the swap file:
sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576
Only the root user should be able to read and write to the swap file. Issue the command below to set the correct permissions :
sudo chmod 600 /swapfile
Use the mkswap tool to set up a Linux swap area on the file:
sudo mkswap /swapfile
Activate the swap file:
sudo swapon /swapfile
To make the change permanent open the /etc/fstab file:
sudo nano /etc/fstab
and paste the following line:
/swapfile swap swap defaults 0 0
Verify whether the swap is active using either the swapon or free command as shown below:
sudo free -h
sudo swapon --show
NAME TYPE SIZE USED PRIO
/swapfile file 1024M 507.4M -1Copy
First create a file which will be used for swap:
sudo fallocate -l 1G /swapfile
If fallocate is not installed or you get an error message saying fallocate failed: Operation not supported you can use the following command to create the swap file:
sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576
Only the root user should be able to read and write to the swap file. Issue the command below to set the correct permissions :
sudo chmod 600 /swapfile
Use the mkswap tool to set up a Linux swap area on the file:
sudo mkswap /swapfile
Activate the swap file:
sudo swapon /swapfile
To make the change permanent open the /etc/fstab file:
sudo nano /etc/fstab
and paste the following line:
/swapfile swap swap defaults 0 0
Verify whether the swap is active using either the swapon or free command as shown below:
sudo free -h
sudo swapon --show
NAME TYPE SIZE USED PRIO
/swapfile file 1024M 507.4M -1Copy
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
mcedit /etc/fstab
/swapfile none swap sw 0 0