我正在尝试从我的 NAS 中移除的 1TB 驱动器中恢复数据,但是运行时fdisk -lu /dev/sdb
我收到一条消息,提示没有有效的分区表。
据我所知,分区表位于磁盘的前 512 个字节内,因此,由于目前那里没有分区表,我写入新的分区表会造成任何损害吗?
Testdisk 找到了三个分区,我假设是通过扫描驱动器上的扇区,如果我将此分区表写入磁盘,它肯定只会影响前 512 个字节?如果事实证明它们不正确,我什么也没丢失,我的所有数据在磁盘的其余部分仍然完好无损,不是吗?
只要我不更改磁盘上的其他任何内容,我是否可以不随心所欲地重写分区表?如果我继续删除前 512 个字节,然后再次运行 Testdisk,它的扫描应该仍然会在磁盘上的原始位置找到三个原始分区?
如果这会影响磁盘上前 512 个字节之外的实际数据,我不愿意继续将该分区表写入磁盘。
任何指导将不胜感激。
问候 Rich
答案1
经过一些简短的测试,并且仅在虚拟环境中使用 TestDisk 和 sfdisk(我无法确认在 fdisk 或 gparted 之类的程序中创建新的分区表是否会使其保持完整)我倾向于说不,写入分区表不会影响除前 512 个字节以外的任何内容。
以下是测试步骤...
我创建了一个 100MB 的硬盘并对其进行了如下分区:
然后我挂载并向每个分区添加文件,然后擦除前 512 个字节
sudo dd if=/dev/zero bs=1 count=512 conv=notrunc of=/dev/sdb
使用 fdisk 快速检查显示该数据已被清除
richard@mint14 ~/Disktests $ sudo fdisk -lu /dev/sdb
Disk /dev/sdb: 104 MB, 104857600 bytes
255 heads, 63 sectors/track, 12 cylinders, total 204800 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 identifier: 0x00000000
Disk /dev/sdb doesn't contain a valid partition table
因此我运行了 TestDisk,通过扫描驱动器成功找到了分区,然后我将它们写入磁盘。
此后,我使用 sfdisk 转储了分区表
richard@mint14 ~/Disktests $ sudo sfdisk -d /dev/sdb > sdb_partitions.out
Warning: extended partition does not start at a cylinder boundary.
DOS and Linux will interpret the contents differently.
richard@mint14 ~/Disktests $ cat sdb_partitions.out
# partition table of /dev/sdb
unit: sectors
/dev/sdb1 : start= 2048, size= 20480, Id=83, bootable
/dev/sdb2 : start= 22528, size= 61440, Id=83
/dev/sdb3 : start= 83968, size= 61440, Id= 5
/dev/sdb4 : start= 145408, size= 59392, Id= 7
/dev/sdb5 : start= 86016, size= 59392, Id=83
我复制了此文件,并手动编辑它以创建一个 20MB 的分区,因此该分区与第二个分区重叠,然后将其写回驱动器
richard@mint14 ~/Disktests $ sudo sfdisk /dev/sdb < sdb_partitions.out_modified
Checking that no-one is using this disk right now ...
OK
Disk /dev/sdb: 12 cylinders, 255 heads, 63 sectors/track
sfdisk: ERROR: sector 0 does not have an MSDOS signature
/dev/sdb: unrecognised partition table type
Old situation:
No partitions found
New situation:
Warning: The partition table looks like it was made
for C/H/S=*/173/42 (instead of 12/255/63).
For this listing I'll assume that geometry.
Units = sectors of 512 bytes, counting from 0
Device Boot Start End #sectors Id System
/dev/sdb1 * 2048 43007 40960 83 Linux
start: (c,h,s) expected (0,48,33) found (0,32,33)
end: (c,h,s) expected (5,158,42) found (2,172,42)
/dev/sdb2 0 - 0 0 Empty
/dev/sdb3 0 - 0 0 Empty
/dev/sdb4 0 - 0 0 Empty
Warning: partition 1 does not end at a cylinder boundary
Successfully wrote the new partition table
Re-reading the partition table ...
使用 fdisk 进行另一次快速检查表明它已成功将此分区表写入磁盘
richard@mint14 ~/Disktests $ sudo fdisk -lu /dev/sdb
Disk /dev/sdb: 104 MB, 104857600 bytes
173 heads, 42 sectors/track, 28 cylinders, total 204800 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 identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sdb1 * 2048 43007 20480 83 Linux
最后使用sfdisk替换原来的分区表
richard@mint14 ~/Disktests $ sudo sfdisk --force /dev/sdb < sdb_partitions.out
Checking that no-one is using this disk right now ...
OK
Disk /dev/sdb: 12 cylinders, 255 heads, 63 sectors/track
sfdisk: ERROR: sector 0 does not have an MSDOS signature
/dev/sdb: unrecognised partition table type
Old situation:
No partitions found
New situation:
Units = sectors of 512 bytes, counting from 0
Device Boot Start End #sectors Id System
/dev/sdb1 * 2048 22527 20480 83 Linux
/dev/sdb2 22528 83967 61440 83 Linux
/dev/sdb3 83968 145407 61440 5 Extended
/dev/sdb4 145408 204799 59392 7 HPFS/NTFS/exFAT
/dev/sdb5 86016 145407 59392 83 Linux
然后我再次安装这些文件并验证文件是否存在且完好无损。