Note – Running all these commands require root privilege, so I recommend running a “root” terminal.
Finding out available swap file(s)
Before we get to change the swap, let’s find out how much swap size we have.
According to the result, the system has a swap file at “/swapfile”.
For manipulating the swap file, we have to disable it first.
Now, change the size of the swap file –
Here, the total size of the swap file will be bs*count = 1M x 4096 = 4GB
Make the “/swapfile” usable again –
Turn on the swapfile –
After restarting your system, check out the result –
Deleting the swap file
If your RAM space is high enough, then you probably want to get rid of the swap file. If that’s your case, then let’s get rid of the swap file!
Don’t worry! I’ll also show you how to set a completely fresh swap file.
For deleting the swap file, run the following commands –
Remove the swap file entry from “/etc/fstab” file. It should be the last line of the file.
Now, time to remove the actual swap file.
Don’t forget to restart your system!
For getting back the swap file, use the following commands –
# Adding permission where only root user can read the swap file
# Setup the file for swap space
Edit the “/etc/fstab” file and add the following line at the end of the file –
Restart your system.
Voila! Your swap file is back!
What if you had a swap partition? You have to perform actions on the partition itself. That’s more troublesome than just simply managing your swap files directly using the methods above, right?
I recommend deleting the “swap” partition and use the above method to create a new swap file.