最近磁盘上的Btrfs分区在调整大小的时候,报错:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
$ 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
1 |
$ mount /dev/sda1 /mnt |
- If it mounts - are you sure it's broken? if Yes - run
1 |
$ btrfs scrub start /mnt |
to scrub the system, and
1 |
$ btrfs scrub status /mnt |
to monitor it
- If it doesn't mount, try to scrub the device just in case it works
1 |
$ btrfs scrub start /dev/sda1 |
and
1 |
$ 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
1 |
$ 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>"
1 |
$ 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>"
1 |
$ 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>"
1 |
$ btrfs rescue super-recover /dev/sda1 |
Then try to mount the device normally. If it works, stop going.
- Run "btrfs rescue zero-log <device>"
1 |
$ btrfs rescue zero-log /dev/sda1 |
Then try to mount the device normally. If it works, stop going.
- Run "btrfs rescue chunk-recover <device>"
1 |
$ 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>"
1 |
$ 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>"
1 |
$ btrfs check --repair /dev/sda1 |
最后,上面的步骤都不能解决问题,因此最终是把磁盘上的文件全部拷贝出来,然后重新格式化分区,再把文件全部拷贝回去,解决问题。