Using usbdrive as ram in ubuntu

Solution 1:

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.

Solution 2:

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

Solution 3:

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

Solution 4:

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.