如何在 Linux raid 上恢复分区表

如何在 Linux raid 上恢复分区表

我有一个 Linux raid(那些 md 设备),它只包含一个驱动器,并且上面有一个 btrfs 分区。

我不小心做了以下事情:

fdisk /dev/md126

我没有看到警告

The old btrfs signature will be removed by a write command.

Device does not contain a recognized partition table. Created a new
DOS disklabel with disk identifier 0x3cf67d6f

并输入 w 退出。

现在分区表不见了。

我尝试使用 testdisk /dev/md126,它会拾取我的分区,但是

Disk /dev/md126 - 1993 GB / 1856 GiB - CHS 486640640 2 4                                                                                                                                                                                       

The harddisk (1993 GB / 1856 GiB) seems too small! (< 1993 GB / 1856 GiB)                                                                                                                                                                      
Check the harddisk size: HD jumpers settings, BIOS detection...                                                                                                                                                                                

The following partition can't be recovered:                                                                                                                                                                                                    
     Partition               Start        End    Size in sectors                                                                                                                                                                               
>  Linux                16368   0  1 486657007   1  4 3893125120 [2018.10.18-11:37:13 v15254]                                                                                                                                                  










[ Continue ]                                                                                                                                                                                                                                   
btrfs blocksize=4096, 1993 GB / 1856 GiB

它似乎不允许我保留分区。

而且分手救援根本不显示分区

接下来我应该做什么?


这是我破坏分区表之前的 fdisk -l 输出:

Disk /dev/sdb: 1.8 TiB, 2000365380096 bytes, 3906963633 sectors
Disk model: EARX-00PASB0    
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xcca96a8e

Device     Boot   Start        End    Sectors  Size Id Type
/dev/sdb1          2048    4982527    4980480  2.4G fd Linux raid autodetect
/dev/sdb2       4982528    9176831    4194304    2G fd Linux raid autodetect
/dev/sdb3       9437184 3902564351 3893127168  1.8T fd Linux raid autodetect

Disk /dev/md126: 1.8 TiB, 19933000280061440 bytes, 3893125120 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

后:

Disk /dev/sdb: 1.8 TiB, 2000365380096 bytes, 3906963633 sectors
Disk model: EARX-00PASB0    
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xcca96a8e

Device     Boot   Start        End    Sectors  Size Id Type
/dev/sdb1          2048    4982527    4980480  2.4G fd Linux raid autodetect
/dev/sdb2       4982528    9176831    4194304    2G fd Linux raid autodetect
/dev/sdb3       9437184 3902564351 3893127168  1.8T fd Linux raid autodetect


Disk /dev/md126: 1.8 TiB, 1993280061440 bytes, 3893125120 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x3cf67d6f

这是当前情况的分开打印输出:

Model: Linux Software RAID Array (md)
Disk /dev/md126: 1993GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start  End  Size  Type  File system  Flags

这是具有类似配置的另一个驱动器的输出:

Model: Linux Software RAID Array (md)
Disk /dev/md123: 1995GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags: 

Number  Start  End     Size    File system  Flags
 1      0.00B  1995GB  1995GB  btrfs

答案1

您该设备上没有分区表。因此,尝试恢复分区(当您没有分区时)注定会失败。将分区表写入保存文件系统的设备上可能会损坏该文件系统。

尝试重新创建您的情况:

# file -s /dev/md100
/dev/md100: BTRFS Filesystem sectorsize 4096, nodesize 16384, leafsize 16384, UUID=fbae0a54-9d6b-4d20-9981-a1a385a0a91f, 120848384/205520896 bytes used, 1 devices
# fdisk /dev/md100
# file -s /dev/md100
/dev/md100: DOS/MBR boot sector

以下步骤对我的恢复很有帮助。

用于wipefs删除您编写的 msdos 分区标头:

# wipefs --all --types dos /dev/md100
/dev/md100: 2 bytes were erased at offset 0x000001fe (dos): 55 aa
/dev/md100: calling ioctl to re-read partition table: Success
# file -s /dev/md100
/dev/md100: data

用于btrfs-select-super恢复备份超级块:

笔记:我最终使用了,btrfs-select-super因为btrfs check由于某种原因无法/不愿意解决这个问题。请先阅读手册页,然后再继续。

# btrfs-select-super -s 1 /dev/md100
using SB copy 1, bytenr 67108864
# file -s /dev/md100
/dev/md100: BTRFS Filesystem sectorsize 4096, nodesize 16384, leafsize 16384, UUID=fbae0a54-9d6b-4d20-9981-a1a385a0a91f, 120848384/205520896 bytes used, 1 devices

之后,文件系统可以安装完整的文件。

但我不能保证同样的方法对你有用。如果可能的话,您不应直接在驱动器上运行此实验,而应使用写时复制覆盖

相关内容