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
1 |
sudo swapoff -a |
2. Resize swap
With goal of 2 GB (1 GB * 2)
1 |
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
1 |
sudo dd if=/dev/zero of=/swapfile bs=1M count=2000 |
3. Make the file swap again!
1 |
sudo mkswap /swapfile |
4. Activate swap
1 |
sudo swapon /swapfile |
(5.) Check the swap file size using top or grep
1 |
grep SwapTotal /proc/meminfo |
Hey, it is not restart persistent, how to make it?
Probably you have dedicated partition for swap, instead of file (verify running sudo swapon –show), you will see the type. In case it is a partition, you have to resize it and it will remain persistent after a reboot. 🙂