How to Create Swap memory over loop Device in Linux

  • Let’s explore how to create virtual memory, also known as swap memory, in Linux using a loop device. It’s an exciting process that can significantly enhance your system’s performance.
    • To begin, use the dd command to create a file:
    • # dd if=/dev/zero of=a.txt bs=1M count=400
    • Once the file is created, let’s attach it to a loop device:
    • #losetup /dev/loop0 a.txt

format the loop device /dev/loop0 with mkswap

  1. #mkswap /dev/loop0
  2. Then activate swap using swapon command.
  3. #swapon /dev/loop0

Now you can check you Swap memory using free -m command

  1. #free -m

Also you can verify swap is created over loop device or not using below command.

  1. cat /proc/swaps

How to Remove swap memory:Learn removal process.

  1. First run swapoff command to Disable swap memory
  2. #swapoff /dev/loop0
  3. Now deattach loop device from file using below command.
  4. # losetup -d /dev/loop0
  5. Time to cross check the removal.
  6. losetup -a
  7. At latst time to delete file a.txt we created.
  8. # rm -rf a.txt

Discover more from Learn Linux CCNA CCNP CEH CISSP CISA Penetration-Testing Bug Bounty IPv6 Cyber-Security Network-Security Online

Subscribe to get the latest posts to your email.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.