Add Swap to CentOS
For Centos 6
See what size swap is
[[email protected]]# free -m
or
[[email protected]]# swapon -s
Create directory
[[email protected]]# mkdir /home/swap
Create a swap file
[[email protected]]# fallocate -l 12G /home/swap/swap.img
Checking
[[email protected]]# ls -alh /home/swap/swap.img
Assigning rights
[[email protected]]# chmod 600 /home/swap/swap.img
Create swap space
[[email protected]]# mkswap /home/swap/swap.img
Turn on the swap file
[[email protected]]# swapon /home/swap/swap.img
Checking
[[email protected]]# swapon -s
Adding the swap file to startup
[[email protected]]# nano /etc/fstab
/home/swap/swap.img swap swap defaults 0 0
To turn off this swap file
[[email protected]]# swapoff /home/captain/swap/swap.img
Checking
[[email protected]]# swapon -s
For Centos 7
See what size swap is
[[email protected]]# free -m
or
[[email protected]]# swapon -s
Create a 12 Gb file
[[email protected]]# dd if=/dev/zero of=/swapfile bs=1M count=12288
Create swap space
[[email protected]]# mkswap /swapfile
Assigning rights
[[email protected]]# chmod 600 /swapfile
Turn on the swap file
[[email protected]]# swapon /swapfile
Adding the swap file to startup
[[email protected]]# nano /etc/fstab
/swapfile swap swap defaults 0 0
To turn off this swap file
[[email protected]]# swapoff /swapfile
Checking
[[email protected]]# swapon -s