
One of the most common problems Linux users face, especially on systems with limited disk space, is the root
partition (/)
getting completely full.
When this happens, you may encounter errors such as:
No space left on device
Don’t panic! It just means your root directory (the /
partition) is full, which is a common issue, especially on systems with limited disk space or servers running 24/7.
When this happens, you may experience problems such as:
- Inability to install or upgrade packages.
- Failure to boot the system.
- Services not starting.
- Logs or temporary files not being written.
In this article, we’ll walk you through practical steps to identify the issue, safely clean up space, and prevent this from happening again. These instructions are suitable for both beginners and intermediate users.
Step 1: Check Disk Usage in Linux
The first step is to confirm the issue using the df command, which will displays the space used and available on the root partition. If the usage is 100%, it’s time to take action.
df -h /
Now let’s locate which folders are consuming the most space.
sudo du -h --max-depth=1 / | sort -hr
This will display the top-level directories under /
sorted by size.
/var /usr /home /tmp /opt
Once you identify the largest directory, you can inspect it further, for example, if /var
is large:
sudo du -h --max-depth=1 /var | sort -hr
Step 2: Clean Package Cache in Linux
When you install or update software, Linux stores downloaded package files in a local cache. Over time, this cache can grow very large, especially if your system performs frequent updates or installations.
Cleaning this cache is a safe and effective way to free up space.
sudo apt clean # For Debian/Ubuntu sudo dnf clean all # For RHEL-based
These commands remove all cached package files from /var/cache/apt/archives/
(for APT) and /var/cache/dnf/
(for DNF), which can accumulate over time and consume a significant amount of space.
Step 3: Remove Old Kernels in Linux
When your system installs kernel updates, it usually keeps the older versions to allow recovery in case the new one fails. Over time, this can consume a lot of space, especially in /boot
, which has limited capacity.
To free up space on your Linux system, it’s a good idea to remove older, unused kernels. However, never remove the currently running kernel, as it is required for your system to boot and operate properly.
First, check the currently running kernel version.
uname -r
Then list all installed kernels:
dpkg --list | grep linux-image # For Debian/Ubuntu rpm -q kernel # For RHEL-based
Once you’ve identified which kernel versions are no longer needed, you can remove them. For example, to remove the version 5.15.0-88-generic on Ubuntu.
sudo apt remove --purge linux-image-5.15.0-88-generic
And on RHEL-based systems:
sudo dnf remove kernel-4.18.0-305.el8.x86_64
After removal, update the bootloader.
sudo update-grub
After removing old kernels, run this to clean up leftover packages and dependencies:
sudo apt autoremove # For Debian/Ubuntu sudo dnf autoremove # For RHEL-based
Step 4: Clear Log Files in Linux
Linux keeps a record of system activity and events in log files in /var/log
directory and these logs help system administrators troubleshoot problems, track user activity, and understand system performance.
But over time, they can grow very large, especially if:
- A service is crashing repeatedly
- The system is logging debug or error messages constantly
- You’re running out of disk space and the logs just keep piling up
If your root partition /
is full, there’s a good chance logs are taking up a lot of space. Cleaning or shrinking these log files can immediately free up some breathing room and get your system back to normal.
First, run the following command to see how much space each log file or folder is using:
sudo du -sh /var/log/*
Once you know which log files are the biggest culprits, you can truncate a log file, which means clearing its contents without deleting the actual file.
sudo truncate -s 0 /var/log/syslog sudo truncate -s 0 /var/log/kern.log sudo truncate -s 0 /var/log/auth.log
If your system uses journalctl (common in systemd systems), clean logs using:
sudo journalctl --vacuum-time=7d
This will keep only the last 7 days of logs.
Step 5: Clean Docker (if installed) in Linux
If you’re using Docker, it might be using a large amount of space due to images, containers, and volumes.
Check Docker space usage:
docker system df
To remove unused Docker data:
docker system prune -a
Be careful: this will delete all unused images, containers, and volumes.
Step 6: Live USB Rescue Method for Full Root Partition
If the system is completely full and unresponsive, you can use a Live USB to boot into a Live Linux environment and mount your root partition.
sudo fdisk -l sudo mount /dev/sda1 /mnt # Replace sda1 with your actual root partition
Browse the filesystem and delete large unwanted files.
cd /mnt sudo du -sh var/* sudo rm -rf var/log/*
Be cautious while removing files – avoid deleting critical system files.
Preventing This Issue in the Future
Here are some best practices to avoid filling up your root partition:
- Use Separate Partitions – Create separate partitions for
/var
,/home
, and/tmp
during installation. - Monitor Disk Usage – Set up simple monitoring tools like monit, cron jobs, or email alerts to notify you when disk usage is high.
- Schedule Regular Cleanup – Create cron jobs to clean logs and cache regularly.
- Avoid Storing Large Files in / – Store backup files, downloads, and media on mounted external drives or a separate data partition.
Summary
When your root partition fills up, it can cause serious issues, from package installation failures and service crashes to logging errors and even system boot failures. Fortunately, with the right set of commands and some careful cleanup, you can recover space and bring your system back to normal without needing a reinstall.
Have you ever run into a full root (/)
partition on your Linux system? What steps did you take to fix it? Share your experience in the comments below – your tips might help others in the community!