Removing Swap Space

To remove a swap partition:

  1. The hard drive can not be in use (partitions can not be mounted, and swap space can not be enabled). The easiest way to achieve this it to boot your system in rescue mode. Refer to Chapter 8 for instructions on booting into rescue mode. When prompted to mount the filesystem, select Skip.

    Alternately, if the drive does not contain any partitions in use, you can unmount them and turn off all the swap space on the hard drive with the swapoff command.

  2. At a shell prompt as root, execute the following command to make sure the swap partition is disabled (where /dev/hdb2 is the swap partition):

    swapoff /dev/hdb2
  3. Remove its entry from /etc/fstab.

  4. Remove the partition using parted or fdisk. Only parted will be discussed. To remove the partition with parted:

    • At a shell prompt as root, type the command parted /dev/hdb, where /dev/hdb is the device name for the hard drive with free space.

    • At the (parted) prompt, type print to view the existing partitions and determine the minor number of the swap partition you wish to delete.

    • At the (parted) prompt, type rm MINOR, where MINOR is the minor number of the partition you want to remove.

      WarningWarning
       

      Changes take effect immediately; you must type the correct minor number.

    • Type quit to exit parted.

To remove a swap file:

  1. At a shell prompt as root, execute the following command to disable the swap file (where /swapfile is the swap file):

    swapoff /swapfile
  2. Remove its entry from /etc/fstab.

  3. Remove the actual file:

    rm /swapfile