18

In windows it is possible to use usb flash drive as a virtual ram. I wonder if it is possible to do so in ubuntu? If it is, how could one do it?

[Edit]: I mean Ready boost equivallent for ubuntu. I know that it is not a perfect replacement for ram and it is not advisable for longterm use.

Is creating swap file in a usb flash drive similar to it? Will it demonstrate performance gains over a swap file in a Hard Disk Drive?

2
  • 1
    If you mean to use it like Vista and Windows 7's Readyboost feature, you have to format it as a swap partition and assign a swap file to it. If you want to use it as extra system RAM, you can't.
    – Ringtail
    Mar 24, 2012 at 16:34
  • yeah I mean readyboost
    – Tachyons
    Mar 24, 2012 at 16:39

4 Answers 4

13

The answer Sean suggests is one way of accomplishing this, another would be to just create a swapfile on the stick, that way you can also use your stick for other files. Like so:

  • find out where the stick is mounted. Look in nautilus or issue mount in the terminal

  • create an empty file of dd if=/dev/zero of=/media/YOURSTICK/swap bs=4096 count=131072. This creates a 512 MB file (512 * 1024^2 / 4096 = 131072)

  • create the swap and enable it sudo mkswap /media/YOURSTICK/swap && swapon -p 1000 /media/YOURSTICK/swap

The swap on your USB stick won't be faster than one residing on your HDD. Also it will kill the stick on the long term, writing does that to USB sticks.

To increase the usable amount of ram check out zram.

4
  • I have already one swap partition ,i heard that more than one swap partition may lead to the problem,i wont use it in regularly ,but i want to use it when system have heavyload only.
    – Tachyons
    Mar 24, 2012 at 13:32
  • 3
    If you have a workload where things are regularly being pulled in and out of swap to the extent where faster swap makes a significant difference, you're probably better off getting more RAM. Whether your swap is on a hard drive or USB drive, it is going to be orders of magnitude slower than real RAM. Mar 24, 2012 at 15:26
  • Yeah usb cant replace real ram ,But it may be better than real Ram(correct me if this is wrong :))
    – Tachyons
    Mar 24, 2012 at 17:51
  • 4
    USB is not better than real RAM
    – laurent
    Mar 25, 2012 at 12:34
6

I found out about this when I did it from http://www.tuxgarage.com/2011/07/add-virtual-ram-to-ubuntu-using-spare.html

Plug-in your USB drive and make sure there are no important files on the drive. Delete all the files on the drive or re-format it and go to a Terminal.

First, we need to unmount the drive if Ubuntu auto-mounted it when you plugged it in:

sudo umount /media/drive-label

Where 'drive-label' is the name you see for the USB drive when it is mounted.

Or you can also do it this way:

sudo umount /dev/sdx1

Where 'sdx1' is your drive/partition letter. You can find it by running this command:

sudo fdisk -l

Now, we'll create the Swap file on your USB drive:

sudo mkswap /dev/sdx1

Where 'sdx1' is your drive letter we figured out from the output of 'fdisk -l' command above.

Now, turn on your new Swap:

sudo swapon -p 32767 /dev/sdx1

Done!

In order to make sure your new Swap is working, you can take a look at the output of this command:

cat /proc/swaps

My output is:

/dev/sda2 partition 2047992 60692 -1
/dev/sdb1 partition 7912708 17764 32767

To take the stick out first turn off the Swap:

sudo swapoff /dev/sdx1
1
  • 1
    this adds a swap file it does not make it usable as RAM
    – Ringtail
    Mar 24, 2012 at 16:28
5

If you truly need to add RAM to your system, there is nothing short of installing more memory sticks or increasing the physical memory of the machine.

Using a USB cannot increase the RAM in such a manner as to ONLY increase the swap file, plus the read/write times are decreased by the USB 480mb transfer limitations.

If you want to experience an increase in performance use "zRam". This adds a special file to your existing system and increases the system's virtual memory. It decreases the I/O write times as it uses a compressed block technology stored on the current RAM

More information here

2
  • Native swap partition in ubuntu is faster than readyboost in windows :o !!!!!!!??????
    – Tachyons
    Mar 24, 2012 at 17:41
  • I agree, readyboost is limited by it's transfer speed
    – Ringtail
    Mar 24, 2012 at 17:50
3

I already tried this ago. But usb stick so slow when writing something.

I experienced very short hang continuously when system using usb swap. It was may my stick was so cheaper one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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