Sunday, July 3, 2011

Add Virtual RAM to Ubuntu using a Spare USB Drive

Almost all of the Ubuntu users have got a Swap partition on their HDDs. Having Swap helps if one runs out of RAM and also, it is used for hibernation.

Smaller USB drive seek times are much faster as compared to the HDD. Windows 7 is using the 'Readyboost' technology these days which is simply like having a Swap file on the USB drive. It can be easily achieved in Ubuntu (Linux in general) by just running a few commands.

The downside is that regular and sequential read/writes to the USB drive decrease the life of the drive itself. It is not as good as having proper RAM but at least it is far better than having Swap on the HDD.  You can do this occasionally when you feel you've started running out of RAM but don't permanently mount your USB drive as Swap as your USB drive would die in a few months for sure.

Plug-in your USB drive and make sure there are no important files on the drive. Delete all the files on the drive or re-format it and go to a Terminal.

First, we need to unmount the drive if Ubuntu auto-mounted it when you plugged it in:

sudo umount /media/drive-label

Where 'drive-label' is the name you see for the USB drive when it is mounted.

Or you can also do it this way:

sudo umount /dev/sdx1

Where 'sdx1' is your drive/partition letter. You can find it by running this command:

sudo fdisk -l

Now, we'll create the Swap file on your USB drive:

sudo mkswap /dev/sdx1

Where 'sdx1' is your drive letter we figured out from the output of 'fdisk -l' command above.

Now, turn on your new Swap:

sudo swapon -p 32767 /dev/sdx1


In order to make sure your new Swap is working, you can take a look at the output of this command:

cat /proc/swaps

My output is:

/dev/sda2 partition 2047992 60692 -1
/dev/sdb1 partition 7912708 17764 32767

Related Posts: