Categories: HomeHow-to'sLinux

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 !

Akash Angle

I am a Full time Linux user who has quit using Windows for unknown reasons, making my life truly open source.

Recent Posts

Get the most juice from your ISP/router — setting MTU size & other handy tweaks

This is not an ad-vocation by any means for TP-link branding, however a real life…

7 months ago

How to make any Android phone up-to 3x faster – Developer options unleashed

First of all we need to hit the kernel version on any Android device. You…

7 months ago

systemd-resolve command not found in Ubuntu Desktop

Use resolvectl status instead. It's like something deprecates and suddenly things get broken! In systemd…

12 months ago

How to exclude multiple directories with rsync?

Geeky question: This is what people and friends have tried: rsync -arv --exclude "/home/john/.ccache:/home/ben/build" /home/john…

12 months ago

How to resolve apt-get -f not working

You might encounter this error which appears to be very common on Debian based Distro's…

12 months ago

How to install Broadcom STA wireless drivers on Kali Linux

PS: This article is for only Kali Linux users, that too having a Broadcom Wireless…

1 year ago