Skip to content

How to add SWAP partition on CentOS

homepage-banner

Task: Add a 1GB SWAP partition and mount it automatically at boot

Create a SWAPFILE in the /var directory

dd if=/dev/zero of=/var/SWAPFILE bs=1k count=1024000

Set up the SWAP partition

mkswap /var/SWAPFILE

Activate the SWAP partition

swapon /var/SWAPFILE

Mount the SWAP partition at boot: edit /etc/fstab and add the following line at the end

/var/SWAPFILE swap swap defaults 0 0
  • Check the status of the SWAP partition.
  • To stop the SWAP partition, run:
swapoff /var/SWAPFILE
  • To delete the SWAP file, remove the corresponding line in /etc/fstab.
Leave your message