This guide assumes your root partition (/dev/sda2 or /) is full.
Use the du (disk usage) command to locate the directories consuming the most space.
-
Change directory to root:
cd / -
Run
duand sort the results:sudo du -sh /* | sort -h
This lists the sizes of all top-level directories (e.g.,
/var,/home,/usr) in human-readable format, sorted by size. -
Drill down: If
/varshows a huge size, investigate it further:sudo du -sh /var/* | sort -h
Focus your cleanup efforts on the largest directories (often
/var/logor/home).
The fastest way to free up gigabytes of space is usually by clearing system caches and logs.
The system journal can grow extremely large. Set a maximum size and remove the excess immediately.
- Clean logs, keeping the last 500MB (or less, if space is critical):
You can substitute
sudo journalctl --vacuum-size=500M
500Mwith a lower value if needed.
Remove stored installation packages (.deb files) and unnecessary libraries/old kernels.
- Clear the package cache:
sudo apt clean
- Remove unused dependencies and old kernel files:
sudo apt autoremove --purge
Files that have been deleted but are still being held open by a running process (like a large log file) still consume disk space.
- List open deleted files:
Note the PID (Process ID) and the file NAME.
sudo lsof | grep deleted - Truncate or restart:
- Truncate (Clear contents) a log file (safer than killing the process):
sudo truncate -s 0 /path/to/large/log/file
- Restart the associated service (e.g.,
sudo systemctl restart nginx).
- Truncate (Clear contents) a log file (safer than killing the process):
Set a permanent size limit on your system journal to prevent future disk saturation.
-
Edit the configuration file:
sudo nano /etc/systemd/journald.conf
-
Set the maximum log usage (e.g., to 1 Gigabyte) by adding/editing this line under the
[Journal]section:SystemMaxUse=1G -
Save, exit, and restart the service:
sudo systemctl restart systemd-journald
Always confirm the fix by checking the available space:
df -hGoal: See the /dev/sda2 usage percentage drop significantly.