Operating system 自定义引导扇区虚拟光盘

Operating system 自定义引导扇区虚拟光盘,operating-system,virtual-machine,bootloader,bootstrapping,Operating System,Virtual Machine,Bootloader,Bootstrapping,下面是大量的“如何构建自己的操作系统”教程, 我应该通过将自定义加载程序写入软盘引导扇区 #include <sys/types.h> /* unistd.h needs this */ #include <unistd.h> /* contains read/write */ #include <fcntl.h> int main() { char boot_buf[512]; int floppy_desc, file_desc;

下面是大量的“如何构建自己的操作系统”教程,
我应该通过将自定义加载程序写入软盘引导扇区

#include <sys/types.h> /* unistd.h needs this */
#include <unistd.h>    /* contains read/write */
#include <fcntl.h>

int main()
{
    char boot_buf[512];
    int floppy_desc, file_desc;

    file_desc = open("./boot", O_RDONLY);
    read(file_desc, boot_buf, 510);
    close(file_desc);

    boot_buf[510] = 0x55;
    boot_buf[511] = 0xaa;

    floppy_desc = open("/dev/fd0", O_RDWR);
    lseek(floppy_desc, 0, SEEK_CUR);
    write(floppy_desc, boot_buf, 512);
    close(floppy_desc);
}
#include/*unistd.h需要这个*/
#include/*包含读/写操作*/
#包括
int main()
{
char boot_buf[512];
int软盘描述,文件描述;
文件描述=打开(“./boot”,仅限ordu);
读取(文件描述,引导,510);
关闭(文件描述);
boot_buf[510]=0x55;
boot_buf[511]=0xaa;
软盘描述=打开(“/dev/fd0”,O_RDWR);
lseek(软盘描述,0,寻道电流);
写入(软盘描述,启动,512);
关闭(软盘描述);
}
我没有带软驱的PC,我更喜欢通过VirtualBox在虚拟机上尝试整个项目

那么如何将自定义引导扇区写入虚拟CD映像,该映像将由我的虚拟机调用?:)
如果您有其他选择,请建议:)

(注意:这假设您使用的是linux)

您可以向某些磁盘写入可用于启动VirtualBox的磁盘映像,而不是写入需要真正的软盘驱动器的
/dev/fd0
。但是,您需要将文件填充到1.44MiB,因为这是典型的软盘

更好的方法是首先创建引导扇区二进制文件(使用0xAA55“魔法代码”),然后执行类似于
dd if=MyBootsectorBin of=Floppy.flp bs=512 count=2880的操作来创建输出文件Floppy.flp。然后可以通过VirtualBox(或者我的首选QEMU,通过
QEMU-fda Floppy.flp
)启动

我不确定是否有虚拟CD,但您可以轻松创建一个ISO来写入磁盘。这所需要的程序是mkisofs,可以从中阅读更多关于它的内容