How to make an additional swap file in Linux !

Alternatively referred to as a page file or paging file, a swap file is a file stored on the computer hard drive that is used as a temporary location to store information that is not currently being used by the computer RAM. By using a swap file a computer has the ability to use more memory than what is physically installed in the computer. However, users who are low on hard drive space may notice that the computer runs slower because of the inability of the swap file to grow in size.

A swap file allows an operating system to use hard disk space to simulate extra memory. When the system runs low on memory, it swaps a section of RAM that an idle program is using onto the hard disk to free up memory for other programs. Then when you go back to the swapped out program, it changes places with another program in RAM. This causes a large amount of hard disk reading and writing that slows down your computer considerably.

Run all the commands as root or as a super user:-

dd if=/dev/zero of=/var/swapfile bs=1M count=1024

were dd = disk duplicator, if = input file, bs = block size, of = output file

Now change the file ownership

chmod 600 /var/swapfile

mkswap /var/swapfile

swapon /var/swapfile

Make an entry into the file system table

vi /etc/fstab

/var/swapfile         swap        swap       defaults     0 0

That’s it swap file has successfully been created. Finally to list all the swap partitions, enter

swapon -s

Njoy !