Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

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 :D

share|improve this question

1 Answer 1

up vote 9 down vote accepted

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.

share|improve this answer
    
Awesome. I'm trying this right when I get home! I had a feeling there was a little bit more involved than simply formatting a USB stick as swap and plopping it in the slot and booting up . I'll be back if I have any issues to award you with the correct answer my Linux brother. –  Joshua Robison Aug 9 '12 at 9:01
    
To see whether your changes have been applied, type cat /proc/swaps. In the following list shown there should be your usb drive mounted as swap. Good luck to you, bro! :) –  FuzzyQ Aug 9 '12 at 9:41
    
well sir @FuzzyQ it worked like a charm. Also, though I did do the fstab work, I was worried about that because even on persistent live usb sticks/ hybrid usb sticks... the fstab is always reset on reboot... but something funny happened when I rebooted and it turns out though I am thankful for your fstab suggestion I didn't even need to use that magic and Ubuntu recognized the swap disk and started using it right away. –  Joshua Robison Aug 9 '12 at 13:18
1  
Getting good results too. The wife's computer definitely pauses and dims from USB writes much less –  Joshua Robison Aug 9 '12 at 15:26
1  
I just did that and worked like a charm here too! –  Pedro Dusso Apr 30 '13 at 7:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.