Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»General Articles»How To Add Swap Space on Debian 11

    How To Add Swap Space on Debian 11

    By RahulSeptember 11, 20213 Mins Read

    Swap memory is a location on hard disk to be used as Memory by the operating system. When the operating systems detects that main memory is low and required more RAM to run applications properly it check for swap space and transfer files there. In general terms, swap is a part of the hard disk used as RAM on the system.

    Advertisement

    This tutorial will help you to Add Swap on Debian 11 Bullseye Linux system.

    How to Create Swap in Debian 11

    Use the below steps to create and enable Swap memory on your Debian 11 system via command line.

    1. First of all, Check that no Swap memory is enabled on your system. You can see the swap memory details by running the following commands.
      sudo swapon -s 
      free -m 
      

      Check Available Swap Memory
      Check Available Swap Memory
    2. Now, create a file to use as swap in your system system. Make sure you have enough free disk available to create new file. Also keep the swap just up to 2x of the memory on your system.

      My Debian system have 2GB of main memory. So we will create a swapfile of 4GB in size.

      sudo fallocate -l 4G /swapfile 
      chmod 600 /swapfile 
      
    3. Now use the mkswap command to convert file to use for swap memory.
      sudo mkswap /swapfile 
      
    4. Then activate the swap memory on your system.
      sudo swapon /swapfile 
      
    5. You have successfully added swap memory to your system. Execute one of the below commands to view current active swap memory on your system:
      sudo swapon -s 
      free -m 
      

      add swap on ubuntu
      Swap is Added to your System

    Make Swap Permanent

    After running above commands, Swap memory is added to your system and operating system can use when required. But after reboot of system swap will deactivate again.

    You can make it permanent by appending the following entry in /etc/fstab file. Edit fstab file in editor:

    vim /etc/fstab 
    

    and add below entry to end of file:

    /swapfile   none    swap    sw    0   0
    

    Add swap in fatab

    Save file and close. Now Swap memory will remain activate after system reboots.

    Configure Swappiness

    Now change the swappiness kernel parameter as per your requirement. It tells the system how often system utilize this swap area.

    Edit /etc/sysctl.conf file:

    sudo vim /etc/sysctl.conf 
    

    append following configuration to end of file

    vm.swappiness=10
    

    Now reload the sysctl configuration file

    sudo sysctl -p 
    

    Conclusion

    Now the operating system can use swap memory in case of low physical memory. In this tutorial, you have learned to create and enable Swap memory on Debian 11 Linux system.

    debian Memory swap
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    20 Basic Linux Commands for the Beginners (Recommended)

    tail Command in Linux with Examples

    What is a Orphan Process in Unix/Linux

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • 20 Basic Linux Commands for the Beginners (Recommended)
    • tail Command in Linux with Examples
    • What is a Orphan Process in Unix/Linux
    • How To Display Warning Message to Unauthorized SSH Access
    • How to Set a Custom SSH Login Banner and MOTD
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.