环境
- Time 2022-11-11
- WSL-Ubuntu 22.04
- QEMU 6.2.0
- NASM 2.15.05
前言
说明
参考:https://os.phil-opp.com/multiboot-kernel/
目标
将编写好的内核可执行文件,制作成 ISO 镜像,然后从 QEMU 启动。
建立文件目录
isofiles
└── boot├── grub│ └── grub.cfg└── kernel.bin
grub.cfg
set timeout=0
set default=0menuentry "my os" {multiboot2 /boot/kernel.binboot
}
制作 ISO
安装依赖:apt-get install grub-pc-bin grub-common xorriso
制作镜像
root@jiangbo12490:~/git/game# grub-mkrescue -o os.iso isofiles
xorriso 1.5.4 : RockRidge filesystem manipulator, libburnia project.Drive current: -outdev 'stdio:os.iso'
Media current: stdio file, overwriteable
Media status : is blank
Media summary: 0 sessions, 0 data blocks, 0 data, 233g free
Added to ISO image: directory '/'='/tmp/grub.or37ho'
xorriso : UPDATE : 294 files added in 1 seconds
Added to ISO image: directory '/'='/root/git/game/isofiles'
xorriso : UPDATE : 298 files added in 1 seconds
xorriso : NOTE : Copying to System Area: 512 bytes from file '/usr/lib/grub/i386-pc/boot_hybrid.img'
ISO image produced: 2475 sectors
Written to medium : 2475 sectors at LBA 0
Writing to 'stdio:os.iso' completed successfully.
启动命令
qemu-system-x86_64 -cdrom os.iso -curses
总结
创建了一个内核可执行程序 kernel.bin,并且制作成 ISO 镜像,在 QEMU 中运行。