Raspberry Pi has only 256 MB of RAM, so I would like to use swap space (either on SD card or attached USB storage). How do I set it up?
You can set up swap space quite simply. For example, if your USB drive is
Note that this would use the whole device and you will probably lose all the existing data on it.
You can also create a swap file (by using a
When you no longer need the swap file (if you want to eject the USB drive for example), you must use
You should be careful though. SD cards have limited read/write limits and it will shorten its lifespan. If you are using an external hard drive, you should be fine, but it will be very slow.
Do not do this at all.
You should not enable swap on the Raspberry Pi.
Although it is possible, it is not useful. Even on a class 10 SDHC card, it is just too slow. Also you will reduce the lifespan of the SD card.
On any flash-based storage device (SD card, SDD, USB thumb drives) you are also likely to see system-wide pauses while a large group of flash blocks is erased.
Raspbian uses dphys-swapfile, which is a swap-file based solution instead of the "standard" swap-partition based solution. It is much easier to change the size of the swap.
The configuration file is:
The content is very simple. By default my Raspbian has 100MB of swap:
If you want to change the size, you need to modify the number and restart dphys-swapfile:
Raspbmc uses /etc/init/swap.conf to configure swap via /swap file. It first checks for presence of "/home/pi/.enable_swap"
If you delete "/home/pi/.enable_swap" then swap file is not created, and then just recreate it with "touch /home/pi/.enable_swap" if you need swap turned on and reboot.
protected by Jivings♦ Jun 19 '12 at 13:47
This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.