我在嘗試在磁碟映像上安裝引導程式時遇到一些奇怪的行為。這是我遵循的過程:
$ 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?
答案1
MBR 分割表是一個非常簡單的結構,位於磁碟第一個 512 位元組區塊的末端。它不包含校驗和、雜湊值或其他錯誤保護功能。
透過針對您建立的檔案系統/分割區映像運行fdisk -l
,您實際上會強制其將其第一個區塊(分割區引導記錄,簡稱 PBR)誤解為 MBR。正如您所演示的,這會導致無意義的輸出。
如果我沒記錯的話,創建的 PBRextlinux
將包含啟動程式碼位於 MBR 中實際分區表所佔用的位置。fdisk
讀取部分extlinux
PBR 引導程式碼並嘗試將其顯示為 MBR 內容也是如此。難怪輸出毫無意義!