Ubuntu Swap Memory Storage

Swap Image File

Create Swap File
sudo fallocate -l 1G /swapfile.img
Set swap file permissions
sudo chmod 600 /swapfile.img
Prepare Swap on File
sudo mkswap /swapfile.img
Activate the Swap
sudo swapon /swapfile.img
Add swap to fstab
sudo nano /etc/fstab
Add the following
/swapfile.img swap swap defaults 0 0
Show Swaps
sudo swapon --show
Show Memory & Swap
sudo free -h

Swap Drive/Partition

List Drives and Locations
sudo blkid
Verify that the device is unmounted (Replace 'sdX' with device or 'sdX#' with partition)
sudo umount /dev/sdX
Format device
sudo mkswap /dev/sdX
Add Swap device to fstab (Note UUID from previous)
sudo nano /etc/fstab
UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX none swap sw,pri=5 0 0
Activate Swap
sudo swapon -a
List Swaps
cat /proc/swaps
To reduce Swapping we need to adjust swappiness. Values range from 0 (off) to 100 (aggressive), I use 10 to only swap when in need.
sudo nano /etc/sysctl.conf
Add/Edit the following
vm.swappiness = 10
To Stop Swap for editing use:
sudo swapoff -a