This article will guide you on how to add Swap partitions manually under Debian 11 and Ubuntu 22.04.
First, check that your system already has a Swap partition.
If no result is returned or the
Swap column in
free -m has a value of
0, then your system does not have a swap partition.
Creating a SWAP partition
We can use the
fallocate command to create a 1GB swap partition.
If this command does not work, please install the
Then set the permissions for this file.
Then activate the SWAP partition.
At this point you can use the command
swapon -s or
free -m to see if the Swap partition is active.
Setting up boot-up
We need to edit the file
/etc/fstab and add the following.
Once you have finished, use the command
free -m to see if the Swap partition is correct.
Adjusting the system kernel Swappiness value
Swapiness is a property of the Linux kernel that defines how often the system uses swap space. Swapiness values range from 0 to 100 (the default is 60), a low value causes the kernel to avoid swaps as much as possible, while a high value causes the kernel to use swap space more aggressively.
This value defaults to
60 and we can check the current value using the command
Normally we can change it to
Then use the
sysctl -p command to make it effective.
Sometimes we need to close a Swap partition, so we can use the following command.
First, deactivate the Swap partition.
/etc/fstab and delete the line
/swapfile swap swap defaults 0 0.
Finally delete the file