
Table of Contents
What is Swap?
This partition helps RAM by creating virtual memory when the system memory becomes full. When a computer runs out of RAM, the operating system temporarily moves data between RAM and a dedicated space on the disk, known as swap space.
To create this partition, we first need to add an additional disk to the server. In this case, a 10 GB disk will be added to the system.
As a standard practice, the virtual machine must be powered off before attaching the new 10 GB hard disk.

We have to click on “Edit virtual machine settings“.

We have to click on ‘Add‘ button and select ‘Hard Disk‘.

Click on Next.

We will go with the recommend option of SCSI. Click on Next.

We will go with the default option of “Create a new virtual disk“. Click on Next.

We will provide 10 GB of space in front of “Maximum disk size“. Click on Next.

Click on Finish and Power on the machine.
Now our new hard disk of 10 GB is attached with our server to make a partition for swap.
Let’s check our partition detail by ‘fdisk -l‘ command.

We got our 10 GB of hard disk with the name “/dev/sdc“.
Now, We have to make the partition of 5 GB for the swap. There would be the 2 steps that is creating the partition and formatting the partition.
We will create the partition by “fdisk /dev/sdc” command.

For new partition, We will press n.

We will go with the primary option by pressing p.

We will go with partition number 1 as it is our first partition.

For the first sector, We will go with default and press enter.

Now, We have to give the size by adding +5G for 5 GB.

Next, We have to change the partition type to swap from Linux by pressing t and type 82.

We have to press w for writing and quitting from the hard disk. If you want to learn more about partitions then click on the link.
We have to settle our partition by “udevadm settle” command.
Now we will check our partition by “fdisk -l” command.

As we can see that we get “/dev/sdc1” of 5 GB and of swap type.
We can check our current RAM space by “free -m” command.

As we can see, there is currently no virtual memory available on the server, even though a partition has already been created for it.
Next, we format this partition using the mkswap (partition name) command. In our case, the new partition name is /dev/sdc1, so the command used is mkswap /dev/sdc1.

The new memory space has now been created, and the next step is to activate it using the swapon (partition name) command. In this case, the command used is swapon /dev/sdc1.

We can check our partition by “swapon -s” command.

Now last step is to make our partition permanent by adding it in “/etc/fstab” file.

We can save “/etc/fstab” file and check it by “mount -a” for errors.
That’s all!
Thanks for Learning with us. You can downaload the iso file from here.
FAQ’s
Q. Why do I need swp memory?
A. Swp memory helps keep the system stable when physical RAM gets fully utilized. When RAM is exhausted, this memory provides extra space so the system can continue running smoothly instead of freezing or terminating active processes. Without it, systems with limited RAM are more likely to crash under heavy load.
Q. How does swp memory work?
A. When physical RAM becomes full, the operating system moves less frequently used data from RAM to disk storage. This process is known as paging. When that data is needed again, it is brought back into RAM. This mechanism allows the system to manage memory efficiently and remain responsive.
Q. Is swp space the same as virtual memory?
A. Swp space is a part of virtual memory. Virtual memory is a broader concept that allows the operating system to extend usable memory beyond physical RAM. Swp space acts as the disk-based area that supports this memory extension.
Q. How much swap space should I allocate?
A. The recommended amount of swp space depends on your system’s RAM and workload. Common guidelines include:
1. For systems with 4GB or less of RAM: 2 times the amount of RAM.
2. For systems with 4GB–8GB of RAM: 1.5 times the amount of RAM.
3. For systems with more than 8GB of RAM: At least 8GB, or an amount based on your workload (e.g., heavy applications or large datasets). However, these are just guidelines. Modern systems with plenty of RAM may not need as much swp, and SSDs can mitigate some of the speed differences.
Q. Can I increase or decrease space?
A. You can create or resize this files or partitions by adjusting swap space size.
Q. What is “swap usage” and how do I check it?
A. Swap usage refers to the amount of swap space that the system is currently using. You can check swap usage using system monitoring tools like vmstat, top and free -h
Discover more from Root Learning
Subscribe to get the latest posts sent to your email.
Another nice stuff after partitions
I’m extremely impressed along with your writing skills as smartly as with the format to your weblog.
Is that this a paid subject matter or did you modify it yourself?
Anyway stay up the excellent high quality writing, it’s uncommon to peer a great blog like this one these days.
Upto the mark 👍🏻
Nice post, Good going!
Swap is one of the important topics in Linux, Thanks for covering it here!