Add Extra Swap Space To Your Linux Box with a USB drive [Linux Hacks]

You must have heard about a feature called “Readyboost” in Windows Vista and Windows 7, which lets you add a flash drive or USB thumb drive as an extra drive for disk cache. By using this feature system performance is significantly increased, as the newly added flash drive increases the virtual memory of your computer.

In a similar way, you can use a USB flash drive to add extra swap space to your Linux OS. Increasing the swap space means increasing the system performance. Christer Edwards has written a shell script, which allows you to add a USB drive as an extra swap space in Linux. You can download the shell script file from here : http://bit.ly/6V87XK

The steps required to use the extra space on the USB drive as swap space are :

  1. Insert USB disk and allow KDE/Gnome to auto-mount the device.
  2. Open a Terminal and run ./swapboost.sh -n to create a new swap addition.
  3. After executing these steps the swap space would have been increased, by the amount of free space on the USB drive. You can check the available swap space for your Linux OS with swapon -s .

When you no longer want to use the USB drive as an extra swap space, you can do the following:

  1. In the Terminal, run ./swapboost.sh -d to delete added swap and safely unmount your USB disk.
  2. Your swap should now have been reduced by the amount of space previously added. swapon -s will now show only your default swap space.

Note: This script is still in alpha stage, so use it on your own risk.

4 thoughts on “Add Extra Swap Space To Your Linux Box with a USB drive [Linux Hacks]”

  1. This will give you more swap space, but the default kernel won’t use it for disk cache. For most people, that won’t matter, because the Linux filesystems don’t fragment nearly as badly as NTFS does, so an on-disk disk cache doesn’t actually speed things up significantly unless you’re someone like me who has a very large, very slow drive for storage, and a small, but lightning fast drive for working. If you fall into that category, check out https://github.com/facebook/flashcache for a kernel module that will use a swapfile for disk cache. You probably won’t see a significant benefit from it though unless you work with large amounts of data.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>