Ubuntu – How to make a USB stick swap disk

live-usbswap

OK , I know this sounds a bit silly and solid state drives like a USB flash stick are probably the last thing on earth you want to use as a swap disk since they could go bad pretty quick from all the read/writes.

Regardless of the bad idea aspect of this I would like to know how to make one of my old 4 gig USB sticks my designated swap disk so that when my computer running Ubuntu Precise starts up, it will use the USB stick as swap.

Couple of twists to add to the challenge:

  1. the computer I'm using is my wife's laptop core2 duo and has 4gigs of ram

  2. she likes Ubuntu but doesn't trust me to backup her hd so I have her running Ubuntu 12.04 on a 16gb highspeed USB 2 flash memory stick with persistency.

  3. the second USB stick will be my swap disk and when the live USB starts up I want it to do all the heavy swap writing etc on the second USB stick

Anyone up to the challenge. Trivial maybe but please indulge me 😀

Best Answer

1) Make sure your USB stick is connected. In a terminal type:

sudo blkid

It will list all your connected drives. Search for your USB stick you want to use as swap and copy the UUID (everything inside these quotes UUID="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX").

This represents the individual name of your device.

Also note the /dev/XXX point of your device.

2) Now unmount your device by typing:

sudo umount /dev/XXX (where XXX represents your device name)

3) Format your USB stick as swap, e.g. by terminal

sudo mkswap /dev/XXX (<-- be sure to use the correct device name here or you'll probably end up formatting the wrong drive!)

or simply use GParted.

4) Now you have to edit your /etc/fstab file, so type

gksudo gedit /etc/fstab

and enter the following

UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX none swap sw,pri=5 0 0

(for all the Xs, use the UUID number you got by typing sudo blkid)

5) Now type

sudo swapon -a

That's it, this should already work.

Related Question