
我的 NAS 中有一個帶有 BTRFS 的 500GB 磁碟。我最近獲得了一個 4TB 磁碟,我想只使用新磁碟,而不需要任何停機時間。所以我跑了btrfs replace start 1 /dev/sdb .
,等待它完成並拔掉 500GB 驅動器。
現在,由於我無法存取 4TB 磁碟,我想恢復更換的 500GB 磁碟上的所有數據,但其上的 BTRFS 分割區不再被識別。我嘗試正常安裝它,使用-o degraded
,-o recovery,ro
,我什至嘗試過btrfs restore
,btrfs check
,但都失敗了。我在這裡有什麼選擇?
答案1
這是一個過去的問題,但我遇到了同樣的情況,會回答。
我btrfs replace
在 debian bullseye(5.10.0-13-amd64) 上運行 RAID1 檔案系統,並使用下列程序在 Manjaro(5.13.19-2) 上恢復。
原因
至少對於內核版本 5.10,btrfs replace
命令最終調用btrfs_scratch_superblocks
此位置的函數:GitHub
此函數刪除原始磁碟超級區塊上的「魔術字串」。
我實際上在我的環境中得到了以下結果:
# btrfs inspect-internal dump-super -F /dev/sdb1
superblock: bytenr=65536, device=/dev/sdb1
---------------------------------------------------------
csum_type 0 (crc32c)
csum_size 4
csum 0x7d4435b9 [DON'T MATCH]
bytenr 65536
flags 0x1
( WRITTEN )
magic ........ [DON'T MATCH]
根據維基百科,「magic」(=「魔法字串」)必須是_BHRfS_M
.
恢復程式
參考What if I don't have wipefs at hand?
關於維基百科,在 shell 上執行以下命令。
在另一台 PC 上運行它可能比在更換的磁碟所連接的 PC 上運行更安全。
請根據您的環境重寫設備和安裝點位置。
(在我的環境中,它成功為 /dev/sdb1 !)
# # backup magic strings just in case
# dd bs=1 count=8 if=/dev/sdb skip=$((64*1024+64)) of=~/magic1
# dd bs=1 count=8 if=/dev/sdb skip=$((64*1024*1024+64)) of=~/magic2
# dd bs=1 count=8 if=/dev/sdb skip=$((256*1024*1024*1024+64)) of=~/magic3
# # write magic string
# echo "_BHRfS_M" | dd bs=1 count=8 of=/dev/sdb seek=$((64*1024+64))
# echo "_BHRfS_M" | dd bs=1 count=8 of=/dev/sdb seek=$((64*1024*1024+64))
# echo "_BHRfS_M" | dd bs=1 count=8 of=/dev/sdb seek=$((256*1024*1024*1024+64))
# btrfs device scan
# mkdir -p /mnt/before_replace
# mount -o degraded,ro /dev/sdb /mnt/before_replace
我英文不好,如果閱讀起來有困難,請見諒。但我希望這可以幫助處於相同情況的其他人。