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 :

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 ./ -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 ./ -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.

  • Great tip. Will surely be helpful for those running older computers.
    .-= Chinmoy Kanjilal´s last blog ..Where the hell is the Admin of this Blog =-.

  • Pingback: Links 23/12/2009: OLPC XO 3.0 Concept Surfaces | Boycott Novell()

  • Laurence Perkins

    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 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.

  • The only thing missing is making the flashdrive swap file have a higher priority over any HD swap space so it will use the flashdrive FIRST assuming it’s faster than the HD access.