Linux : How to create swap area on a live system

By | February 16, 2013

This article is about how to create swap space on a live RHEL/CentOS Linux system. However you can still follow that procedure in case you messed up your filesystem and swap is now non-existent (e.g.: swap show 0M).

First, use fdisk to edit the partition table and create a partition (this step might be skipped if you already have one) :

Useful fdisk commands are :

m = help
p = show the partition layout
n = create a partition
t = change partition type
w = write changes
q = quit fdisk utility

Then, show your current partition layout (hit “p” key) :

(We can see we have no swap area here!)

Let’s create a partition (hit “n” key) :

(Select extended or primary depending on your situation. We’ll use extended here)

Change the type of your brand new partition for swap use (hit “t” key and enter “82” as hex code) :

Now write the changes to the partition table (hit “w” key and then “q”).

We are now ready to format the partition as swap, use “mkswap” command :

Will return :

The last step is to set (or modify if the swap where accidental removed) the partition UUID in fstab :

Config line shoud looks like :

Final step, enable the swap!