Thursday, 26 April 2012

Increasing swap file size in Linux

If you need to increase your Linux swap space, but don't want to repartition your hard drives, you can use a swap file.

First, create an empty file, of the size you want.
 dd if=/dev/zero of=/mnt/my_swap bs=1M count=2048  

The above creates an empty file of size 2GB, called mnt/my_swap. To create a file of a different size, replace the 2048 with the size of swap file you require, in MB.

Next, format the file as swap space:
 mkswap /mnt/my_swap  

Then tell the operating system to begin using it:
 swapon /mnt/my_swap  

Finally, to persist the change, and ensure the OS uses the new swap file on every boot, open /etc/fstab and add the following line:
 /mnt/my_swap none swap sw 0 0  

To open /etc/fstab, you can use gedit with this line:
 gedit /etc/fstab  

Additionally, to check the current swap spaces in use by the system, you can use:
 swapon -s  

With thanks to DistroWatch Weekly, Issue 388, 17 January 2011 for this information!

No comments:

Post a Comment

Please leave a comment if you find this blog helpful or interesting! I'd love to hear from you!