In this blog, We are going to create swap area in running ec2 instance, But before we are going on AWS for creating swap area in ec2 instance. We should have the answer of following question
- What Is Called Swap Area ?
- What Is Ideal Size Of Swap Area ?
- How To See Swap Area On Running Instance ?
So, Lets see the answer of each question one by one in below section
What Is Called Swap Area ?
What Is Ideal Size Of Swap Area ?
|Amount of RAM||Recommended swap space|
|≤ 2GB||"2X RAM"|
|2GB – 8GB||"= RAM"|
How To See Swap Area On Running Instance ?
[root@studentvm1 ~]# free
total used free shared buff/cache available
Mem: 4038808 382404 2754072 4152 902332 3404184
Swap: 10485756 0 10485756
Create Swap Area In Running EC2 Instance In AWS ?
- Use the dd command to create a swap file on the root file system, where “bs” is the block size and “count” is the number of blocks. In this example the swap file is 4 GB
$ sudo dd if=/dev/zero of=/swapfile bs=1G count=4
- Update the read and write permissions for the swap file
$ chmod 600 /swapfile
- Set up a Linux swap area
$ mkswap /swapfile
- Make the swap file available for immediate use by adding the swap file to swap space
$ swapon /swapfile
- Verify that the procedure was successful
$ swapon -s
- Enable the swap file at boot time by editing the /etc/fstab file
$ vi /etc/fstab $ /swapfile swap swap defaults 0 0
- You can also use the swapon -s command, or top, free, or any of several other commands to verify this.
$ free -h