Create Swap Memory

This is a short tutorial that shows how to create swap memory for your Ubuntu system, to improve compiling performance, and to avoid out-of-memory errors.

Make sure your SD card is big enough. It is recommended to use at least an 8 GB micro SD card, but 4 can work, if your projects are small.

Create Memory Image File

To begin, log into Ubuntu on OcPoC, and type:

$ mkdir /media/fasthdd
$ cd /media/fasthdd
$ :> swapfile.img

Now we'll expand the file to be 1 GB.

$ dd if=/dev/zero of=/media/fasthdd/swapfile.img bs=1024 count=1M

And now assign it to be swap memory.

$ mkswap /media/fasthdd/swapfile.img

Finally, edit the file /etc/fstab:

$ nano /etc/fstab

And add this line to the end of the file:

/media/fasthdd/swapfile.img swap swap sw 0 0

Close nano by typing [ctrl]-X, then type 'y' to confirm changes, and finally ENTER to exit.

In order for the changes to take place, you'll need to power off and power on the board.