How to repair a broken/unmountable btrfs filesystem

最近磁盘上的Btrfs分区在调整大小的时候,报错:

$ sudo btrfs check --force --repair /dev/sdb7
enabling repair mode
Opening filesystem to check...
WARNING: filesystem mounted, continuing because of --force
Checking filesystem on /dev/sdb7
UUID: 57e881c6-4aac-4f0c-aed9-74341f525e79
repair mode will force to clear out log tree, are you sure? [y/N]: y
parent transid verify failed on 83801812992 wanted 276510 found 277808
parent transid verify failed on 83801812992 wanted 276510 found 277808
parent transid verify failed on 83801812992 wanted 276510 found 277808
Ignoring transid failure
[1/7] checking root items
parent transid verify failed on 83801812992 wanted 276510 found 277808
Ignoring transid failure
parent transid verify failed on 83800657920 wanted 276512 found 277808
parent transid verify failed on 83800657920 wanted 276512 found 277808
parent transid verify failed on 83800657920 wanted 276512 found 277808
Ignoring transid failure
ERROR: child eb corrupted: parent bytenr=194117632 item=11 parent level=1 child level=1
ERROR: failed to repair root items: Input/output error

How to repair a broken/unmountable btrfs filesystem

The below are the recommended steps for any major btrfs filesystem issue, especially if its unmountable. Reading dmesg or syslog might help you identify which step you could skip to in order to fix a particular problem, but the initial steps are normally useful regardless as btrfs scrub is a very safe repair tool.

  • Boot to a suitable alternative system, such as a rescue shell, different installation of openSUSE, a liveCD, or an openSUSE installation DVD. The installation DVD for the version of openSUSE you are running is usually a good choice as it will certainly use the same kernel/btrfs version. A recent Tumbleweed disk might be better as it will include newer kernel/btrfs
  • Go to a suitable console and make sure you do the below as root
  • Try to mount your partition to /mnt, just to confirm it's really broken
$ mount /dev/sda1 /mnt
  • If it mounts - are you sure it's broken? if Yes - run
$ btrfs scrub start /mnt

to scrub the system, and

$ btrfs scrub status /mnt

to monitor it

  • If it doesn't mount, try to scrub the device just in case it works
$ btrfs scrub start /dev/sda1

and

$ btrfs scrub status /dev/sda1

to monitor. Once complete, try mounting, if yes, you're fixed.

  • If scrubbing is not an option or does not resolve the issue

then instead try mount -o usebackuproot

$ mount -o usebackuproot /dev/sda1 /mnt

Warning: All of the above steps are considered safe and should make no destructive changes to disk. If the above doesn't fix things for you, you can continue with the below steps but the situation is serious enough to justify a bug report, please!

  • Run "btrfs check <device>"
$ btrfs check /dev/sda1

This isn't going to help, but save the log somewhere, it will be useful for the bug report.

  • Seriously consider running "btrfs restore <device> <somewhereto copy data>"
$ btrfs restore /dev/sda1 /mnt/usbdrive

This won't fix anything but it will scan the filesystem and recover everything it can to the mounted device. This especially useful if your btrfs issues are actually caused by failing hardware and not btrfs fault.

  • Run "btrfs rescue super-recover <device>"
$ btrfs rescue super-recover /dev/sda1

Then try to mount the device normally. If it works, stop going.

  • Run "btrfs rescue zero-log <device>"
$ btrfs rescue zero-log /dev/sda1

Then try to mount the device normally. If it works, stop going.

  • Run "btrfs rescue chunk-recover <device>"
$ btrfs rescue chunk-recover /dev/sda1

This will take a LONG while. Then try to mount the device normally. If it works, stop going.

  • If you didn't run it earlier, be sure to now run "btrfs restore <device> <somewhere to copy data>"
$ btrfs restore /dev/sda1 /mnt/usbdrive
  • Failure to use btrfs restore at this point but continuing to attempt repairs means you are at a very high risk of data loss. It is advisable to use btrfs restore to recover as much data as possible before continuing.

Warning: The above tools had a small chance of making unwelcome changes. Below this point there is a higher risk of damage. Do not continue unless you're prepared to accept the consequences of your choice.

  • Now, ONLY NOW, try btrfsck aka "btrfs check --repair <device>"
$ btrfs check --repair /dev/sda1

最后,上面的步骤都不能解决问题,因此最终是把磁盘上的文件全部拷贝出来,然后重新格式化分区,再把文件全部拷贝回去,解决问题。

参考链接


发布者

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注