How to Free Up Space in Linux Ubuntu When Root (/) Partition Is Full &, if necessary, extend your root partition (/)

How to Free Up Space in Linux Ubuntu When Root (/) Partition Is Full &, if necessary, extend your root partition (/)

Freeing up space in the existing sized root partition.

Sudo du -h –max-depth=1/ |
The first step is to confirm the issue using the df command, which will displays the space used and available on the root partition. Isudf the usage is 100%, it’s time to take action.

df -h /

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 Deunbian/Ubuntu

These commands remove all cdached 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

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

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/syslogd

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 monitcron 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.

If you’ve tried cleaning up your Linux root partition but it keeps filling up, it might be time to increase the size of your root (/) partition. Extending the root partition gives your system more space for applications, logs, and data.

How to Extend Root Partition in Linux

Understanding the Root Partition

The root partition (/) is where your Linux operating system resides and contains all the system files, installed applications, configuration settings, and sometimes user data if /home isn’t on a separate partition.

The root partition can fill up for several reasons:

  • Installing lots of applications.
  • Big log files are taking up space.
  • Temporary files that aren’t cleaned automatically.
  • Databases or development tools storing data on /.

When the root partition runs low on space, Linux can start acting unpredictably. Expanding it helps prevent these problems and keeps your system running smoothly.

How to Check Current Disk Usage

The first step is to see your current partition layout and how much space you have using the following df command.

df -h

The above command shows disk usage in a human-readable format, here you can see that / is almost full (90% used).:

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda1        20G   18G  2G  90% /

tmpfs           2.0G  1.2M 2.0G 1% /dev/shm

Next, check your partition layout with the following fdisk command:

fdisk -l

The above command will list all the disk partitions on the system.

NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sda      8:0    0  50G  0 disk

├─sda1   8:1    0  20G  0 part /

├─sda2   8:2    0  10G  0 part /home

└─sda3   8:3    0  20G  0 part

Notice how / is only 20GB while /home is 10GB. We may want to take advantage of unused space on the disk or shrink other partitions.

Important: Backup Your Root Partition

Before making any changes to your partitions, always back up your important data, because mistakes do happen during partitioning, which can lead to data loss, so it’s better to be safe than sorry.

To take your root partition backup, we will use the rsync command as shown, or you can use any other backup tool you prefer..

rsync -av –progress / /path/to/backup/

There are several ways to increase the root partition’s space, and the approach you choose depends on your setup.

Method 1: Extending Root Partition Using GParted

If you’re on a desktop or have a Live CD/USB, GParted is the easiest tool to use.

  • Boot from a Live USB/CD – You cannot resize a mounted root partition, so start by booting into a live Linux environment.
  • Launch GParted – Open GParted from the menu and see a list of all your partitions.
  • Resize the Root Partition – Identify the / (root) partition, check if there’s unallocated space next to it, right-click the partition and select Resize/Move.
  • Apply Changes – Click the checkmark button to apply the changes, be patient; this may take a few minutes.

After rebooting, run df -h to confirm that the root partition has increased in size.

Method 2: Using LVM (Logical Volume Manager)

If your root partition is on LVM (many modern Linux distributions like CentOS, RHEL, and  Ubuntu support LVM), expanding is safer and doesn’t require booting from a Live CD.

First, check if the root is on LVM.

lsblk

You might see something similar, here, / is an LVM logical volume (lv_root) inside volume group vg_root.

NAME                 MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sda                    8:0    0  50G  0 disk

└─sda2                 8:2    0  50G  0 part

  ├─vg_root-lv_root   253:0  0  20G  0 lvm  /

  └─vg_root-lv_home   253:1  0  30G  0 lvm  /home

If there is free space in the volume group, you can extend the logical volume.

sudo lvextend -L +10G /dev/vg_root/lv_root

  • +10G means add 10GB to the root.
  • Replace /dev/vg_root/lv_root with your path.

Next, resize the filesystem.

sudo resize2fs /dev/vg_root/lv_root  #for ext3

sudo xfs_growfs /                    #for xfs

After resizing, run the following command to confirm that the root partition has increased in size.

df -h

Method 3: Shrinking Another Partition

If LVM is not used and there’s no unallocated space, you can shrink another partition like /home to create space:

  • Backup /home – Make sure all your important files are saved somewhere safe.
  • Boot from a Live USB – Start your computer from a Linux USB so the partitions aren’t in use.
  • Shrink /home using GParted – Use GParted to reduce the size of the /home partition and free up space.
  • Move the root partition – Carefully shift your root partition into the free space. This step is advanced and risky.
  • Resize the filesystem – Expand the root filesystem so it can use the new space.

Tip: This is tricky for beginners. If possible, use LVM or work with partitions that already have unallocated space.

Conclusion

For beginners, using GParted via a Live USB is the safest way to extend the root partition, while LVM users have the flexibility to do it safely without rebooting.

Always remember to back up your important data before making any changes, and double-check your partitions before resizing.

By Admin

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.