然後看你的輸出, btrfs check --backup 的時候在 free space tree 發現找不到兩個 block group (或者 free space tree 壞了),分別是 4M 和 8M 大小的,這麼小的 BG 大概是 system bg 。可能是 system bg 在挪位置自動擴大的過程中遇到了啥問題(比如突然斷電)導致了不一致。
確實是這樣,不過內核 mount btrfs 的代碼和 btrfs check (btrfsprogs) 的代碼是兩套,這裏的問題可能不只需要用 backuproot 還需要讀到正確的 system bg 位置。 superblock 中有 system bg 位置的信息(dump-super --full 能看到的那些 sys_chunk_array ), root tree 中有 chunk tree 的位置,從 chunk tree 也能找到 system bg 。我懷疑 mount btrfs 的時候用的 superblock 的,btrfs check 的時候用的 backup root 找到的 root tree 的。
sudo fdisk -l /dev/sda
Disk /dev/sda: 465.76 GiB, 500107862016 bytes, 976773168 sectors
Disk model: DISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33553920 bytes
Disklabel type: gpt
Disk identifier: 1F3024F4-FA48-41AE-99B0-0069A99FE531
Device Start End Sectors Size Type
/dev/sda1 2048 209717247 209715200 100G Microsoft basic data
/dev/sda2 209717248 976773119 767055872 365.8G Linux filesystem
分区是紧邻没有重叠的。
btrfs check --readonly -s {0,1,2}都是同样的报错:
sudo btrfs check --readonly -s 0 /dev/sda2
using SB copy 0, bytenr 65536
Opening filesystem to check...
checksum verify failed on 32276480 wanted 0x00000000 found 0xb6bde3e4
checksum verify failed on 32276480 wanted 0x9ed7104b found 0x5a4d29a7
checksum verify failed on 32276480 wanted 0x9ed7104b found 0x5a4d29a7
bad tree block 32276480, bytenr mismatch, want=32276480, have=65536
Couldn't read tree root
ERROR: cannot open file system
sudo btrfs check --readonly -s 1 /dev/sda2
using SB copy 1, bytenr 67108864
Opening filesystem to check...
checksum verify failed on 32276480 wanted 0x00000000 found 0xb6bde3e4
checksum verify failed on 32276480 wanted 0x9ed7104b found 0x5a4d29a7
checksum verify failed on 32276480 wanted 0x9ed7104b found 0x5a4d29a7
bad tree block 32276480, bytenr mismatch, want=32276480, have=65536
Couldn't read tree root
ERROR: cannot open file system
sudo btrfs check --readonly -s 2 /dev/sda2
using SB copy 2, bytenr 274877906944
Opening filesystem to check...
checksum verify failed on 32276480 wanted 0x00000000 found 0xb6bde3e4
checksum verify failed on 32276480 wanted 0x9ed7104b found 0x5a4d29a7
checksum verify failed on 32276480 wanted 0x9ed7104b found 0x5a4d29a7
bad tree block 32276480, bytenr mismatch, want=32276480, have=65536
Couldn't read tree root
ERROR: cannot open file system
只有当使用backup roots时,才能open filesystem:
sudo btrfs check --readonly -s 0 --backup /dev/sda2
using SB copy 0, bytenr 65536
Opening filesystem to check...
Checking filesystem on /dev/sda2
UUID: d8d3bc1e-23f5-40e3-a059-5d7302c0df51
[1/8] checking log skipped (none written)
[2/8] checking root items
[3/8] checking extents
[4/8] checking free space tree
Space key logical 1048576 length 4194304 has no corresponding block group
Space key logical 5242880 length 8388608 has no corresponding block group
[5/8] checking fs roots
[6/8] checking only csums items (without verifying data)
[7/8] checking root refs
[8/8] checking quota groups skipped (not enabled on this FS)
found 360357588992 bytes used, error(s) found
total csum bytes: 206054124
total tree bytes: 517357568
total fs tree bytes: 273727488
total extent tree bytes: 27656192
btree space waste bytes: 50386636
file data blocks allocated: 359840231424
referenced 368491847680
sudo btrfs check --readonly -s 1 --backup /dev/sda2
using SB copy 1, bytenr 67108864
Opening filesystem to check...
Checking filesystem on /dev/sda2
UUID: d8d3bc1e-23f5-40e3-a059-5d7302c0df51
[1/8] checking log skipped (none written)
[2/8] checking root items
[3/8] checking extents
[4/8] checking free space tree
Space key logical 1048576 length 4194304 has no corresponding block group
Space key logical 5242880 length 8388608 has no corresponding block group
[5/8] checking fs roots
[6/8] checking only csums items (without verifying data)
[7/8] checking root refs
[8/8] checking quota groups skipped (not enabled on this FS)
found 360357588992 bytes used, error(s) found
total csum bytes: 206054124
total tree bytes: 517357568
total fs tree bytes: 273727488
total extent tree bytes: 27656192
btree space waste bytes: 50386636
file data blocks allocated: 359840231424
referenced 368491847680
sudo btrfs check --readonly -s 2 --backup /dev/sda2
using SB copy 2, bytenr 274877906944
Opening filesystem to check...
Checking filesystem on /dev/sda2
UUID: d8d3bc1e-23f5-40e3-a059-5d7302c0df51
[1/8] checking log skipped (none written)
[2/8] checking root items
[3/8] checking extents
[4/8] checking free space tree
Space key logical 1048576 length 4194304 has no corresponding block group
Space key logical 5242880 length 8388608 has no corresponding block group
[5/8] checking fs roots
[6/8] checking only csums items (without verifying data)
[7/8] checking root refs
[8/8] checking quota groups skipped (not enabled on this FS)
found 360357588992 bytes used, error(s) found
total csum bytes: 206054124
total tree bytes: 517357568
total fs tree bytes: 273727488
total extent tree bytes: 27656192
btree space waste bytes: 50386636
file data blocks allocated: 359840231424
referenced 368491847680
Mar 02 19:53:00 kernel: BTRFS: device fsid d8d3bc1e-23f5-40e3-a059-5d7302c0df51 devid 1 transid 5921 /dev/sda2 (8:2) scanned by mount (93222)
Mar 02 19:53:00 kernel: BTRFS info (device sda2): first mount of filesystem d8d3bc1e-23f5-40e3-a059-5d7302c0df51
Mar 02 19:53:00 kernel: BTRFS info (device sda2): using crc32c (crc32c-intel) checksum algorithm
Mar 02 19:53:00 kernel: BTRFS error (device sda2): bad tree block start, mirror 1 want 32276480 have 0
Mar 02 19:53:00 kernel: BTRFS error (device sda2): bad tree block start, mirror 2 want 32276480 have 65536
Mar 02 19:53:00 kernel: BTRFS warning (device sda2): couldn't read tree root
Mar 02 19:53:00 kernel: BTRFS warning (device sda2): try to load backup roots slot 1
Mar 02 19:53:00 kernel: BTRFS info (device sda2): enabling ssd optimizations
Mar 02 19:53:00 kernel: BTRFS info (device sda2): enabling free space tree
Mar 02 19:53:00 kernel: BTRFS info (device sda2): trying to use backup root at mount time
sudo btrfs check --repair --tree-root 31424512 /dev/sda2
enabling repair mode
WARNING:
Do not use --repair unless you are advised to do so by a developer
or an experienced user, and then only after having accepted that no
fsck can successfully repair all types of filesystem corruption. E.g.
some software or hardware bugs can fatally damage a volume.
The operation will start in 10 seconds.
Use Ctrl-C to stop it.
10 9 8 7 6 5 4 3 2 1
Starting repair.
Opening filesystem to check...
parent transid verify failed on 31424512 wanted 5921 found 5918
parent transid verify failed on 31424512 wanted 5921 found 5918
parent transid verify failed on 31424512 wanted 5921 found 5918
Ignoring transid failure
Checking filesystem on /dev/sda2
UUID: d8d3bc1e-23f5-40e3-a059-5d7302c0df51
[1/8] checking log skipped (none written)
[2/8] checking root items
Fixed 0 roots.
[3/8] checking extents
No device size related problem found
[4/8] checking free space tree
Space key logical 1048576 length 4194304 has no corresponding block group
deleted orphan fst entries for range [1048576, 5242880)
Space key logical 5242880 length 8388608 has no corresponding block group
deleted orphan fst entries for range [5242880, 13631488)
[5/8] checking fs roots
[6/8] checking only csums items (without verifying data)
[7/8] checking root refs
[8/8] checking quota groups skipped (not enabled on this FS)
found 360357588992 bytes used, no error found
total csum bytes: 206054124
total tree bytes: 517357568
total fs tree bytes: 273727488
total extent tree bytes: 27656192
btree space waste bytes: 50386636
file data blocks allocated: 359840231424
referenced 368491847680
可以rw mount了,scrub未发现错误,文件系统可以正常读写了
UUID: d8d3bc1e-23f5-40e3-a059-5d7302c0df51
Scrub started: Tue Mar 3 11:20:10 2026
Status: finished
Duration: 0:13:37
Total to scrub: 336.09GiB
Rate: 421.24MiB/s
Error summary: no errors found