Friday, 8 March 2013

How to create a Linux Swap Partition

Creating swap file
A swap file can be created and mounted using the dd command. Say for example you need are planning to add 1 GB extra space for your swap memory.
   # dd if=/dev/zero of=/usr/local/extraswap bs=1M count=1024

After that you need to use the mkswap to format the file to swap file sytem.
   # mkswap /usr/local/extraswap

Then use the swapon command to enable the new swap file.
   # swapon /usr/local/extraswap

Check the swap memory using free -m command and confirm it with
   # swapon -s

To load the swap file on the next boot. Just edit the /etc/fstab and add the following lines.
   /usr/local/extraswap none   swap   defaults  0   0

Save and exit, make sure you have made the backup of /etc/fstab before adding the lines.