place to discuss Linux
Increase Swap Memory in Linux
In Linux, as in most other Unix-like operating systems, it is common to use a whole partition of a hard disk for swapping. However, with the 2.6 Linux kernel, swap files are just as fast as swap partitions, although Red Hat recommends using a swap partition. The administrative flexibility of swap files outweighs that of partitions; since modern high capacity hard drives can remap physical sectors, no partition is guaranteed to be contiguous. You can add swap file as a dedicated partition or use following instructions to create a swap file.
Procedure to add a swap file
You need to use dd command to create swapfile. Next you need to use mkswap command to set up a Linux swap area on a device or in a file.
a) Login as the root user
b) Type following command to create 512MB swap file (1024 * 512MB = 524288 block size):
HungryHacker@localhost:~$ dd if=/dev/zero of=/swapfile1 bs=1024 count=524288
c) Set up a Linux swap area:
HungryHacker@localhost:~$ mkswap /swapfile1
d) Activate /swapfile1 swap space immediately:
HungryHacker@localhost:~$ swapon /swapfile1
e) To activate /swapfile1 after Linux system reboot, add entry to /etc/fstab file. Open this file using text editor such as vi:
HungryHacker@localhost:~$ vi /etc/fstab
Append following line to the above file:
/swapfile1 swap swap defaults 0 0
So next time Linux comes up after reboot, it enables the new swap file for you automatically.
g) How do I verify swap is activated or not?
Simply use free command:
HungryHacker@localhost:~$ free -m
| Print article | This entry was posted by Ashik on April 7, 2009 at 1:55 am, and is filed under Tutorials. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |





about 1 year ago
Thanks for the tip, I never gave any thought to why I always use a swap partition. I think I’ll start using a swap file instead… Thanks again
about 1 year ago
Nice post. I have started using an old USB stick as swap. Since I have 2 Gigs of Ram, it hardly gets touched.
about 1 year ago
IIRC, to use Hibernate function, one has to have swap partition.
Do not remember the details, but I believe that’s why laptop can’t hibernate.
And btw, on most systems now one can easily work without swap at all. But it depends on your applications of course.