Popular Posts

Tuesday, April 23, 2013

Using USB Drive As Swap Space For Linux

1) Put on your USB drive, open terminal and 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!)

You can also use Gparted if you want GUI

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

gksudo gedit /etc/fstab

and enter the following


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

5) Now type

sudo swapon -a

For more info, man swapon

p/s: you can define priority between your HDD swap and USB swap using the pri=value. The higher value indicates higher priority. You also can adjust the swappiness on /etc/sysctl.conf, the swappiness sysctl parameter represents the kernel's preference (or avoidance) of swap space. Swappiness can have a value between 0 and 100. Setting this parameter to a low value will reduce swapping from RAM, and is known to improve responsiveness on many systems.

nano /etc/sysctl.conf


1. vm.swappiness=1
2. vm.vfs_cache_pressure=50

No comments:

Related Posts Plugin for WordPress, Blogger...