Creating a Swap Partition

  1. Create the swap partition by using either fdisk or parted.

    • If using fdisk, create the partition as discussed in Creating Partitions. Then use t to change the partition type from the default to 82 Linux swap / So.

    • If using parted, specify linux-swap at the File system type? prompt as shown in Partitioning Disks by Using parted.

  2. Initialize the partition as a swap partition.

    For example, if the partition is /dev/sda2, use the following command:

    sudo mkswap /dev/sda2
  3. Enable swapping to the swap partition.

    sudo swapon /dev/sda2
  4. Add an entry to /etc/fstab for the swap partition so that the system uses it following the next reboot, for example:

    /dev/sda2       swap       swap       defaults       0 0