SWAP

Change swap size in Ubuntu 18.04

In the following example, we’ll extend the swap space available in the /swapfile from 4 GB to 8 GB.

1.We can see if the system has any configured swap by typing:

sudo swapon --show

2.Turn off all swap processes

sudo swapoff -a

3.Creating a Swap File

sudo fallocate -l 1G /swapfile

For CentOS:

sudo dd if=/dev/zero of=/myswap count=4096 bs=1MiB

Verify that the correct amount of space was reserved by typing:

ls -lh /swapfile

4. Enabling the Swap File

sudo chmod 600 /swapfile

Verify the permissions change by typing:

ls -lh /swapfile

mark the file as swap space by typing:

sudo mkswap /swapfile

enable the swap file, allowing our system to start utilizing it:

sudo swapon /swapfile

Last updated

Was this helpful?