VirtualBox-找不到可启动媒体 [英] VirtualBox - No bootable medium found

查看:157
本文介绍了VirtualBox-找不到可启动媒体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于具有类似标题的stackoverflow有很多问题.我读了所有这些内容,但没有一个能解决我的问题.这就是为什么我提出这个问题.

There are a lot of question on stackoverflow with the similar title. I read all of them, but none of them answers my problem. This is why I opened this question.

我正在用汇编器和C创建一个操作系统.我发现必须将C代码编译为二进制格式,提取文本部分并将其保存为文件,然后将其转换为ISO,然后将其安装到虚拟机中.磁盘,然后将我的操作系统加载到VirtualBox中.因此,这是我要避免的许多工作.我不想每次都将二进制文件转换为ISO.

I am creating an operating system in assembler and C. I found that I must compile C code to binary format, extract text section and save it as a file, then convert it to ISO, then mount it to virtual optical dive of diskete and then load my OS in VirtualBox. So, that is a lot of work I want to avoid. I don't want to convert my binary file to ISO every time.

因此,我决定将操作系统的二进制计算机代码放入虚拟硬盘驱动器(VDI文件),然后将其设置为引导顺序的顶部并加载,而不是从虚拟光盘驱动器ISO加载.

So, I decided to put the binary machine code of my OS to virtual hard drive (VDI file) and then set it to the top of boot order and load it instead of loading from virtual optical drive ISO.

我正在研究VDI的工作原理,发现它通常是动态分配的,并且只存储数据的开头.因此,VDI的开头表示一个标头,其余的是存储在虚拟驱动器上的实际数据.因此,我发现数据从某个地址开始(对于我来说,它是从VDI文件开始的0x00200000).

I was researching how VDI works and I found that it is usually dinamically allocated and that only the beginning of data is stored. So, the start of VDI represents a header and the the rest is actual data stored on virtual drive. So, I found that data starts at some address (in my case it is 0x00200000 from the start of the VDI file).

然后,我基本上用该地址55 AA从该地址填充到VDI文件的末尾.因此,我想它现在意味着该磁盘是可引导的(因为在第一个扇区的末尾仍是签名55 AA).

Then, I basically filled from that address to the end of VDI file with pattern 55 AA. So, I suppose it now means that the disk is bootable (because at the end of first sector is still signature 55 AA).

我启动了虚拟机,它说:

I started virtual machine and it says:

未找到可启动媒体!系统停止

No bootable medium found! System halted

有什么办法解决这个问题?为什么我的虚拟磁盘仍然无法启动?

Is there any way to solve this? Why is my virtual disk still not bootable?

这是实际的VDI文件: 1.vdi

推荐答案

您没有提供一个最小的完整可验证示例,其中显示了引导加载程序以及如何将其加载到VDI中.但是至少您需要在主引导记录的最后2个字节中放置0xAA55.下面的示例创建一个简单的引导程序;创建一个2MiB原始图像;将引导程序放置在原始映像中;并将原始图像转换为VDI.

You don't provide a minimal complete verifiable example showing a bootloader and how you get it into a VDI. But at a minimum you'll need to place 0xAA55 in the last 2 bytes of the master boot record. The example below creates a simple bootloader; creates a 2MiB raw image; places the bootloader in the raw image; and converts the raw image to a VDI.

boot.asm:

BITS 16
ORG 0x7C00

    xor ax, ax
    mov ds, ax
    mov ss, ax       ; Stack below bootloader
    mov sp, 0x7c00

    mov ax, 0xb800   ; Video segment b800
    mov es, ax

    ; Print Hello with white on light magenta
    mov word [es:0x0], 0x57 << 8 | 'H'
    mov word [es:0x2], 0x57 << 8 | 'e'
    mov word [es:0x4], 0x57 << 8 | 'l'
    mov word [es:0x6], 0x57 << 8 | 'l'
    mov word [es:0x8], 0x57 << 8 | 'o'

    ; End with infinite loop
    cli
endloop:
    hlt
    jmp endloop

; Fill out to 510 bytes and add boot signature
times 510 - ($ - $$) db 0
dw 0xAA55            ; add boot signature at the end of bootloader

然后我使用此命令创建引导加载程序文件boot.bin:

I then use this command to create the bootloader file boot.bin:

nasm -f bin boot.asm -o boot.bin

创建2MiB磁盘映像文件1.raw:

Create a 2MiB disk image file 1.raw:

