Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
July 20, 2022 11:19 am GMT

Allocate swap memory to Ec2 linux instance or any other linux machine

- If you ever heard of the virtual memory, then in case of linux machines you are looking at swap memory.
- Swap space is the dedicated space from your hard disks or SSDs that is used when you Physical RAM is full.
- If the operating system is in need of more memory resources and the its RAM is full, inactive pages in memory are moved to the swap space. By inactive pages we mean the content that is not needed on urgent basis or not in use.

Before you start creating a swap file, you should check your Ubuntu system if it contains an existing swap file, use the command below to verify:

swapon --show

If output is empty, then you can create a new Swap file. Otherwise, If swap file is exist, then you can turn it on or else upgrade the size.

You can also run free command to check the memory information.

free -h

Image description

How to attach a swap memory

We can attach it to our server disk.
Suppose we have a disk attached to our server called sdc as shown

Image description

fdisk /dev/sdc

Image description

Type m for help

Image description

Type 'n' :- To add a new partition
Select 'p' for default

Enter partition number (1-4):1

Set the last sector partition size to 5G as shown below

Image description

Type 'p' to print partition table

Image description

Type 'l' to list know partition type

As you can see the swap id hex code is 82

Image description

Type 't' to change the partition

Enter Hex code as 82

Image description

We have successfully change the partition , Type 'p' to print the Partition.

Type 'w' to save and exit

Image description

partprobe is a program that informs the operating system kernel of partition table changes, by requesting that the operating system re-read the partition table.

partprobe /dev/sdc1

Image description

Now use the mkswap command to setup a Swap area

Image description

Using swapon command, we can use the newly created space for immediate use

Image description

You can now run free command to check the memory information.

free -h

Image description

Update the /etc/fstab file to use it at boot time only

Image description

Verify the newly created swap

Image description


Original Link: https://dev.to/shankarsurya035/allocate-swap-memory-to-ec2-linux-instance-or-any-other-linux-machine-2ldh

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To