Close Menu
Technoracle
    Facebook X (Twitter) Instagram
    Facebook X (Twitter) Instagram
    TechnoracleTechnoracle
    • Home
    • AWS
      • EC2
      • Lightsail
      • RDS
      • S3
    • Ubuntu
      • Ubuntu 20.04
      • Ubuntu 22.04
    • AI Tools
    • Web Hosting
    • WordPress
    • Tech News
    Technoracle
    Home - Uncategorized - How to Create Linux Swap File Easily
    Uncategorized

    How to Create Linux Swap File Easily

    Rajesh ShivamBy Rajesh ShivamMarch 29, 2022No Comments2 Mins Read
    Create Linux Swap File
    Create Linux Swap File

    Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the primary memory(RAM) is full, inactive pages in memory are moved to the swap space. In this step-by-step tutorial, I am going to create Linux swap file easily.

    Page Contents

    Toggle
    • Steps to Create Linux Swap File
      • Step 1: Create a file for swap setup
      • Step 2: Set Permission for Swap File
      • Step 3:  Set up a Linux swap area
      • Step 4: Enable the swap
      • Step 5: Verify Swap Setup
      • Step 6: Enable Swap on startup
    • Conclusion

    Steps to Create Linux Swap File

    Now, I will create 2GB linux swap file, if you need more you can change the value of 2G.

    Step 1: Create a file for swap setup

    Create a file for swap using following command.

    $ sudo fallocate -l 2G /swapfile

    Step 2: Set Permission for Swap File

    Set permission for swap file. Only root user should read and write the swap file.

    $ sudo chmod 600 /swapfile

    Step 3:  Set up a Linux swap area

    Use mkswap utility for linux swap area.

    $ sudo mkswap /swapfile

    Step 4: Enable the swap

    Make the swap file available for immediate use by adding the swap file to swap space. To make swap available use following command.

    $ sudo swapon /swapfile

    Step 5: Verify Swap Setup

    Verify that the swap setup successful, run following command.

    $ sudo swapon -s

    Step 6: Enable Swap on startup

    To swap enable on startup, edit following file.

    $ sudo vi /etc/fstab

    Add the following new line at the end of the file, save the file, and then exit

    /swapfile swap swap defaults 0 0

    Conclusion

    In this short step-by-step guide, you have learned to create Linux swap file. If you have any doubts feel free to contact me, I will definitely try to help you. Also, you can join our elite Facebook group to get direct help from me. If you like this tutorial, please share this article on your social media handle.

    create swap linux swap file
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit
    Previous Article[Easily Guide] How to Install PrestaShop on Ubuntu 20.04
    Next Article Best WordPress Hosting for Bloggers
    Rajesh Shivam
    • LinkedIn

    Rajesh Shivam is a seasoned professional with expertise in AWS and Linux System Administration. With over 10 years of freelancing experience, he brings a wealth of knowledge to the table. Rajesh has a strong passion for technology and stays connected with the latest happenings in the field. His dedication and expertise make him a trusted resource for all things tech-related.

    Related Posts

    Uncategorized

    How to Get your First Order On Fiverr in 2024 – 5 Proven tricks

    Read More
    Copy File from Local to Remote Server
    Uncategorized

    How to Copy File from Local to Remote Server Easily

    Read More
    increase execution time in PHP
    Uncategorized

    How to Increase Execution Time in PHP

    Read More
    Add A Comment
    Leave A Reply Cancel Reply

    linux commands every user should know in 2025

    25 Must-Know Linux Commands Every User Should Master in 2025

    April 10, 2025
    TeamViewer and Ubuntu logos on gradient background – banner for how to install TeamViewer on Ubuntu 24.04 tutorial

    How to Install TeamViewer on Ubuntu 24.04 [Fast & Easy Steps]

    April 10, 2025
    Troubleshooting ‘Permission Denied (publickey)’ SSH error on a Linux server using secure terminal access

    Fix ‘Permission Denied (publickey)’ SSH Error on Linux [Step-by-Step Guide]

    April 8, 2025
    Blog banner showing Ubuntu logo, coding laptop, and icons for VS Code, Docker, and Git with the title 'Perfect Dev Setup in Ubuntu 24.04 – Step-by-step guide for developers' on a dark tech-themed background.

    How to Set Up the Perfect Development Environment on Ubuntu 24.04

    April 8, 2025

    Subscribe to Blog

    Enter your email address to subscribe to
    this blog and receive notifications of new posts by email.

    Facebook X (Twitter) Instagram Pinterest
    • Sitemap
    • Privacy Policy
    • Disclaimer
    • Term of Services
    © 2025 Technoracle

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

    Click to Copy