17.2.2 Creating and Using a Swap File


Configuring a swap file on a btrfs file system is not supported.

To create and use a swap file:

  1. Use the dd command to create a file of the required size (for example, one million one-kilobyte blocks):

    # dd if=/dev/zero of=/swapfile bs=1024 count=1000000
  2. Initialize the file as a swap file:

    # mkswap /swapfile
  3. Enable swapping to the swap file:

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

    /swapfile       swap       swap       defaults       0 0