在该fdisk
区域中,清除 MBR 需要写入 446 字节,并且要包括分区信息的清除,将前 512 字节清零就足够了:
dd if=/dev/zero of=/dev/sdb bs=512 count=1
清除 512 字节是否足以使parted
某些旧的分区表信息不再被识别?
答案1
写入512字节不够,需要清理掉至少两个 512 字节块。
如果您从原始光盘开始:
# dd if=/dev/sdb bs=512 count=80000 | od -c
0000000 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
*
234200000
80000+0 records in
80000+0 records out
40960000 bytes (41 MB) copied, 0.99129 s, 41.3 MB/s
然后启动parted
并创建分区:
# parted
(parted) unit GB
(parted) mklabel gpt
(parted) print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 2.15GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
(parted) mkpart primary 0 2
(parted) print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 2.15GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 0.00GB 2.15GB 2.15GB primary
(parted) quit
Information: You may need to update /etc/fstab.
再次查看磁盘,可以看到写入了超过512字节的数据:
# dd if=/dev/sdb bs=512 count=80000 | od -c
0000000 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
*
0000700 001 \0 356 376 377 377 001 \0 \0 \0 037 - @ \0 \0 \0
0000720 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
*
0000760 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 U 252
0001000 E F I P A R T \0 \0 001 \0 \ \0 \0 \0
0001020 351 356 t 217 \0 \0 \0 \0 001 \0 \0 \0 \0 \0 \0 \0
0001040 037 - @ \0 \0 \0 \0 \0 " \0 \0 \0 \0 \0 \0 \0
0001060 376 , @ \0 \0 \0 \0 \0 n T l 342 306 351 ^ E
0001100 237 ~ i 270 t 034 227 004 002 \0 \0 \0 \0 \0 \0 \0
0001120 200 \0 \0 \0 200 \0 \0 \0 / \n Z 202 \0 \0 \0 \0
0001140 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
*
0002000 257 = 306 017 203 204 r G 216 y = i 330 G } 344
0002020 _ _ 344 4 257 / 276 G 226 375 n 244 332 P 230 224
0002040 \0 \b \0 \0 \0 \0 \0 \0 377 ' @ \0 \0 \0 \0 \0
0002060 \0 \0 \0 \0 \0 \0 \0 \0 p \0 r \0 i \0 m \0
0002100 a \0 r \0 y \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0002120 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
*
234200000
80000+0 records in
80000+0 records out
40960000 bytes (41 MB) copied, 0.988582 s, 41.4 MB/s
然后,如果只清理前 512 个字节,parted
会发现一些信息:
# dd if=/dev/zero of=/dev/sdb bs=512 count=1
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.0030505 s, 168 kB/s
lm17base avanderneut # parted /dev/sdb
GNU Parted 2.3
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Warning: /dev/sdb contains GPT signatures, indicating that it has a GPT table.
However, it does not have a valid fake msdos partition table, as it should.
Perhaps it was corrupted -- possibly by a program that doesn't understand GPT
partition tables. Or perhaps you deleted the GPT table, and are now using an
msdos partition table. Is this a GPT partition table?
Yes/No? No
(parted) quit
您需要清理两个块才能消除此消息:
# dd if=/dev/zero of=/dev/sdb bs=512 count=2
2+0 records in
2+0 records out
1024 bytes (1.0 kB) copied, 0.00469557 s, 218 kB/s
# parted /dev/sdb
GNU Parted 2.3
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Error: /dev/sdb: unrecognised disk label
(parted) quit
清除光盘开头写入的所有信息至少需要清零三(1 个分区)512 字节块。对于 10 个分区,这会增加到五块。
分区表的副本写入光盘的末尾。如果您使用sgdisk
来备份分区表,然后将零写入第一个块,然后尝试使用 进行恢复sgdisk
,则该实用程序会抱怨备份和主分区表不匹配。
如果你已经sgdisk
安装了,最好先sgdisk --clear
清理 GPT 数据。这不会将表初始化为零,但它也会影响磁盘末尾备份副本。