How to clear & clean server root partition safely when you run out of disk space on /dev/mapper/centos-root 100% full
When your /dev/mapper/centos-root
partition is critically full, nearing at 98% or more, freeing up space is absolutely necessary in order to avoid bigger server issues. Here’s how you can identify and clean up unnecessary files safely:
1. Analyze Disk Usage
First, check which directories are taking up the most space under /
:
du -ahx / | sort -rh | head -n 20
This command lists the top 20 largest files and directories in /
.
2. Check for Logs
Log files can grow large, especially under /var/log
. List the largest log files:
du -sh /var/log/*
- Delete old or rotated logs that are no longer needed:
rm -f /var/log/*.old rm -f /var/log/*.gz
- Alternatively, truncate large log files:
> /var/log/large-log-file.log
3. Clear Cache
System caches under /var/cache
can consume significant space:
du -sh /var/cache/*
- Clean up package manager cache:
yum clean all
- Remove other caches if necessary:
4. Temporary Files
Temporary files under /tmp
or /var/tmp
can also pile up:
- Safely remove old files:
5. Remove Unused Kernels
If old kernels are installed and not being used, they can occupy space under /boot
. List installed kernels:
Remove old kernels (except the currently active one):
6. Audit Installed Packages
Check for unnecessary packages that might be installed:
Remove unneeded packages:
7. Move Files to /home
Since your /home
partition has ample space, consider moving non-critical data from /
to /home
.
For example, move backups or large files:
8. Reclaim Space from Docker (if applicable)
If you’re using Docker, its files can bloat /var/lib/docker
. Clean up unused Docker data:
9. Find Orphaned Files in /var
Some directories under /var
may have orphaned files:
Delete or move large unnecessary files.
10. Verify Changes
After cleanup, check disk usage again:
Warnings:
- Double-check before deletion: Always verify files before removing them to avoid deleting critical system files.
- Backup important data: If unsure about a file, move it elsewhere (
/home
or an external drive) instead of deleting.
If you’re unsure about a specific large file or directory, share its details, and I can guide you further!