我在尝试在磁盘映像上安装引导加载程序时遇到一些奇怪的行为。这是我遵循的过程:
$ dd if=/dev/zero of=test.img status=progress bs=200M count=1
1+0 records in
1+0 records out
209715200 bytes (210 MB, 200 MiB) copied, 0.190117 s, 1.1 GB/s
$ mkfs.ext2 test.img
mke2fs 1.47.0 (5-Feb-2023)
Discarding device blocks: done
Creating filesystem with 204800 1k blocks and 51200 inodes
Filesystem UUID: f6442813-7b8c-4636-b69e-334696e0840b
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
$ sudo mount test.img mount-point/ -o loop
$ fdisk -l test.img
Disk test.img: 200 MiB, 209715200 bytes, 409600 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
$ sudo extlinux -i mount-point/
mount-point/ is device /dev/loop0
Warning: unable to obtain device geometry (defaulting to 64 heads, 32 sectors)
(on hard disks, this is usually harmless.)
$ fdisk -l test.img
Disk test.img: 200 MiB, 209715200 bytes, 409600 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: 0x20ac7dda
Device Boot Start End Sectors Size Id Type
test.img1 3224498923 3657370039 432871117 206.4G 7 HPFS/NTFS/exFAT
test.img2 3272020941 5225480974 1953460034 931.5G 16 Hidden FAT16
test.img3 0 0 0 0B 6f unknown
test.img4 50200576 974536369 924335794 440.8G 0 Empty
Partition table entries are not in disk order.
我不明白为什么该extlinux -i
命令会在磁盘映像上创建新分区。我怀疑它可能会修改一些文件系统元数据,但我希望对细节进行一些澄清。另外,是否可以在未分区的磁盘映像上安装 Syslinux?
MBR 分区表是一个非常简单的结构,位于磁盘第一个 512 字节块的末尾。它不包含校验和、哈希值或其他错误保护功能。
通过针对您创建的文件系统/分区映像运行
fdisk -l
,您实际上会强制其将其第一个块(分区引导记录,简称 PBR)误解为 MBR。正如您所演示的,这会导致无意义的输出。如果我没记错的话,创建的 PBR将在 MBR 中实际分区表占用的位置
extlinux
包含引导代码。fdisk
读取部分extlinux
PBR 引导代码并尝试将其显示为 MBR 内容也是如此。难怪输出毫无意义!