Wednesday, May 16, 2012

Adding swap space on CentOS

# login as root with
su -

# not '-' sign - important!

#allocate file: 20 GB = 20 * 1024 * 1024
dd if=/dev/zero of=/swapfile bs=1024 count=20971520

mkswap /swapfile

#set permissions:
chown root:root /swapfile
chmod 0600 /swapfile

#add immediately to OS
swapon /swapfile

# edit fstab for persistence:
vi /etc/fstab

# edit fstab by adding the following line at the end of the file:
/swapfile /swap swap defaults 0 0

# check if the swap is allocated
free -m

No comments: