Linux 磁盘空间显示为负?深度解析 df -h 负值背后的文件系统元数据损坏与修复实战 一、背景修机师傅运气不错有时候还能收到些“奇奇怪怪”的问题话说df -h返回值为负是啥情况上个图检查挂载点下也没有特别异常的文件而且业务还运行正常。检查内核日志发下xfs有报错重启故障虚拟机也还是有这个现象 。在关机状态下克隆了一台做测试以下操作基于克隆的虚拟机。二、修复与分析1、进入救援模式查看挂载点显示为负值2、执行xfs_repair /dev/mapper/centos-root然后再次挂载正常从xfs_repair修复的结果看有识别到一些异常并且成功修复了而修复之后再次挂载空间使用也正常。结合日志和操作分析是xfs文件系统异常导致后面在redhat kb库也找到了类似案例同步分享下。3、进一步分析根因Root CauseIn this case, the command the strace of the df command provided a value of f_bfree, 37345930, which is larger than the value of f_blocks, 34216732. Based on statfs(2) man page, we see the second parameter is a struct which the kernel populates, with the following member definitions:Rawstruct statfs { long f_type; /* type of file system (see below) */ long f_bsize; /* optimal transfer block size */ long f_blocks; /* total data blocks in file system */ long f_bfree; /* free blocks in fs */ long f_bavail; /* free blocks avail to non-superuser */ long f_files; /* total file nodes in file system */ long f_ffree; /* free file nodes in fs */ fsid_t f_fsid; /* file system id */ long f_namelen; /* maximum length of filenames */ };statfs is part of the linux VFS, so each file system will have its own implementation. In this case, the file system was ext3, which populates the two struct fields of interest in fs/ext3/super.c via:Rawfbuf-f_blocks le32_to_cpu(es-s_blocks_count) - overhead; buf-f_bfree percpu_counter_sum(sbi-s_freeblocks_counter);Since both values are maintained by the file system, some form of filesystem corruption seemed likely.Diagnostic StepsRun strace to determine if the kernel is handing back bad data or df mishandling itIn particular, look at the values of f_bfree and f_blocksIf b_free excedes b_blocks, the kernel is providing bad dataRaw# strace -e tracestatfs,statfs64 df /dev/cciss/c0d0p1 /dev/null statfs(/, {f_typeEXT2_SUPER_MAGIC, f_bsize4096, f_blocks34216732, f_bfreebr /37345930, f_bavail35579785, f_files35323904, f_ffree35180816, f_fsid{0, 0}, f_namelen255, f_frsize4096}) 0参考上述kb当文件系统的f_free大于f_blocks时会出现负值我这边的环境这个值出现异常也就是前面xfs报错相关。三、总结df -h返回负值是因为文件系统元数据f_free大于f_blocks导致解决方案主要也是通过文件系统修复来处理1、卸载并检查文件系统对于ext3/ext4文件系统使用e2fsck -fvy /dev/centos/root来修复对xfs文件系统使用xfs_repair命令2、如果无法卸载文件则进救援模式并参考上面步骤处理。3、如果文件系统仍显示负值则考虑是否空间不足尝试进行文件系统扩容。

相关新闻

最新新闻

ShawzinBot 把 MIDI 变成 Shawzin 按键:从第一次运行到多人合奏的实操指南

ShawzinBot 把 MIDI 变成 Shawzin 按键:从第一次运行到多人合奏的实操指南

ShawzinBot 把 MIDI 变成 Shawzin 按键:从第一次运行到多人合奏的实操指南 【免费下载链接】ShawzinBot Convert a MIDI input to a series of key presses for the Shawzin 项目地址: https://gitcode.com/gh_mirrors/sh/ShawzinBot ShawzinBot 是一款 MIDI…

2026/8/22 13:09:42
System_Architect案例高频考点:Redis分布式锁、缓存雪崩穿透、数据库读写分离完整答题指南

System_Architect案例高频考点:Redis分布式锁、缓存雪崩穿透、数据库读写分离完整答题指南

System_Architect案例高频考点:Redis分布式锁、缓存雪崩穿透、数据库读写分离完整答题指南 【免费下载链接】System_Architect 🐍 2024年软考 (杭州e类租房补贴)系统架构设计师资料整理复习(软考高级) 二战 20天备考通过🎉🎉&…

2026/8/22 13:09:42
Astro Ink部署指南:Vercel上SSR还是纯静态?4步转换法彻底讲明白

Astro Ink部署指南:Vercel上SSR还是纯静态?4步转换法彻底讲明白

Astro Ink部署指南:Vercel上SSR还是纯静态?4步转换法彻底讲明白 【免费下载链接】astro-ink Crisp, minimal, personal blog theme for Astro 项目地址: https://gitcode.com/gh_mirrors/as/astro-ink Astro Ink 是一款专为个人博客打造的极简 As…

2026/8/22 13:09:42
【随笔】用于收藏值得学习的社区链接分享和mark

【随笔】用于收藏值得学习的社区链接分享和mark

一、收藏列表 1.1 LINUXDO-新的理想型社区 LINUX DO - 新的理想型社区 【开源】一套嵌入式软件调试 Skill 工具集,打通嵌入式开发AI工作流最后一步 - 开发调优 - LINUX DO 1.2 嵌入式相关开源项目、库、资料,超级汇总站(超级超级推荐&…

2026/8/22 13:09:42
Ionic+Angular实战:covidAPI构建移动端疫情数据看板的完整拆解

Ionic+Angular实战:covidAPI构建移动端疫情数据看板的完整拆解

IonicAngular实战:covidAPI构建移动端疫情数据看板的完整拆解 【免费下载链接】covidAPI Coronavirus API for Current cases by country COVID-19 项目地址: https://gitcode.com/gh_mirrors/co/covidAPI covidAPI 是一个用 Node.js 搭建疫情数据 API、用 I…

2026/8/22 13:09:42
LCD Image Converter 上手指南:一条命令把 PNG 变成能烧进 MCU 的 C 数组

LCD Image Converter 上手指南:一条命令把 PNG 变成能烧进 MCU 的 C 数组

LCD Image Converter 上手指南:一条命令把 PNG 变成能烧进 MCU 的 C 数组 【免费下载链接】lcd-image-converter Tool to create bitmaps and fonts for embedded applications, v.2 项目地址: https://gitcode.com/gh_mirrors/lc/lcd-image-converter LCD I…

2026/8/22 13:04:42