How to Permanently Disable Swap in Linux? (2024)

How to Permanently Disable Swap in Linux? (1)

  • Trending Categories
  • Data Structure
  • Networking
  • RDBMS
  • Operating System
  • Java
  • MS Excel
  • iOS
  • HTML
  • CSS
  • Android
  • Python
  • C Programming
  • C++
  • C#
  • MongoDB
  • MySQL
  • Javascript
  • PHP
  • Physics
  • Chemistry
  • Biology
  • Mathematics
  • English
  • Economics
  • Psychology
  • Social Studies
  • Fashion Studies
  • Legal Studies
  • Selected Reading
  • UPSC IAS Exams Notes
  • Developer's Best Practices
  • Questions and Answers
  • Effective Resume Writing
  • HR Interview Questions
  • Computer Glossary
  • Who is Who

LinuxOpen SourceOperating System

';

Linux is a free and open-source operating system that is widely used in the tech industry. It is known for its stability, security, and flexibility. One of the key features of Linux is the ability to manage memory effectively using swap space. Swap space allows the system to use hard disk space as virtual memory, which helps to prevent the system from running out of memory.

In this tutorial, we will discuss how to permanently disable swap space in Linux. Disabling swap space is useful in situations where we have enough physical memory (RAM) and don't want the system to use hard disk space as virtual memory. It can also be useful in situations where the system has limited hard disk space, and we want to reclaim that space by disabling the swap. In the next section of the article, we will explain how to disable swap space temporarily before proceeding to the permanent solution.

How to Permanently Disable Swap in Linux?

Before we proceed with disabling swap space permanently, let's first understand what swap space is and how can we check it in linux.

Swap space is a portion of the hard disk that is used by the operating system as virtual memory. When the system runs out of physical memory (RAM), it moves inactive pages of memory to the swap space to free up space in the RAM for active processes. This helps to prevent the system from crashing due to a lack of memory.

To check the current swap usage, we can use the 'free' command. Open the terminal and type the following command

$ free -h

The output of this command will show us the current swap usage. The '-h' option is used to display the output in a human-readable format. Here is an example output

 total used free shared buff/cache availableMem: 7.7G 2.9G 2.0G 221M 2.7G 4.2GSwap: 2.0G 0B 2.0G

In the above output, the 'Swap' line shows us that the system has a total of 2.0 GB of swap space available. In this case, the 'used' column shows 0B, which means that the system is not currently using any swap space.

Now that we understand the basic of swap space, let’s move to the next section of this article to learn how can we disable the same.

Disabling Swap Usage

There are two ways to disable the usage of swap space in Linux, which are temporary and permanent. Temporarily disabling swap involves using the "swapoff" command to turn off swap space for the current session. While this method can be useful for testing purposes, it has some drawbacks, such as reducing the overall performance of the system and potentially causing crashes in applications that rely heavily on swap space. Therefore, it is recommended to only use this method for temporary testing purposes.

On the other hand, permanently disabling the swap involves editing the "/etc/fstab" file to remove the entry for the swap partition. This method ensures that swap space is disabled every time the system boots up. While it may require a bit more effort to set up, it provides a more reliable and long-term solution for managing memory usage on a Linux system.

To gain a better understanding of how to disable swap space in Linux, let's take a closer look at both methods in more detail.

Disable Swap Space Temporarily

To disable swap space temporarily using the "swapoff" command. This is useful if we need to perform maintenance on the system and want to prevent the system from using swap space during the maintenance.

To disable swap space temporarily, we can use the "swapoff" command followed by the device file of the swap partition. Open the terminal and type the following command −

$ sudo swapoff -a

The "-a" option tells the command to disable all swap devices. If we only want to disable a specific swap device, we can replace "-a" with the device file path (e.g. "/dev/sda3").

Once we have disabled swap space, we can perform our maintenance tasks without the system using swap space. However, there are some drawbacks to disabling swap space temporarily. For example, if the system runs out of physical memory (RAM) while the swap is disabled, the system may crash or become unresponsive. Additionally, disabling swap space can cause performance issues if the system is under a heavy memory load.

Now that we've covered how to temporarily disable swap space, let's move on to disabling it permanently.

Disable Swap Space Permanently

By disabling swap space permanently, you can ensure that the system will never use swap space again, unless you manually re-enable it. This provides a more reliable and long-term solution for managing memory usage on your Linux system.

To permanently disable swap space we need to edit the "/etc/fstab" file. This file contains configuration information for the file systems and swap space on the system.

Open a terminal and type the following command to open the "/etc/fstab" file in a text editor:

$ sudo nano /etc/fstab

Locate the line in the "/etc/fstab" file that specifies the swap partition. This line will include the word "swap" and the device file path for the swap partition.

Comment out this line by adding a "#" character at the beginning of the line. This will disable the line and prevent the system from using the swap partition. The line should now look something like this:

# /dev/sda3 none swap sw 0 0

Save the changes to the file and exit the text editor.

Finally, we need to disable the swap space on the system by running the following command:

$ sudo swapoff -a

This will immediately disable all swap space on the system.

