• Home
  • Blog
  • Linux
  • Using pen drive as additional memory in Linux (ReadyBoost)

Using pen drive as additional memory in Linux (ReadyBoost)

It is possible to reproduce on Linux the Windows ReadyBoost feature, where a pendrive and be used to optimize memory, being mounted as swap área with the highest priority. This process can only be done with root access and, obviously, a good sense, because if you made any partition mistake, you can really mess your system.

If you know how to format the pendrive as linux-swap, do it an go to step 5.

1 - Erase all pendrive data

Backup your files (if necessary) and empty the pendrive. Don't worry with format (FAT32, ext4, ext3, etc). We gonna format as linux-swap.

2 - Identify the pendrive partition path

As any HD, the pendrive also has partitions (but in almost all cases, just one). To list the disks and partitions, use fdisk -l.

In my case, I have a disk of 250.1 GB (my HD in /dev/sda) and a 7756 MB one (my pendrive in /dev/sdb). The HD has three partitions (/dev/sda1, /dev/sda2, /dev/sda3). The pendrive, just one, which path in my case is /dev/sdb1.

WARNING: be sure that you are identifying the correct partition, because in your computer can be different. If are not sure, don't go ahead.

3 - Unmout the partition, if mounted

To identify if the pendrive is mounted, and where, do:

mount | grep /dev/sdb1 | awk '{print $3}'

If return any directory, unmoount it using the command umount <mounted-path>

4 - Define the partition as Swap

Define a swap area in the pendrive with mkswap. This command gonna erase your data.

mkswap /dev/sdb1

5 - Tell the system to use the device's swap area (with maximum priority)

swapon -p 32767 /dev/sdb1

Obs: the 32767 is the usage priority (0 = lowest, 32767 = highest). We may prefer the pendrive instead os disk because use have better read/write ratios (I do not know how is it against SSD disks).

6 - Confirm that swaps was activated

Typing cat /proc/swaps, confirm that the system is using the new swap area

# cat /proc/swaps
Filename Type Size Used Priority /dev/sda6 partition 5858300 339816 -1 /dev/sdb1 partition 7572476 0 32767

Finally, to undo...

To deactivate this aditional swap, do:

swapoff /dev/sdb1

And to use the pendrive again, format it as you prefer.