If you're attempting to run xfs_repair, getting the error message that suggests mounting the filesystem to replay the log, and after mounting still receiving the same error message, you may need to perform a forced repair (using the -L flag with xfs_repair). This option should be a last resort.

For example, I'll use a case where I had a corrupt root partition on my CentOS 7 install. When attempting to mount the partition, I continually received the below error message:

mount: mount /dev/mapper/centos-root on /mnt/centos-root failed: Structure needs cleaning

Unfortunately, forcing a repair would involve zeroing out (destroying) the log before attempting a repair. When using this method, there is a potential of ending up with more corrupt data than initially anticipated; however, we can use the appropriate xfs tools to see what kind of damage may be caused before making any permanent changes.

Using xfs_metadump and xfs_mdrestore, you can create a metadata image of the affected partition and perform the forced repair on the image rather than the partition itself. The benefits of this is the ability to see the damage that comes with a forced repair before performing it on the partition.

To do this, you'll need a decent sized USB or external hard drive. Start by mounting the USB drive - my USB was located at /dev/sdb1, yours may be named differently.

mkdir -p /mnt/usb
mount /dev/sdb1 /mnt/usb

Once mounted, run xfs_metadump to create a copy of the partition metadata to the USB - again, your affected partition may be different. In this case, I had a corrupt root partition located at /dev/mapper/centos-root:

xfs_metadump /dev/mapper/centos-root /mnt/usb/centos-root.metadump

Next, you'll want to restore the metadata in to an image so that we can perform a repair and measure the damage.

xfs_mdrestore /mnt/usb/centos-root.metadump /mnt/usb/centos-root.img

I found that in rescue mode xfs_mdrestore is not available, and instead you'll need to be in rescue mode of a live CentOS CD.

Finally, we can perform the repair on the image:

xfs_repair -L /mnt/usb/centos-root.img

After the repair has completed and you've assessed the output and potential damage, you can determine as to whether you'd like to perform the repair against the partition.

To run the repair against the partition, simply run:

xfs_repair -L /dev/mapper/centos-root

Don't forget to check the other partitions for corruption as well. After the repairs, reboot the system and you should be able to successfully boot.

Remember that the -L flag should be used as a last resort where there are no other possible options to repair.

https://serverfault.com/questions/777299/proper-way-to-deal-with-corrupt-xfs-filesystems

https://serverfault.com/questions/851204/risk-of-not-repairing-structure-needs-cleaning-xfs-errors

https://unix.stackexchange.com/questions/330742/cannot-remove-file-structure-needs-cleaning

http://xfs.9218.n7.nabble.com/mount-Structure-needs-cleaning-td2796.html

fsck -vcfy /dev/sda3 会清空数据。

我的移动硬盘也遇到这个问题,同样是XFS文件系统。

在未挂载状态下试一试这个命令:
# xfs_repair /dev/sdb1 /*后面跟目标驱动器路径*/
如果提示log什么的有问题,则使用-L参数,这会重建log,然后再使用上面一条命令进行修复。
#xfs_repair -L /dev/sdb1

1 执行debugfs -w /dev/sdb    (/dev/sdb出现 该情况文件所在的分区) -w says that partition will be opened in read-write mode.

2 mount /dev/sdb /mnt/other  挂载到mnt/other 目录下

