Recovering a Linux System After a Full Root Partition

ANGADSINGH OBBIANGADSINGH OBBI
4 min read

Running out of space on your Linux system’s root partition can lead to serious problems, including sudden shutdowns or boot failures. If your system is powered off due to a full root partition, there’s no need to panic—there are clear steps to recover your system and prevent this issue from happening again.

In this blog, I’ll walk you through how to recover from a full root partition, clean up unnecessary files, and ensure your system stays healthy moving forward.

Why Does a Full Root Partition Cause Issues?

The root partition is critical for the operating system to function. When it fills up, the system has no room to write important files such as logs, temporary data, or even updates. This can cause applications to fail, services to stop running, and sometimes make the system unbootable.

How to Recover Your System?

Step 1: Boot into Recovery Mode or Single User Mode

To begin the recovery process, you’ll need to access the terminal. Since a full root partition may prevent your system from booting normally, you'll likely have to use Recovery Mode or Single User Mode to gain access.

Here’s how:

  1. Reboot your system.

  2. When the system starts, press Esc or Shift to open the GRUB menu.

  3. Select Advanced options from the GRUB menu.

  4. Choose the kernel option labeled Recovery mode.

  5. In the recovery menu, choose the root option to open a root shell.

Alternatively, if this doesn't work, you can add single or init=/bin/bash to the kernel boot parameters to start in Single User Mode.

Step 2: Identify Large Files

Once you have terminal access, the next step is to figure out which files or directories are taking up the most space on your root partition.

Use these commands to find large files and check disk usage:

  • Find files larger than 100MB:

      find / -xdev -type f -size +100M
    
  • Check disk usage of root directories:

      du -h --max-depth=1 /
    

This will give you a clear picture of where your disk space is being consumed.

Step 3: Free Up Disk Space

Now that you’ve identified the large files, it’s time to clean them up. Below are some common culprits that can take up a lot of space.

1. Clear Log Files

System logs in /var/log/ can grow very large, especially if there’s an issue that’s being logged repeatedly. You can safely delete these files:

rm -f /var/log/*.log

After clearing the logs, your system will start fresh and create new log files.

2. Clean Up Package Cache

Linux distributions cache package files during installations and updates, which can take up significant space. You can safely clean the package cache:

  • For Debian/Ubuntu-based systems:

      apt-get clean
    
  • For Fedora/Red Hat-based systems:

      dnf clean all
    
3. Remove Temporary Files

Temporary files can accumulate in /tmp/ and /var/tmp/, especially after long periods of uptime. You can remove these files with:

rm -rf /tmp/*
rm -rf /var/tmp/*
4. Uninstall Old Kernels

If your system retains old kernels after updates, they can take up valuable space. To list all installed kernels, run:

dpkg --list | grep linux-image

To remove an old kernel, use:

apt-get remove --purge linux-image-<version>
5. Remove Orphaned Packages

Unused dependencies from uninstalled software can also take up space. Clean these up with:

apt-get autoremove

Step 4: Reboot the System

Once you’ve freed up some space, reboot your system:

reboot

After rebooting, your system should be back to normal. If it doesn't boot successfully, repeat the steps above and try freeing up more space.

How to Prevent Future Disk Space Issues

After recovering your system, it’s important to put measures in place to avoid this issue in the future.

1. Monitor Disk Usage Regularly

Check your disk space periodically using the df command:

df -h

This will help you keep an eye on your partitions and prevent them from filling up.

2. Enable Log Rotation

Logs can grow quickly, so it’s crucial to set up automatic log rotation using logrotate. This will compress and rotate logs, ensuring they don’t take up too much space:

sudo nano /etc/logrotate.conf

Make sure your log rotation settings are configured correctly for all log files.

3. Automate Cleanup

Setting up a cron job to clear temporary and cache files regularly can help prevent your root partition from filling up. For example, you could schedule a cleanup script to run weekly.

Conclusion

Recovering a Linux system after the root partition fills up can seem daunting, but with the right steps, it’s a manageable process. By booting into recovery mode, identifying large files, and freeing up disk space, you can get your system back up and running. Don’t forget to monitor your disk usage regularly and implement preventative measures like log rotation and cache cleaning to keep your system healthy.

If you have any questions or have faced similar issues, feel free to share your experience in the comments below!

1
Subscribe to my newsletter

Read articles from ANGADSINGH OBBI directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

ANGADSINGH OBBI
ANGADSINGH OBBI