- If you skipped or forgot to add virtual memory during the installation of the operating system, it can be done after the installation is complete.
- With a simple process through the terminal, the available amount of working memory of the computer can be doubled in a few steps.
Author: Periša Reljić
SWAP: Adding virtual memory to Debian systems
Starting “System Monitor” will show the state of the operating memory in the left corner. The virtual memory is called “SWAP”, and the process of adding it is identical for Debian systems Ubuntu, BackBox or Parrot.
The absence of virtual memory can also be checked through the terminal (Ctrl + Alt + T), by typing the command:
free - m
The resulting response looks something like this, and the SWAP value is zero:
total used free shared buffers cachedMem: 3823 3026 796 114 154 1683-/+ buffers/cache: 1188 2635Swap: 0 0 0
To a computer with 4 gigabytes of working memory, 4 gigabytes of virtual (SWAP) memory are added by typing in the terminal the command:
sudo fallocate -l 4G /swapfile
After “enter” and entering the user password, check in the terminal by typing:
ls -lh /swapfile
And the response received confirms the successful addition of virtual memory:
-rw——- 1 root root 4.0G Feb 16 02:07 /swapfile
After we’ve added virtual memory to the computer, we need to tell the operating system how to use it. To avoid the possibility that someone else can use the virtual memory, we will protect it with:
sudo chmod 600 /swapfile
After which confirm permission to use virtual memory with:
ls -lh /swapfile
The resulting response in the terminal will look something like this:
-rw——- 1 root root 4.0G Feb 16 02:07 /swapfile
Thus obtained and protected space on the computer, we will “order” the system to use it as SWAP with:
sudo mkswap /swapfile
The resulting response will look something like this:
Setting up swapspace version 1, size = 4194300 KiBno tag, UUID=21c49ef7-c391-4b48-95aa-f080324c85fd
In order for the system to be ready to use the obtained 4 gigabytes as virtual memory, we will type the permission in the terminal:
sudo swapon /swapfile
We will check whether the procedure was successful piece by piece:
sudo swapon -s
After which the resulting response will look something like this:
Filename Type Size Used Priority/swapfile file 4194300 0 -1
By typing in the terminal:
free - m
The resulting response will display the virtual memory parameters:
total used free shared buffers cachedMem: 3823 3070 752 123 155 1742-/+ buffers/cache: 1173 2650Swap: 4095 0 4095
We will make the thus obtained virtual memory permanent by changing the fstab file in the terminal:
sudo nano /etc/fstab
When the fstab file opens in the terminal, scroll to the end with the arrow (down) and copy-paste:
/swapfile none swap sw 0 0
After which save the changes made with
“Ctrl + X”
Type:
Y
and finally of course:
enter
Swappiness is set to 60 by default, which is quite correct for computers, and there is no need to change the file in that part. ( cat /proc/sys/vm/swappiness )
It is still necessary to make a change in vfs_cache_pressure, which we will do by opening the file with:
sudo nano /etc/sysctl.conf
Scroll to the end with the arrow (down) and copy-paste:
vm.vfs_cache_pressure = 50
Save changes with:
Ctrl + X
Y
Enter
The virtual memory (SWAP) has been successfully added to the operating system, which will be confirmed by the system monitor (System Monitor) showing 4 Gb of virtual in addition to the already existing working memory.