Linux 101 : Swap memory - Using a partition as a swap space (mkswap, swapon) -

To be able to run a program, the operating system loads the program into the RAM.
When the RAM is full, programs can't function properly. To fix that we allocate a part of the hard drive and use it as a "slower" extension of the RAM, this is what is called the Swap space.
The less frequently accessed data is written to the disk to free up the RAM.
A Swap space could be a partition, a logical volume or a file.

Using a disk partition as a Swap space:

We are going to create a partition on the disk /dev/sdb using the fdisk partition tool:

Changing the partition type to "Linux swap":

Writing the changes to the disk:

We then write the changes to the disk using the below command:

Creating the swap partition:

We create the swap partition using the below command:

Then we turn the swap space on so we could use it:

ow our swap space is ready for use.

Checking the Swap space:

We can check the swap memory using the below command:

Adding teh swap space to the "/etc/fstab" file:

To be able to have access to the Swap space after a reboot, we add the below line to the "/etc/fstab" file:


Leave as a comment: