19.2.3 Creating and Using a Swap Partition

To create and use a swap partition:

  1. Use fdisk to create a disk partition of type 82 (Linux swap) or parted to create a disk partition of type linux-swap of the size that you require.

  2. Initialize the partition (for example, /dev/sda2) as a swap partition:

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

    # swapon /swapfile
  4. Add an entry to /etc/fstab for the swap partition so that the system uses it following the next reboot:

    /dev/sda2       swap       swap       defaults       0 0