環境
- 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=0
menuentry "my os" {
multiboot2 /boot/kernel.bin
boot
}
製作 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 中執行。