Swap: how to set up a swap partition or file
A swap partition or file is useful for extending RAM with disk space or for being able to hibernate the device.
Table of Contents
- Reserve disk space
- Create swap
- Enable swap
- Editing fstab file
Reserve disk space
You can create a swap partition or a swap file with at least the same size as your RAM (if you want to hibernate your system). It can be less if you are not going to hibernate your device.
Create a partition
Create a partition (with
fdisk for example).
Create a file
dd if=/dev/zero of=<file path> bs=1M count=<size in megabytes> chmod 600 <file path>
mkswap <partition path> # e.g.: mkswap /dev/sda5 # or mkswap <swap file path> # e.g.: mkswap /swap/swapfile
swapon <partition path> # or swapon <swap file path>
Editing fstab file
Append this line to the
<swap file path> none swap defaults 0 0 # or UUID=<swap UUID> none swap defaults 0 0
- You can find swap partition UUID by running
swapoff <swap partition or swap file> # or swapoff -a
If you have any suggestion, feel free to contact me via social media or email.
Latest tutorials and articles: