Learning with Raspberry PI, Delivery V - Increase SWAP memory of Raspbian

In previous deliveries We saw How to upgrade the Software and the Firmware of our Raspberry, How to make or overturn a complete picture of the SD card making the main memory in the PI function, and How to make Overclocking and Overvoltage without losing the warranty.

This time we'll see as raising the Swap of Raspbian, Since the 100MB that come predefined us may be shorter depending on the project you want to develop with our Raspberry.

There is a need to expand the memory SWAP.

There is a need to expand the memory SWAP.

We can extend it in two different ways, I will explain both and you will finally offer reflection of the because of my choice.

Expand the SWAP using a partition

To expand the SWAP in this way, We need to create a partition in the SD card, or if we want it in a pendrive connected to the port USB, to act as swap space, and this can be done from any partitioning program to support Linux Swap.

I prefer Fdisk, but for that you can see it in a way most graphic this time will use Gparted. First We redimensionaremos the operating system partition to let you 256MB to the memory SWAP.

We resize the SD card.

We resize the SD card.

And then create the swap partition with those 256MB free.

We create a Linux SWAP partition.

We create a Linux SWAP partition.

At this point, once introduced the SD card in our Raspberry and booted the operating system, We will disassemble the SWAP current and mount the new partition.

We must remember that Rebooting will not operate Since you will be charged the swap defined by Raspbian, because at the moment we are testing, and we must also be aware that this operating system call your storage devices /dev/mmcblk * and not /dev/sd *.

pi@raspberrypi:~$ sudo mkswap /dev/mmcblk0p3
Setting up swapspace version 1, size = 262140 KiB
no label, UUID=d443580c-5ab7-4063-9aa3-beec81899ca4

pi@raspberrypi ~ $ sudo swapon /dev/mmcblk0p3

With the following command you can check that everything is functioning correctly by referring to the reference values to the Swap in the file /proc/meminfo.

pi@raspberrypi:~$ cat /proc/meminfo | grep Swap
SwapCached:            0 kB
SwapTotal:        364536 kB
SwapFree:         364536 kB

Now it only remains to add changes in the configuration file /etc/fstab to make the change permanent, But first we need the UUID partition.

pi@raspberrypi:~$ sudo blkid /dev/mmcblk0p3
/dev/mmcblk0p3: UUID="d443580c-5ab7-4063-9aa3-beec81899ca4" TYPE="swap"

Now we can already edit /etc/fstab and add this reference to our SWAP be mounted automatically at the beginning of the system whenever it starts.

pi@raspberrypi:~$ sudo nano /etc/fstab

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
UUID=d443580c-5ab7-4063-9aa3-beec81899ca4 none            swap    sw              0       0

After restart you can verify that the partition swap that the system is using is still that we have allocated to our needs in terms of virtual memory, either with the command seen above in this post or in a way most graphic.

New 256MB SWAP.

New 256MB SWAP.

Expand the SWAP by modifying the file Raspbian swapfile

This method is much more simple and clean as above, Since it is the OS to set the size that will have the SWAP, in this case it is a file and not a partition, Since thus the developers of the project have decided it Raspbian.

To implement it we only change a value in the file /etc/dphys-swapfile, where is indicates the size in MB you will have the SWAP.

#/etc/dphys-swapfile (ORIGINAL)

Once modified the file It must be so:

#/etc/dphys-swapfile (MODIFICADO)

To apply the changes, We can reboot the system; or restart the swap.

pi@raspberrypi:~$ sudo dphys-swapfile setup
pi@raspberrypi:~$ sudo dphys-swapfile swapon

Finally after the reboot of the system, or of the swap; We will check that the changes have been applied correctly.

pi@raspberrypi:~$ cat /proc/meminfo | grep Swap
SwapCached:            0 kB
SwapTotal:        364536 kB
SwapFree:         364536 kB

Final reflection: Implementation I have chosen and why?

I personally I prefer this last method being which is already implemented in Raspbian, and I guess that for something the developers have chosen him after tests and more tests.

Also allows me in the future have two primary partitions more in the SD by the needs that may arise me, and you have to take into account that it is the form more easily and quickly from among the available.

If you like you can follow me on Twitter, Facebook, Google +, LinkedIn, or share it with the buttons under this publication, If you have any questions or suggestions please do not hesitate to comment.

Help us to reach more readers Share on LinkedIn
Share on Facebook
Tweet about this on Twitter
Share on Google+
Google +
Email this to someone

Leave a Reply