Marketing

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:
    bash
    rm -rf /var/cache/*

4. Temporary Files

Temporary files under /tmp or /var/tmp can also pile up:

bash
du -sh /tmp/*
du -sh /var/tmp/*
  • Safely remove old files:
    bash
    rm -rf /tmp/*
    rm -rf /var/tmp/*

5. Remove Unused Kernels

If old kernels are installed and not being used, they can occupy space under /boot. List installed kernels:

bash
rpm -q kernel

Remove old kernels (except the currently active one):

bash
package-cleanup --oldkernels --count=1

6. Audit Installed Packages

Check for unnecessary packages that might be installed:

bash
yum list installed | grep -i unused

Remove unneeded packages:

bash
yum remove <package-name>

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:

bash
mv /path/to/large/file /home/large-file
ln -s /home/large-file /path/to/large/file

8. Reclaim Space from Docker (if applicable)

If you’re using Docker, its files can bloat /var/lib/docker. Clean up unused Docker data:

bash
docker system prune -a

9. Find Orphaned Files in /var

Some directories under /var may have orphaned files:

bash
find /var -type f -size +100M

Delete or move large unnecessary files.


10. Verify Changes

After cleanup, check disk usage again:

bash
df -h

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!

Leave a Reply

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