Running into a full /usr partition is particularly problematic because this directory contains:
- Essential system binaries (/usr/bin)
- Shared libraries (/usr/lib)
- Header files (/usr/include)
- Documentation (/usr/share/doc)
- Application data (/usr/share)
First, let's identify space hogs without installing additional packages:
# Check largest directories
sudo du -sh /usr/* | sort -h
# Alternative with depth control
sudo du -h --max-depth=1 /usr | sort -h
# Find largest files (may take time)
sudo find /usr -type f -exec du -h {} + | sort -h | tail -n 20
These locations typically contain removable data:
1. Old Kernel Versions
# List installed kernels (current one marked with 'ii')
dpkg --list | grep linux-image
# Remove specific old kernel
sudo rm -rf /usr/lib/modules/[old-kernel-version]
2. Documentation and Manual Pages
# Clear documentation cache
sudo rm -rf /usr/share/doc/*
# Remove non-essential manuals
sudo rm -rf /usr/share/man/[locale]
3. Application Cache and Temporary Files
# Clear system-wide cache
sudo rm -rf /usr/share/[app-name]/cache/*
# Example: Clearing font cache
sudo rm -rf /usr/share/fonts/truetype/*.cache
When apt is broken, we can manually clean package files:
# Remove downloaded .deb files
sudo rm -rf /usr/cache/apt/archives/*.deb
# Clean partial package installations
sudo rm -rf /usr/var/cache/apt/archives/partial/*
After recovery, consider these permanent solutions:
- Move /usr/share to separate partition
- Implement log rotation for /usr logs
- Set up monitoring with cron job:
# Simple disk monitoring script
#!/bin/bash
THRESHOLD=90
CURRENT=$(df /usr --output=pcent | tail -1 | tr -d '%')
if [ "$CURRENT" -ge "$THRESHOLD" ]; then
echo "Warning: /usr partition at ${CURRENT}% capacity" | mail -s "Disk Alert" admin@example.com
fi
As last resort before repartitioning:
# Temporarily move large directories to / (if space available)
sudo mv /usr/share/[large-dir] /[new-location]
sudo ln -s /[new-location]/[large-dir] /usr/share/[large-dir]
When your /usr partition hits 100% capacity on Ubuntu, you enter a vicious cycle: can't install new packages (including diagnostic tools) because there's no space, and can't identify space hogs because you can't install analysis tools. Here's how to break this cycle.
Without package managers or external tools, we'll use built-in commands:
# Find largest directories (depth=2 for quick scan)
sudo du -h --max-depth=2 /usr | sort -hr | head -20
# Alternative with ncdu if installed
ncdu /usr --exclude /usr/src
- Old kernel headers:
/usr/src/linux-headers-*
(keep current and one previous) - Cached package files:
/usr/share/doc/*/changelog.Debian.gz
- Locale archives:
/usr/share/locale/
(keep only needed languages) - Manual pages:
/usr/share/man/
(non-essential documentation)
Here are specific commands to reclaim space:
# Remove old kernel headers (adapt version numbers)
sudo rm -rf /usr/src/linux-headers-5.4.0-42
sudo rm -rf /usr/src/linux-headers-5.4.0-42-generic
# Clean locale data (keep en_US)
sudo find /usr/share/locale -mindepth 1 -maxdepth 1 ! -name 'en_US*' -exec rm -rf {} +
# Remove bulky documentation
sudo rm -rf /usr/share/doc/*
After recovery, implement these measures:
# Add to /etc/apt/apt.conf.d/99cleanup
APT::Clean-Installed "false";
APT::Get::Purge "true";
Consider these long-term solutions:
- Resize partitions using GParted Live USB
- Create symlinks to move less critical /usr subdirectories
- Bind mount /usr/share to another partition