Introduction
Swap partitions are an important part of any Linux system, as they provide a way to extend the amount of physical memory available to the system. However, in some cases, it may be necessary to permanently disable the swap partition in order to free up disk space or improve system performance. This tutorial will explain how to permanently disable the swap partition in Linux. It will cover the steps necessary to disable the swap partition, as well as the potential risks and benefits of doing so.
How to Permanently Disable Swap Partition in Linux
1. Open a terminal window and type “sudo swapoff -a” to disable all swap partitions.
2. Type “sudo nano /etc/fstab” to open the file system table.
3. Find the line that contains the swap partition and comment it out by adding a # at the beginning of the line.
4. Save the file and exit.
5. Reboot the system to make sure the changes take effect.
Swapping or swap space represents a physical memory page that lives on top of a disk partition or a special disk file used for extending the RAM memory of a system when the physical memory fills up.
Using this method of extending RAM resources, inactive memory pages are frequently dumped into the swap area when no RAM is available. However, due to the spinning speed of classical hard disks, swap space is way lower in transfer speeds and access time compared to RAM.
On newer machines with fast SSD hard disks, reserving a small partition for swapping can greatly improve access time and speed transfer compared to classical HDD, but the speed is still magnitudes lower than RAM memory.
Some suggest that the swap space should be set as twice the amount of machine RAM. However, on systems with more than 4 GB of RAM, swap space should be set between 2 or 4 GB.
In case your server has sufficient RAM memory or does not require the use of swap space or the swapping greatly decreases your system performance, you should consider disabling the swap area.
How to Check Swap Space in Linux
Before actually disabling swap space, first, you need to visualize your memory load degree and then identify the partition that holds the swap area, by issuing the below free command.
# free -h
Look for the Swap space used size. If the used size is 0B or close to 0 bytes, it can be assumed that swap space is not used intensively and can be safely disabled.
How to Check Swap Partition in Linux
Next, issue following the blkid command, look for TYPE="swap"
line in order to identify the swap partition, as shown in the below screenshot.
# blkid
Again, issue the following lsblk command to search and identify the [SWAP]
partition as shown in the below screenshot.
# lsblk
How to Disable Swap in Linux
After you’ve identified the swap partition or file, execute the below command to deactivate the swap area.
# swapoff /dev/mapper/centos-swap
Or disable all swaps from /proc/swaps, which provides a snapshot of the swap file name.
# swapoff -a
Run free command in order to check if the swap area has been disabled.
# free -h
How to Disable Swap Permanently in Linux
In order to permanently disable swap space in Linux, open /etc/fstab file, search for the swap line and comment on the entire line by adding a #
(hashtag) sign in front of the line, as shown in the below screenshot.
# vi /etc/fstab
Afterward, reboot the system in order to apply the new swap setting or issue mount -a
command in some cases might do the trick.
# mount -a
After the system reboot, issuing the commands presented at the beginning of this tutorial should reflect that the swap area has been completely and permanently disabled in your system.
# free -h # blkid # lsblk
How to Permanently Disable Swap Partition in Linux
Swap partitions are used to provide virtual memory on Linux systems. They are used to extend the amount of physical memory available to the system. However, in some cases, it may be necessary to permanently disable the swap partition. This article will explain how to do this.
Step 1: Check the Current Swap Partition
Before disabling the swap partition, it is important to check the current swap partition. This can be done by running the command swapon -s
. This will show the current swap partition and its size.
Step 2: Disable the Swap Partition
Once the current swap partition has been identified, it can be disabled by running the command swapoff -a
. This will disable all swap partitions on the system.
Step 3: Remove the Swap Partition from fstab
The next step is to remove the swap partition from the /etc/fstab
file. This file contains information about the partitions that are mounted at boot time. To remove the swap partition from this file, open it in a text editor and delete the line that contains the swap partition.
Step 4: Reboot the System
Once the swap partition has been disabled and removed from the /etc/fstab
file, the system must be rebooted for the changes to take effect. After the system has been rebooted, the swap partition will no longer be used.
Conclusion
Disabling the swap partition in Linux is a relatively simple process. By following the steps outlined in this article, it is possible to permanently disable the swap partition on a Linux system.