To confirm that swap has been permanently disabled, we can run the "free -h" command again and check the "Swap" line. It should show "0B" in the "used" column, indicating that swap is no longer being used by the system.

Here's an example output of the "free -h" command after disabling swap space permanently −

 total used free shared buff/cache availableMem: 7.8G 1.1G 5.5G 108M 1.2G 6.3GSwap: 0B 0B 0B

As you can see in the above output, the "Swap" line shows "0B" for both the "used" and "free" columns, indicating that swap space is no longer being used by the system. If you see any other value for the "used" column, it means that swap space is still being used and you may need to double-check your configuration to ensure that it has been disabled permanently.

Conclusion

In this tutorial, we discussed how to permanently disable swap space in Linux, an operating system known for its stability, security, and flexibility. Swap space is the portion of the hard disk that is used by the operating system as virtual memory, which helps to prevent the system from running out of memory. We explained how to disable swap space temporarily before proceeding to the permanent solution. By disabling swap space permanently, we can ensure that the system will never use swap space again, providing a more reliable and long-term solution for managing memory usage on a Linux system.

Prince Yadav

Updated on: 27-Jul-2023

5K+ Views

  • Related Articles
  • How to disable action bar permanently in Android?
  • How to Disable SSH Root Login in Linux?
  • How to swap two files in Linux command line?
  • How to Increase Swap Space on Linux Ubuntu?
  • How to Disable Suspend and Hibernation Modes In Linux?
  • Set Up cURL to Permanently Use a Proxy on Linux
  • How to Disable Package Updates Using YUMDNF in RHEL Linux?
  • 3 Ways to Permanently and Securely Delete Files and Directories in Linux
  • How to disable delete permission of File and Directory in Linux?
  • How to find out which processes are using swap space in Linux?
  • How to set sql_mode permanently in MySQL?
  • How to create PowerShell alias permanently?
  • The Use of Swap Space in Modern Linux Systems
  • How to permanently delete a YouTube video?
  • How to Delete Data Permanently from a PC?
Kickstart Your Career

Get certified by completing the course

Get Started

How to Permanently Disable Swap in Linux? (31)

Advertisem*nts

';

How to Permanently Disable Swap in Linux? (2024)
Top Articles
Export an Existing Certificate From a Web Browser
Here Are the New Tax Brackets for 2024
Ron Martin Realty Cam
I Make $36,000 a Year, How Much House Can I Afford | SoFi
123 Movies Black Adam
Jackerman Mothers Warmth Part 3
Form V/Legends
Uihc Family Medicine
Top Financial Advisors in the U.S.
Rochester Ny Missed Connections
Lesson 1 Homework 5.5 Answer Key
Where's The Nearest Wendy's
Mycarolinas Login
Keurig Refillable Pods Walmart
iLuv Aud Click: Tragbarer Wi-Fi-Lautsprecher für Amazons Alexa - Portable Echo Alternative
SF bay area cars & trucks "chevrolet 50" - craigslist
Hennens Chattanooga Dress Code
Www.craigslist.com Savannah Ga
Ivegore Machete Mutolation
Egizi Funeral Home Turnersville Nj
480-467-2273
Roanoke Skipthegames Com
Panolian Batesville Ms Obituaries 2022
Watson 853 White Oval
Airg Com Chat
How to Use Craigslist (with Pictures) - wikiHow
Sony Wf-1000Xm4 Controls
Elanco Rebates.com 2022
Mercedes W204 Belt Diagram
The Bold and the Beautiful
Shaman's Path Puzzle
Weekly Math Review Q4 3
El agente nocturno, actores y personajes: quién es quién en la serie de Netflix The Night Agent | MAG | EL COMERCIO PERÚ
The Mad Merchant Wow
Tugboat Information
Temu Y2K
Nearest Ups Office To Me
Captain Billy's Whiz Bang, Vol 1, No. 11, August, 1920
America's Magazine of Wit, Humor and Filosophy
Mississippi weather man flees studio during tornado - video
Advance Auto.parts Near Me
Unlock The Secrets Of "Skip The Game" Greensboro North Carolina
Goats For Sale On Craigslist
R/Gnv
The Blackening Showtimes Near Ncg Cinema - Grand Blanc Trillium
Ouhsc Qualtrics
Wzzm Weather Forecast
Congruent Triangles Coloring Activity Dinosaur Answer Key
Colin Donnell Lpsg
Dolce Luna Italian Restaurant & Pizzeria
Hsi Delphi Forum
Salem witch trials - Hysteria, Accusations, Executions
Affidea ExpressCare - Affidea Ireland
Latest Posts
Article information

Author: Terrell Hackett

Last Updated:

Views: 6045

Rating: 4.1 / 5 (52 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Terrell Hackett

Birthday: 1992-03-17

Address: Suite 453 459 Gibson Squares, East Adriane, AK 71925-5692

Phone: +21811810803470

Job: Chief Representative

Hobby: Board games, Rock climbing, Ghost hunting, Origami, Kabaddi, Mushroom hunting, Gaming

Introduction: My name is Terrell Hackett, I am a gleaming, brainy, courageous, helpful, healthy, cooperative, graceful person who loves writing and wants to share my knowledge and understanding with you.