How to Free Up Disk Space on a Full Root Filesystem in Linux
Running out of disk space on your Linux server can lead to serious performance issues, application failures, or even system crashes. If your root filesystem (/
) is at 100% capacity, here’s how you can free up space effectively.
1. Check Large Files and Directories
The first step is identifying what is consuming space:
du -ahx / | sort -rh | head -20
This command lists the top 20 largest files and directories within the root filesystem.
2. Clean APT Cache
If you have installed software via APT (Debian/Ubuntu-based systems), cleaning cached packages can help recover space:
apt-get clean
This removes cached .deb
packages from /var/cache/apt/archives
.
3. Remove Old Logs
System logs can accumulate over time. You can clear unnecessary logs with:
journalctl --vacuum-time=5d # Keep only the last 5 days of logs
rm -rf /var/log/*.gz # Delete compressed log files
4. Clear Temporary Files
The /tmp
directory stores temporary files that may no longer be needed:
du -sh /tmp # Check the size of /tmp
rm -rf /tmp/* # Delete all temporary files
5. Remove Unused Kernels
Old kernels take up disk space and should be removed if not in use:
dpkg --list | grep linux-image # List installed kernels
apt-get autoremove --purge # Remove unused kernels
6. Verify VM and ISO Storage (Proxmox Users)
For Proxmox or virtualization setups, ISOs and VM snapshots may consume space in /var/lib/vz
:
du -sh /var/lib/vz/* # Identify large files
Delete any unused ISOs or old VM backups to free up space.
7. Expand the Root Filesystem (If Possible)
If your system has additional unallocated space, you can expand the root volume:
lvextend -l +100%FREE /dev/mapper/pve-root
resize2fs /dev/mapper/pve-root
This only applies if Logical Volume Management (LVM) is used and there is free space available.
Final Checks
After performing these steps, verify the available disk space:
df -h /
This should confirm that your root partition has more free space.
By following these steps, you can prevent critical failures caused by a full root filesystem and keep your Linux system running smoothly.