Resize swap in Ubuntu 18.04 and later (Linux)

PROBLEM: My swap is too small ๐Ÿ™
SOLUTION: Disable, resize and enable swap again!

1. Disable swap

sudo swapoff -a


2. Resize swap

With goal of 2 GB (1 GB * 2)

sudo dd if=/dev/zero of=/swapfile bs=1G count=2

Where:
if โ€“ input file
of โ€“ output file
bs โ€“ block size
count โ€“ block multiplier

Note: If you get error:
dd: memory exhausted by input buffer of size 1073741824 bytes (1.0 GiB)
just try to change the bs to MB and increase the count size

sudo dd if=/dev/zero of=/swapfile bs=1M count=2000


3. Make the file swap again!

sudo mkswap /swapfile


4. Activate swap

sudo swapon /swapfile


(5.) Check the swap file size using top or grep

grep SwapTotal /proc/meminfo

Leave a Reply

Your email address will not be published. Required fields are marked *