在 MBR 中指定分区 table 时,磁盘映像出现非 bootable

Disk image appears non-bootable when specifying a partition table in an MBR

我最近在我的引导加载程序中添加了一个 FAT32 分区 table,现在 BIOS 无法将其识别为 bootable MBR。我相信二进制文件是 512 字节并且有一个有效的签名。是 "TIMES 499" 有问题还是其他什么?

[BITS 16]
[ORG 0x7c00]

mov ah, 0x0e        ; Starts TTY mode to display booting message
mov al, 'L'
int 0x10
mov al, 'o'
int 0x10
mov al, 'a'
int 0x10
mov al, 'd'
int 0x10
mov al, 'i'
int 0x10
mov al, 'n'
int 0x10
mov al, 'g'
int 0x10
mov al, '.'
int 0x10
int 0x10
int 0x10

TIMES 499 - ($ - $$) DB 0 ; Zerofill

; ------------- Partition Table

; Partition #1
DQ 0x00000000
DB 0x0c ; Type Code
DW 0x0000
DB 0x00
DQ 0x000003E8 ; LBA Begin
DQ 0x000186A0 ; # of Sectors

; Partition #2
DQ 0x00000000
DB 0x0c ; Type Code
DW 0x0000
DB 0x00
DQ 0x00018A88 ; LBA Begin
DQ 0x000186A0 ; # of Sectors

; Partition #3
DQ 0x00000000
DB 0x0c ; Type Code
DW 0x0000
DB 0x00
DQ 0x00031128 ; LBA Begin
DQ 0x000186A0 ; # of Sectors

; Partition #4
DQ 0x00000000
DB 0x0c ; Type Code
DW 0x0000
DB 0x00
DQ 0x000497C8 ; LBA Begin
DQ 0x000186A0 ; # of Sectors

; ------------- End Partition Table

DW 0xAA55 ; MBR Signature

我期望 "Loading..." 但得到的却是 "No Bootable Device."

@Jester 是正确的,分区 table 条目应该从字节 446 而不是 499 开始,并且您的分区条目每个都大于 16 字节。因此,您的 MBR 大于 512 字节并且 0xaa55 磁盘签名不在最后 2 个字节中,因此机器不会将其视为 bootable media.

分区 table 的大小必须为 64 字节。 446+64(分区 table 大小)+2(引导签名)=512。他们每个 partition entry 的布局是:

不清楚您从何处获得分区条目的布局,但考虑到您尝试生成的条目看起来应该是这样的:

[BITS 16]
[ORG 0x7c00]

mov ah, 0x0e        ; Starts TTY mode to display booting message
mov al, 'L'
int 0x10
mov al, 'o'
int 0x10
mov al, 'a'
int 0x10
mov al, 'd'
int 0x10
mov al, 'i'
int 0x10
mov al, 'n'
int 0x10
mov al, 'g'
int 0x10
mov al, '.'
int 0x10
int 0x10
int 0x10
jmp $                  ; End with an infinite loop

TIMES 446 - ($ - $$) DB 0 ; Zerofill

; ------------- Partition Table

; Partition #1
DB 0x00                ; Status (bootable?)
DB 0x00, 0x00, 0x00    ; CHS Start
DB 0x0c                ; Type Code
DB 0x00, 0x00, 0x00    ; CHS End
DD 0x000003E8          ; LBA Begin
DD 0x000186A0          ; # of Sectors

; Partition #2
DB 0x00                ; Status (bootable?)
DB 0x00, 0x00, 0x00    ; CHS Start
DB 0x0c                ; Type Code
DB 0x00, 0x00, 0x00    ; CHS End
DD 0x00018A88          ; LBA Begin
DD 0x000186A0          ; # of Sectors

; Partition #3
DB 0x00                ; Status (bootable?)
DB 0x00, 0x00, 0x00    ; CHS Start
DB 0x0c                ; Type Code
DB 0x00, 0x00, 0x00    ; CHS End
DD 0x00031128          ; LBA Begin
DD 0x000186A0          ; # of Sectors

; Partition #4
DB 0x00                ; Status (bootable?)
DB 0x00, 0x00, 0x00    ; CHS Start
DB 0x0c                ; Type Code
DB 0x00, 0x00, 0x00    ; CHS End
DD 0x000497C8          ; LBA Begin
DD 0x000186A0          ; # of Sectors

; ------------- End Partition Table

DW 0xAA55 ; MBR Signature

当我运行 SFDISK 上的磁盘映像文件有:

sfdisk disk.img

我列出了这些分区条目:

Device     Boot  Start    End Sectors  Size Id Type
disk.img1         1000 100999  100000 48.8M  c W95 FAT32 (LBA)
disk.img2       101000 200999  100000 48.8M  c W95 FAT32 (LBA)
disk.img3       201000 300999  100000 48.8M  c W95 FAT32 (LBA)
disk.img4       301000 400999  100000 48.8M  c W95 FAT32 (LBA)

使用磁盘映像作为硬盘驱动器 A 在 QEMU 中启动它:

qemu-system-i386 -hda disk.img

我在显示屏上看到了这个: