Home VPN WorkPlace Web Sites/Apps Small Business Other Apps Contact Guides

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
CAMM Services Application Design
Brantford PC
Norfolk County PC
R.D. Cookson Disposal Ltd.
Web Site Design Brantford, Ontario
Web Site & Application Development Norfolk County, Ontario
Various front loader and roll off bin rentals in Simcoe, Ontario
3D Marketing and Exhibit Specialists, Greater Toronto Area
Robert Jones Marine Technical Services