Articles → AWS → Swap space in AWS EC2 instances

Swap space in AWS EC2 instances






Purpose






  1. Content that is not in active use
  2. Content that is not required urgently

How To Implement Swap Space?


  1. First, launch a Linux EC2 instance. Once the EC2 instance is launched
  2. Use MobaXterm to connect to the instance
  3. Use the dd command to create the swap file
  4. sudo dd if=/dev/zero of=/swapfile bs=128M count=32




  5. Update the read and write permission of the swap file using the following command
  6. sudo chmod 600 /swapfile


  7. Set up the Linux swap area
  8. sudo mkswap /swapfile


  9. Make the swap file available
  10. sudo swapon /swapfile


  11. Start the swap file at boot time by editing the /etc/fstab file
  12. sudo vi /etc/fstab


  13. Add the following new line at the end of the file, save the file, and then exit
  14. /swapfile swap swap defaults 0 0



How To Check If A Swap Space Is Implemented Successfully?


free -m


Picture showing checking the swap sapce using the free -m command
Click to Enlarge

sudo swapon -s


Picture showing checking the swap space using the sudo swapon -s command
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Thursday, May 12, 2022

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250