3 执行 clri path/file    移除损坏文件节点 注意path/file 值的是相对路径 而不是/mnt/other/****

4 退出 debugfs 执行fsck -y /mnt/other   修复该分区

ext4文件系统,使用命令  fsck.ext4 /dev/md0 修复,

如果是xfs文件系统,使用命令 xfs_repair -L /dev/md0修复,

 

# mount /dev/sdb1 /disk2
mount: Structure needs cleaning

我用了下列的指令解決了. 雖然我不太清楚什麼東西導致它有問題 :
# xfs_repair -n /dev/sdb1

上面指令還不能完全解決

# xfs_check /dev/sdb1
ERROR: The filesystem has valuable metadata changes in a log which needs to
be replayed. Mount the filesystem to replay the log, and unmount it before
re-running xfs_check. If you are unable to mount the filesystem, then use
the xfs_repair -L option to destroy the log and attempt a repair.
Note that destroying the log may cause corruption — please attempt a mount
of the filesystem before doing this.

用 xfs_check 指令. 它建議我用 “xfs_repair -L ”
# xfs_repair -L /dev/sdb1

這樣弄玩之後. 在用 xfs_check 檢查一次
# xfs_check /dev/sdb1

就可以掛載了
# mount /dev/sdb1 /disk2

[root@pc4 ~]# mount /data2

mount: Structure needs cleaning

[root@pc4 ~]# xfs_repair -L /dev/vgcb0 
Phase 1 - find and verify superblock...
Phase 2 - using internal log
        - zero log...
ALERT: The filesystem has valuable metadata changes in a log which is being
destroyed because the -L option was used.
        - scan filesystem freespace and inode maps...
agi unlinked bucket 16 is 252816 in ag 0 (inode=252816)
sb_icount 2977088, counted 2639872
sb_ifree 1752667, counted 1398980
sb_fdblocks 243437595, counted 241668641
        - found root inode chunk
Phase 3 - for each AG...
        - scan and clear agi unlinked lists...
        - process known inodes and perform inode discovery...
        - agno = 0
7ff4a425e700: Badness in key lookup (length)
bp=(bno 126400, len 16384 bytes) key=(bno 126400, len 8192 bytes)
        - agno = 1
        - agno = 2
        - agno = 3
        - process newly discovered inodes...
Phase 4 - check for duplicate blocks...
        - setting up duplicate extent list...
        - check for inodes claiming duplicate blocks...
        - agno = 2
        - agno = 3
        - agno = 0
        - agno = 1
Phase 5 - rebuild AG headers and trees...
        - reset superblock...
Phase 6 - check inode connectivity...
        - resetting contents of realtime bitmap and summary inodes
        - traversing filesystem ...
        - traversal finished ...
        - moving disconnected inodes to lost+found ...
disconnected inode 252816, moving to lost+found
Phase 7 - verify and correct link counts...
done
[root@pc4 ~]# 
[root@pc4 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda5             194G  5.2G  179G   3% /
tmpfs                  63G   72K   63G   1% /dev/shm
/dev/sda2             194M   32M  152M  18% /boot
/dev/sda4              20G  196M   19G   2% /tmp
/dev/vgca0            2.1T  1.2T  938G  55% /data1
[root@pc4 ~]# mount /data2

structure needs cleaning的更多相关文章

  1. linux 结构需要清理 (structure needs cleaning)

    下面操作会删除挂载点所有文件,注意备份. df -T 查看出错的挂载点对应的文件系统和文件系统类型   然后umount这个文件系统 umount /dev/sda1 然后文件系统类型不同操作不同  ...

  2. Linux ERRNO

    摘自Linux-3.18.20的头文件include/uapi/asm-generic/errno-base.h和include/uapi/asm-generic/errno.h: #define E ...

  3. 《UNIX环境高级编程》笔记——1.UNIX基础知识

    这一章节侧重一些基本概念和书中用到的一些名词. 一.引言 所有的操作都提供服务,典型的服务包括:执行新程序.打开文件.读写文件.分配存储区以及获得当前时间等. 二.UNIX体系结构 其实linux常见 ...

  4. Linux命令的返回码列表

    转自:http://blog.chinaunix.net/uid-10347480-id-3263127.html 在 Linux 下,不管你是启动一个桌面程序也好,还是在控制台下运行命令,所有的程序 ...

  5. linux编程中接收主函数返回值以及错误码提示

    程序A创建子进程,并调用进程B,根据不调用的不同情况,最后显示结果不同. #include <stdio.h> #include <unistd.h> #include < ...

  6. linux下错误的捕获:errno和strerror的使用

    经常在调用linux 系统api 的时候会出现一些错误,比方说使用open() write() creat()之类的函数有些时候会返回-1,也就是调用失败,这个时候往往需要知道失败的原因.这个时候使用 ...

  7. [转]Linux命令的返回值

    Linux命令的返回值 对于某些监测脚本和探测命令蛮有用的: 在 Linux 下,不管你是启动一个桌面程序也好,还是在控制台下运行命令,所有的程序在结束时,都会返回一个数字值,这个值叫做返回值,或者称 ...

  8. linux系统编程之错误处理

    在linux系统编程中,当系统调用出现错误时,有一个整型变量会被设置,这个整型变量就是errno,这个变量的定义在/usr/include/errno.h文件中 #ifndef _ERRNO_H /* ...

  9. linux命令执行返回值(附错误对照表)

    转自:http://blog.sina.com.cn/s/blog_6739945f0100zt4b.html 在 Linux 下,不管你是启动一个桌面程序也好,还是在控制台下运行命令,所有的程序在结 ...

随机推荐

  1. TCP和UDP发送数据包的大小问题

    用UDP协议发送时,用sendto函数最大能发送数据的长度为:65535-20-8=65507字节,其中20字节为IP包头长度,8字节为UDP包头长度.用sendto函数发送数据时,如果指的的数据长度 ...

  2. [实战]MVC5+EF6+MySql企业网盘实战(15)——逻辑重构2

    写在前面 上篇文章修改文件上传的逻辑,这篇修改下文件下载的逻辑. 系列文章 [EF]vs15+ef6+mysql code first方式 [实战]MVC5+EF6+MySql企业网盘实战(1) [实 ...

  3. linux java环境变量设置

    下载JRE或者JDK后解压,设置以下环境变量 JAVA_HOME=/home/zm/jdk1.8.0_181JRE_HOME=/home/zm/jdk1.8.0_181/jreCLASSPATH=.: ...

  4. 《java虚拟机》----java内存模型与线程

    No1. No2. java内存模型规定了所有的变量都存储在主内存中(Main Memory)中 每条线程还有自己的工作内存(Working Memory) 线程的工作内存中保存了被该线程使用到的变量 ...

  5. [BZOJ2594][WC2006]水管局长加强版(LCT+Kruskal)

    2594: [Wc2006]水管局长数据加强版 Time Limit: 25 Sec  Memory Limit: 128 MBSubmit: 4452  Solved: 1385[Submit][S ...

  6. [BZOJ4888][TJOI2017]异或和(树状数组)

    题目描述 在加里敦中学的小明最近爱上了数学竞赛,很多数学竞赛的题都是与序列的连续和相关的.所以对于一个序列,求出它们所有的连续和来说,小明觉得十分的简单.但今天小明遇到了一个序列和的难题,这个题目不仅 ...

  7. Linux sort 排序 去重 统计

    先写一个命令: cut -d' ' -f1 ~/.bash_history|sort -d | uniq -c|sort -nr|head 这个命令可以统计你历史上输入的命令的次数的前十条 整个命令基 ...

  8. 较有意思的Apple XSS(CVE-2016-7762)漏洞

    文章作者:Avfisher0x00 前言应CVE作者的要求帮忙分析一下这个漏洞,实际上这是一个思路比较有意思的Apple XSS(CVE-2016-7762).漏洞作者确实脑洞比较大也善于尝试和发掘, ...

  9. 2017-2018-1 JAVA实验站 冲刺 day03

    2017-2018-1 JAVA实验站 冲刺 day03 各个成员今日完成的任务 小组成员 今日工作 完成进度 张韵琪 写博客.进行工作总结 100% 齐力锋 部分按钮图片.对按钮图片进行ps 100 ...

  10. [BZOJ5028]小Z的加油店

    [BZOJ5028]小Z的加油店 题目大意: 一个长度为\(n(n\le10^5)\)的数列,\(m(m\le10^5)\)次操作,支持区间加和区间\(\gcd\). 思路: 线段树维护差分,\(\g ...