swap file for raspberry pi

I want to compile OpenCV on my raspberry pi. I know form previous experience that there isn’t enough memory on board to do that, so I need to make some swap space. Following this post by Jermal Smith, create a 2GB file, make it readable by root only, and make it swap

$ sudo dd if=/dev/zero of=/swap bs=1M count=2048
$ sudo chmod 600 /swap
$ sudo mkswap /swap
$ sudo swapon /swap

free -m shows 2147M of swap free

adding this to /etc/fstab to keep swap after reboot:

/swap   swap   swap   defaults   0   0

While this seems to work (free and top show the expected memory and swap), either it wasn’t enough, or something wasn’t stable enough to build OpenCV. In the end for the actual compilation I partitioned RaspPi’s SD card to give a more conventional swap partition (and yes, I do know that running a swap on an SD card shortens its life because of the high number of reads & writes, I don’t intend to use it routinely)

One thought on “swap file for raspberry pi

Comments are closed.