Linux Tip: Managing Swap Partitions



We are not entirely certain why the swap partition was not added to the /etc/fstab, however, we noticed when running top that our swap space was showing up as 0k available, 0k used. This was a recent problem found on one of the web servers hosting http://forums.techguy.org. The web server had a fresh install of Fedora Core 4 but didn't appear to have any swap space. Following are the steps taken to correct the problem.

First we needed to determine if the swap partition existed. To do this we issued the following command as root:
fdisk -l
Disk /dev/hda: 10.2 GB, 10245537792 bytes
255 heads, 63 sectors/track, 1245 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 32 257008+ 83 Linux
/dev/hda2 33 163 1052257+ 82 Linux swap / Solaris
/dev/hda3 164 1245 8691165 83 Linux

As we learned from the above, our swap partition was available at /dev/hda2.

Once you know the location of your swap partition it is very easy to configure a running Linux system to make use of the partition.
It is as easy as:
swapon /dev/hda2

Now our running system is making use of the partition, but now we need to make sure the system will boot with the swap partition enabled.
To do this an entry needs to be added to the /etc/fstab. Following is the entry we added to make sure the partition was used at boot time.

/dev/hda2 swap swap defaults 0 0