Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Linux Distributions»Ubuntu»How to Add Swap Space on Ubuntu 20.04

    How to Add Swap Space on Ubuntu 20.04

    RahulBy RahulMay 29, 20203 Mins ReadUpdated:March 15, 2021

    Swap is a location on harddisk is used as Memory by the operating system. When the operating systems detects that main memory is getting full 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.

    I have a virtual machine running which don’t have swap on it. Many times services got crashed due to insufficient memory. In this situation creation of Swap file is better to keep them up. This article will help you to create a swap file on Linux system after installation.

    How to Add Swap in Ubuntu 20.04

    Follow the below steps to create and enable Swap memory on your Ubuntu system.

    1. Check Current Swap

    Before working make sure that system has already swap enabled. If there is no swap, you will get output header only.

    sudo swapon -s
    

    check swap ubuntu

    2. Create Swap File

    Lets create a file to use for swap in system of required size. Before making file make sure you have enough free space on disk. Generally, it recommends that swap should be equal to double of installed physical memory.

    My Digital ocean droplet has 2GB memory. So creating the swapfile of 4GB in size.

    sudo fallocate -l 4G /swapfile
    chmod 600 /swapfile
    

    The, make it to swap format and activate on your system by running following commands:

    sudo mkswap /swapfile
    sudo swapon /swapfile
    

    3. 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:

    sudo 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.

    4. Check System Swap Memory

    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

    5. Update Swappiness Parameter

    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

    In this tutorial, you have learned about creating of Swap memory on Ubuntu system.

    Memory swap swapfile Ubuntu 20.04
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow To Add Swap Space on Debian 10
    Next Article How to Install Apache with Python Mod_wsgi on Ubuntu 20.04

    Related Posts

    Changing the Login Screen Background in Ubuntu 22.04 & 20.04

    Updated:May 9, 20222 Mins Read

    (Resolved) Please install all available updates for your release before upgrading

    2 Mins Read

    How to Install LightDM Display Manager on Ubuntu

    Updated:May 10, 20222 Mins Read

    Change Screen Resolution of An Ubuntu VM in Hyper-V

    Updated:May 2, 20222 Mins Read

    How to Check IPv4 Address on Ubuntu 22.04

    2 Mins Read

    How to Configure Static IP Address on Ubuntu 22.04

    Updated:May 4, 20223 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    • (Resolved) Please install all available updates for your release before upgrading
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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