// edited by joekamprad (12.8.2020)
To add after installation there are two options, using Gparted on the Live ISO or creating a swap file.
Just a note, it’s not recommended making a swap partition on a SSD, this can damage the medium.
Making a swap partition with Gparted
Boot your machine with the Live ISO and open Gparted. Select the last partition on your HDD (this can either be the Root partition or the Home partition, depending on how you partitioned your disk) and shrink the partition by leaving a disk space free equal to the size of your RAM or double the size, that’s up to you. Then select the free space and mark it as a swap partition, let Gparted do its work and boot back into your installed system and swap should be recognized by systemd. To check enter:
Making a swap file
The above method is the easiest one, but it can damage your partition you’ve shrunk. So you can also make a swap file.
just run the following command:
sudo fallocate -l xxG /swapfile
Preallocated files created by fallocate(1) may be interpreted as files with holes too depending of the filesystem.
As documented here: swapon.8#Files_with_holes
So as Archwiki recommend better to use dd command with some danger of using a Destroyer of Disks.
Notes if you are using Btrfs:
sudo truncate -s 0 /swapfile sudo chattr +C /swapfile sudo btrfs property set /swapfile compression none
Use dd to create a swap file the size of your choosing. For example, creating a 512 MiB swap file (for all fileystems)
sudo dd if=/dev/zero of=/swapfile bs=1M count=512 status=progress
Replace count=512 with the amount of MB you want to install for swap use. then:
sudo chmod 600 /swapfile
To give the swap file root-only permissions.
sudo mkswap /swapfile
To make the file as swap space and finally to enable the file:
sudo swapon /swapfile
Edit the fstab configuration to add an entry for the swap file:
/swapfile none swap defaults 0 0
Note: The swap file must be specified by its location on the file system not by its UUID or LABEL.
Remove swap file:
To remove a swap file, it must be turned off first and then can be removed:
sudo swapoff /swapfile sudo rm -f /swapfile
Finally remove the relevant entry from