dd if=/dev/zero of=1.raw bs=1024 count=2048

将引导程序boot.bin放置在文件1.raw的开头,而不会截断文件的其余部分:

Place the bootloader boot.bin at beginning of file 1.raw without truncating the rest of file:

dd if=boot.bin of=1.raw conv=notrunc

1.raw创建一个名为1.vdi的VDI映像:

Create a VDI image called 1.vdi from 1.raw:

rm -f 1.vdi
VBoxManage convertfromraw 1.raw 1.vdi --format VDI

当添加到VirtualBox下的虚拟机时,我会在显示屏上看到它:

When added to a virtual machine under VirtualBox I get this on the display:

在您提供的图像文件1.vdi中,我在执行hexdump时注意到了这一点:

In your supplied image file 1.vdi I noticed this when I did a hexdump:

00200000  aa 55 aa 55 aa 55 aa 55  aa 55 aa 55 aa 55 aa 55
*
002004c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
*
00300000

此输出向我建议您反转了文件中启动签名的字节.它应该是0x55,然后是0xaa. 0xaa55作为WORD存储,其字节反转.

This output suggests to me that you reversed the bytes of the boot signature in your file. It should be 0x55 followed by 0xaa. 0xaa55 as a WORD is stored with the bytes reversed.

有效的引导介质可能不仅仅只是使引导签名正确.一些BIOS可能会在引导加载程序中通常找到的前几个字节中搜索某些指令.找不到此类说明(示例通常包括诸如 JMP XOR CLI MOV 之类的内容)可能会导致这种情况认为它不是有效的启动媒体.

Valid boot medium may be more than just getting the boot signature correct. Some BIOSes may search for certain instructions in the first few bytes that are typically found in bootloaders. Failure to find such instructions (examples often include things like JMP, XOR, CLI, MOV) may cause it to think that it isn't valid boot medium.

一种测试结尾处的0xAA55本身是否足够的方法,我使用了hexedit并修改了1.vdi文件,使其看起来像这样:

One way to test whether 0xAA55 at the end is enough by itself I used hexedit and modified your 1.vdi file to look like this:

00200000  aa 55 aa 55 aa 55 aa 55  aa 55 aa 55 aa 55 aa 55
00200010  aa 55 aa 55 aa 55 aa 55  aa 55 aa 55 aa 55 aa 55
*
002001f0  aa 55 aa 55 aa 55 aa 55  aa 55 aa 55 aa 55 55 aa <-- Corrected signature
                                                               at 1fe & 1ff
00200200  aa 55 aa 55 aa 55 aa 55  aa 55 aa 55 aa 55 aa 55
*
002004c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
*
00300000

仅凭该更改运行是行不通的.然后,我使用hexedit并放置了 CLI 操作码(0xFA)作为扇区的第一个字节.生成的文件现在看起来像:

Running with that change alone didn't work. I then used hexedit and placed a CLI opcode (0xFA) as the first byte of the sector. The resulting file now looked like:

           v-- CLI instruction
00200000  fa 55 aa 55 aa 55 aa 55  aa 55 aa 55 aa 55 aa 55
00200010  aa 55 aa 55 aa 55 aa 55  aa 55 aa 55 aa 55 aa 55
*
002001f0  aa 55 aa 55 aa 55 aa 55  aa 55 aa 55 aa 55 55 aa
00200200  aa 55 aa 55 aa 55 aa 55  aa 55 aa 55 aa 55 aa 55
*
002004c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
*
00300000

我已将fa放置为引导加载程序的第一个字节.现在,当我使用您的映像时,错误找不到可启动媒体!系统停止不再出现.这表明VirtualBox不仅在寻找引导签名,而且还在进行某种健全性检查,以确定引导加载程序的启动是否似乎是可执行指令.这在BIOS中并不罕见.有些人可能会做这样的检查,有些人则不会.目前,我还没有查看VirtualBox源代码来确定其执行的确切检查.

I have placed fa as the first byte int the bootloader. Now when I use your image the error No bootable medium found! System halted no longer appears. This suggests that VirtualBox is looking for more than a boot signature, and is doing some kind of sanity check to determine if the start of the bootloader appears to be executable instructions. This is not uncommon for BIOSes. Some may do such a check, some may not. At this time I haven't looked over the VirtualBox source code to determine the exact checks it performs to make its determination.

这篇关于VirtualBox-找不到可启动媒体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