简体   繁体   English

在MBR中指定分区表时,磁盘映像显示为不可引导

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

I recently added a FAT32 partition table to my bootloader and now BIOS won't recognize it as a bootable MBR. 我最近在自举程序中添加了FAT32分区表,现在BIOS无法将其识别为可启动MBR。 I believe the binary is 512 Bytes and there is a valid signature. 我相信二进制文件是512字节,并且有一个有效的签名。 Is it something wrong with the "TIMES 499" or something else? “ 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

I expected "Loading..." but instead got "No Bootable Device." 我原本希望“正在加载...”,但是却收到“没有可启动设备”。

@Jester is correct that the partition table entries should start at byte 446 and not 499 and your partition entries are greater than 16 bytes each. @Jester是正确的,分区表条目应该从字节446开始而不是499,并且您的分区条目每个都大于16个字节。 As a result your MBR is larger than 512 bytes and the 0xaa55 disk signature isn't in the last 2 bytes so the machine doesn't see this as bootable media. 结果,您的MBR大于512字节,并且0xaa55磁盘签名不在最后2个字节中,因此计算机不会将其视为可启动媒体。

The partition table must be 64 bytes in size. 分区表的大小必须为64个字节。 446+64(partition table size)+2(boot signature)=512. 446 + 64(分区表大小)+2(启动签名)= 512 They layout of each partition entry is: 它们对每个分区条目的布局是:

在此处输入图片说明

It is unclear where you got the layout for your partition entries but the MBR should have looked like this given what appear to be the entries you were trying to generate: 不清楚您在哪里获得了分区条目的布局,但是考虑到您试图生成的条目,MBR应该看起来像这样:

[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

When I run SFDISK on the disk image file with: 当我使用以下命令在磁盘映像文件上运行SFDISK时:

sfdisk disk.img

I get these partition entries listed: 我列出了这些分区条目:

 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) 

Booting it in QEMU with the disk image as hard drive A using: 使用以下命令在磁盘映像作为硬盘A的QEMU中进行引导:

qemu-system-i386 -hda disk.img

I get this on the display: 我在显示器上得到这个:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM