Administering Filesystems  «Prev  Next»

Lesson 5 Enabling swap space
Objective Enable swap space.

Enabling swap Space

Swapping uses space on a hard disk as an extension of a computer's RAM. By utilizing swap, the operating system pretends that more RAM is available than the machine actually contains.
Swapping: Swapping uses space on a hard disk as an extension a computer\'s RAM. By utilizing swap, the operating system pretends that more RAM is available than the machine actually contains. The oldest files in RAM are "swapped out" to the swap partition until they are needed so that other data can be "swapped in" to RAM.
Your swap should be about three times your RAM, or 256MB, whichever is smaller. You should add more swap as needed, but only if adding RAM isn't an option. If your system has multiple drives, set up a swap partition on each disk. The system views all swap space the same, but when it reads and writes to the swap space, the multiple hard disks allow parallel accesses, increasing performance. However, Linux limits you to eight swap partitions, which means you can't put a swap partition on more than eight hard drives.
Execute the following steps to create a swap partition:
  1. Set up the partition table and add a swap partition (or create a swap file instead) using either the fdisk or cfdisk utility.
  2. Reboot the system.
  3. Create the swap partition using mkswap.
  4. Add an entry for the swap to /etc/fstab.
  5. Activate the swap partition or file using swapon -a.
  6. Check the swap partition's status using swapon -s.

The following Simulation steps you through the process of adding additional swap space.
add swap space.
The next lesson explains how to add new drives.

Adding Additional Swap Space

  1. Partitions are created and deleted with the fdisk or cfdisk programs. Set up the partition table and add a swap partition to the device hda using fdisk by typing fdisk /dev/hda.
  2. Enter n to create a new partition. Press Enter.
  3. Enter p to set up the partition as a primary partition. Press Enter.
  4. Set up /dev/hda2 as a partition by entering 2 for the partition number. Press Enter.
  5. Set up /dev/hda2 as a 128MB partition by entering +128M for the size. Press Enter.
  6. Change the /dev/hda2 to a swap partition by entering t for type. Press Enter.
  7. Change the /dev/hda2 to a swap partition by entering 2 for the partition number, and 82 as the hex code. Press Enter.
  8. Type q to quit fdisk. Press Enter.
  9. Here are the final results of creating the 128MB swap partition on /dev/hda2. Type the command mkswap /dev/hda2 to initialize the swap partition. Press Enter.
  10. Click anywhere on the screen to continue.
  11. Add an entry for the swap to the /etc/fstab file, in this case: /dev/hda2 swap swap defaults 0 0. Click anywhere on the screen to continue.
  12. The file /etc/fstab will contain the above after adding an entry for the swap to /etc/fstab. Click anywhere on the screen to continue.
  13. Activate the swap partition typing swapon -a, which reads /etc/fstab and turns on all swap entries listed therein. Press Enter.
  14. Verify the swap partition's status by typing swapon -s or the free command. Press Enter.
  15. Here are the results of checking the swap partition's status using swapon -s. This completes the Simulation.


Implementing Swap Space

Before moving on to the next lesson, click the Exercise link to check your understanding of how to implement swap space.
Implementing Swap Space

Implementing swap space

  1. Set up the partition table and add a swap using the cfdisk utility.
  2. Reboot the system before continuing.
  3. Enable the swap partition using mkswap or fdisk.
  4. Add an entry for the swap to /etc/fstab.
  5. Activate the swap partition or file using swapon -a.
  6. Check the swap partition's status using swapon -s or free.