Ubuntu won’t boot after changing swap size and running out of space
Solution 1:
It seems you’ve asked your computer to make a 130GB swap file rather than an 8GB file. You will need to do the following:
- Boot into recovery (or with a Live USB stick)
- Confirm that you’re not using a swap file:
sudo swapoff -a
- Delete the oversized swap file that you created:
IMPORTANT: You will need to change the name of the file in this command fromsudo rm -f /swappyswapswap
swappyswapswap
to the proper name of the big swap file in your/
directory. The file name in this command is intentionally wrong so that you — hopefully — do not blindly copy asudo rm
command, as there is no undo. - Confirm your system now has space:
df -h
- Create an 8GB file full of zeros, which will become your swap:
sudo dd if=/dev/zero of=/swapfile bs=1M count=8192 status=progress
- Set the new file as your swap:
sudo mkswap /swapfile
- Add the new swap file to your
/etc/fstab
file:
Note: Feel free to use any text editor of your choosing to modify this file. Just remember to open the file withsudo vi /etc/fstab
sudo
as it is owned byroot
.
Add this line to the bottom:
This will ensure the swap file is mounted every time you reboot./swapfile none swap sw 0 0
- Restart the system normally.
Be sure to read, understand, and agree with every one of these steps before copy/pasting them.