How can I see what is consuming space underneath a mounted partition?

环境

  • Red Hat Enterprise Linux (RHEL) all versions

问题

  • My partitions are arranged like this (example):
/ (/dev/sda1)
--/var (/dev/sda2)
--/usr (/dev/sda3)
--/backups (/dev/sda4)
  • My root partition itself (/dev/sda1) is small, and is almost full.
  • There is nothing on any directory that might account for the occuppied space.
  • How can I see where is the consumed space, and free it by deleting files?

决议

The following can be used only to view that is consuming space underneath the mounted partitions. You will not be able to mount the root filesystem read-only on another location, if it is already mounted read-write on /. As such, please exercise extreme care when doing the following procedure, and ensure filesystem activity is kept at a minimum. Failure to do so can incur in filesystem corruption.

  1. Create an alternative directory where the root filesystem will be mounted:

    # mkdir /image
    
  2. Mount the root filesystem on said directory:

    # mount /dev/sda1 /image
    
  3. Execute du command inside that mounted filesystem:

    # cd /image
    # du -sh *
    
  4. To ensure data corruption does not occur, immediately unmount the root filesystem at /image:

    # cd /
    # umount /image
    

Note that, based on the example above, there should not be any files inside /image/usr, /image/var and /image/backups. However, if there are (because files were written there while the partition was not mounted), the output from the du command will show the file sizes of all the top-level directories of the root filesystem, ignoring the mounted partitions (since they are mounted on the respective / childs, not on /image). Based on that output, you will be able to see if any files reside on top-level directories underneath the partitions mounted on them. Once you have this information, you can either:

  • Unmount the partition that resides on the offending directory (the one consuming space where it should not), and remove the files manually.
  • If it is not possible to unmount the partition, you will have to reboot your system into rescue mode (select "Skip" on step 5 of the mentioned guide), mount the root filesystem manually, and delete the files outlined as per the mentioned procedure.

根源

Due to how the Linux filesystem structure works, if you have a partition mounted on a directory (e.g. /backups), and a file getss written to that directory while the partition was not mounted, the space consumed by said file will account towards space used in its parent directory (in this case, /), instead of the partition that will be mounted there (/backups).

posted @   augusite  阅读(137)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· 字符编码:从基础到乱码解决
· Open-Sora 2.0 重磅开源!
历史上的今天:
2019-05-20 公司内网,配置代理以后无法使用yum源
点击右上角即可分享
微信分享提示