ADD virtual RAM memory. [HowTO]

serdeliuk

Registered
Messages
127
Hello,

If you install a lots of plugins and forgot to remove them after, alike me, for sure you will need to add more RAM memory to your device.
Unfortunately there is no way to add physical RAM, but we can add virtual RAM as much as we like.
Here I will explain how to add virtual "swap" memory to your device, it will work with any device which have internal Hard Disk.

So let say we want to add 8GB RAM, through command line, ssh or ftp to your box and:

# First let see how much ram we have and how it's used, you need to issue "free" command

root@vusolo4k:~# free
total used free shared buff/cache available
Mem: 2066108 1098308 806772 540 161028 939724
Swap: 0 0 0

# In my case I have 2GB RAM memory and 806MB free RAM memory, with 0GB Swap "virtual memory"

# So, let's start, we will add 8GB virtual memory to our system, for this we will need to have an internal Hard Disk.
# Find where the HDD is mounted, with following command "mount" we find where the HDD is mounted

root@vusolo4k:~# mount
rootfs on / type rootfs (rw)
/dev/root on / type ext4 (rw,relatime,nodelalloc,data=journal)
devtmpfs on /dev type devtmpfs (rw,relatime,size=109272k,nr_inodes=27318,mode=755)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
tmpfs on /media type tmpfs (rw,relatime,size=64k)
/dev/sda1 on /media/hdd type ext4 (rw,relatime,data=ordered)
/dev/mmcblk0p4 on /media/usb type ext4 (rw,relatime,nodelalloc,data=journal)
tmpfs on /var/volatile type tmpfs (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620)

# In my case the HDD "/dev/sda1" is mounted on "/media/hdd"
# Now let's prepare the OS to accept our swap and set how to use it
# Let see when it is ued by default

root@vusolo4k:~# cat /proc/sys/vm/swappiness
60

# The above "60" result mean that the OS want to use the swap file, if it have one, when tha RAM memory is at 60% used.
# We will change this to 10, to start to use swap file just when is needed, so proceed with following commands,

root@vusolo4k:~# sysctl -w vm.swappiness=10
vm.swappiness = 10

# Check again to see when swap file is used.

root@vusolo4k:~# cat /proc/sys/vm/swappiness
10

# To make this permanent, ie. after reboot, add in /etc/sysctl.conf file, at the end, the following line
vm.swappiness = 10

# Now, let's create an empty file of 8GB to be used as swap "virtual memory", the "root@vusolo4k:~#" it's my prompter, so only what is after is the command itself,
# "count=8192000" mean 8GB

root@vusolo4k:~# dd if=/dev/zero of=/media/hdd/swapfile bs=1024 count=8192000
8192000+0 records in
8192000+0 records out
8388608000 bytes (7.8GB) copied, 122.399746 seconds, 65.4MB/s

# Now we have the empty file with a size of 8GB, let's transform that file into a swap file

root@vusolo4k:~# mkswap /media/hdd/swapfile
Setting up swapspace version 1, size = 16777211904 bytes
UUID=bb72c060-9a92-4ad9-9963-238ce3a134c7

# Now, with the new swap file formatted, let's enable the swap space

root@vusolo4k:~# swapon /media/hdd/swapfile

# All done, let see how much RAM we have now.

root@vusolo4k:~# free
total used free shared buff/cache available
Mem: 2066108 1098084 819704 452 148320 938256
Swap: 8191996 12168 8179828

# Well done, it seems that we have an 8GB virtual memory added, and already started to be used.
# Reboot your device and see if is still there after reboot :)



Best regards,


Marc
 

serdeliuk

Registered
Messages
127
Actually will work also on USB devices, but it is not recommended to add virtual memory on USB devices, because are slow. Also, should not be removed from USB port :)

However, if this is the only one solution and it is required, then, let be an USB device :)

Marc
 
Last edited:

serdeliuk

Registered
Messages
127
Well, not sure why i forgot to add how to make this permanent, after reboot.

In order to have the swap space auto-mounted after reboot, you should add the following line at the end of the /etc/fstab file

/media/hdd/swapfile swap swap defaults 0 0

M
 
Top