Friday, November 25, 2011

Add file type swap to linux

To add swap to linux machine:

1. Create a swap file. Size depends on your preference. Let's say we want to create a swap file with 8GB size (1024 x 1024 x 8 = 8388608).

# dd if=/dev/zero of=/swapfile bs=1024 count=8388608
where if is source, of is output file for dd to write to which is /swapfile in this case, bs is read/write byte size at a time and count is number of blocks.

2. Once created, make it a swap file
# mkswap /swapfile
3. Activate your swap file
# swapon /swapfile
4. Check your newly created swap space using free or top
# free -m
# top
5. To make it appear even after reboot, put it into fstab
# echo "swapfile swap swap defaults 0 0" >> /etc/fstab
It will look like this:
# cat /etc/fstab 
/swapfile1 swap swap defaults 0 0

No comments: