This content originally appeared on DEV Community and was authored by Surya shankar
- 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
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
fdisk /dev/sdc
Type m for help
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
Type 'p' to print partition table
Type 'l' to list know partition type
As you can see the swap id hex code is 82
Type 't' to change the partition
Enter Hex code as 82
We have successfully change the partition , Type 'p' to print the Partition.
Type 'w' to save and exit
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
Now use the mkswap command to setup a Swap area
Using swapon command, we can use the newly created space for immediate use
You can now run free command to check the memory information.
free -h
Update the /etc/fstab file to use it at boot time only
Verify the newly created swap
This content originally appeared on DEV Community and was authored by Surya shankar
Surya shankar | Sciencx (2022-07-20T11:19:34+00:00) Allocate swap memory to Ec2 linux instance or any other linux machine. Retrieved from https://www.scien.cx/2022/07/20/allocate-swap-memory-to-ec2-linux-instance-or-any-other-linux-machine/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.