Using a USB flash drive as RAM in Linux Mint/Ubuntu

Cats: linux mint

Alright, so it’s not exactly RAM, but rather swap space. Simply put, when the OS runs out of physical RAM it uses the ‘swap space’, which is like RAM but on a hard drive. And because it’s on a hard drive, it’s really really slow.

This quick hack uses a USB flash drive instead, which not only offsets the load on the hard drive, but also has speed advantages. One of my older systems ran up against the 2Gb RAM wall pretty quick. For less than $10, this takes away some of the hang ups it used to experience.

Grab a USB stick, make sure there’s nothing on it you need (as it will be deleted!), and follow these steps:

  1. Plug it in. If it automounts, unmount it.
  2. Type: sudo mkswap /dev/sdb1 (or whatever your device path is)
  3. Then type: sudo swapon -p 32767 /dev/sdb1 (the 32767 makes it a higher priority and will thus be used before the hard drive swap drive)

To make sure everything went well, type:

cat /proc/swaps

If you need to take the stick out, type:

sudo swapoff /dev/sdb1

Since I’ll be leaving this in the back of my desktop, first I got the UUID of the drive by typing:

ls -l /dev/disk/by-uuid/

And then I added the following line to my /etc/fstab to have it automount as swap:

UUID=35e61737-7418-4a6a-9d00-9ee18efc6832	none	swap	sw,pri=32767	0	0

It’s obviously not as fast as physical RAM, but it’s a cheap and quick way to get a performance boost.