Problems with GRUB and QEMU
Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Problems with GRUB and QEMU
Hi everyone, I have just started my journey in OS development. I obviously started with the Bare Bones tutorial on the wiki, and have almost finished with no issues.
In the final step i am not able to run my ISO image on QEMU, but have no problems when just running the kernel.
I have been running this code on windows the WSL (Windows Sub-system for Linux) with no other issues. No errors appear when running the grub-mkrescue command and same with QEMU.
When launching the ISO in QEMU, I get the booting from CD/DVD text, and it goes straight to the grub minimal bash.
The code is exactly the same as the Bare Bones tutorial, with compilations through a Makefile listed here:
I realise this question gets asked quite a bit, but I haven't found an answer to solve it.
I have installed grub-pc-bin many times.
Is WSL the correct option for a windows user, or should I be taking a different approach.
In the final step i am not able to run my ISO image on QEMU, but have no problems when just running the kernel.
I have been running this code on windows the WSL (Windows Sub-system for Linux) with no other issues. No errors appear when running the grub-mkrescue command and same with QEMU.
When launching the ISO in QEMU, I get the booting from CD/DVD text, and it goes straight to the grub minimal bash.
- Screenshot 2025年07月31日 181247.png
- Screenshot 2025年07月31日 181247.png (11.53 KiB) Viewed 11999 times
- Screenshot 2025年07月31日 181259.png
- Screenshot 2025年07月31日 181259.png (9.47 KiB) Viewed 11999 times
Code: Select all
SRCDIR := src
TMPDIR := tmp
BINDIR := bin
ISODIR := iso
COMPILER := cross/bin/i686-elf
myos.iso: myos.bin
@sudo grub-mkrescue -o $(BINDIR)/myos.iso $(ISODIR)
myos.bin: kernel.o boot.o
@$(COMPILER)-gcc -T $(SRCDIR)/linker.ld -o $(BINDIR)/myos.bin -ffreestanding -O2 -nostdlib $(TMPDIR)/boot.o $(TMPDIR)/kernel.o -lgcc
@cp $(BINDIR)/myos.bin $(ISODIR)/boot/myos.bin
@grub-file --is-x86-multiboot $(BINDIR)/myos.bin
boot.o:
@$(COMPILER)-as $(SRCDIR)/boot.s -o $(TMPDIR)/boot.o
kernel.o:
@$(COMPILER)-gcc -c $(SRCDIR)/kernel.c -o $(TMPDIR)/kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra
# if you want C++ instead; uncomment this
# i686-elf-g++ -c kernel.cpp -o kernel.o -ffreestanding -O2 -Wall -Wextra -fno-exceptions -fno-rtti
.PHONY: clean q qw
qw:
qemu-system-i386 -kernel $(ISODIR)/boot/myos.bin
q:
qemu-system-i386 -cdrom $(BINDIR)/myos.iso
clean:
rm -rf $(TMPDIR)/*
I have installed grub-pc-bin many times.
Is WSL the correct option for a windows user, or should I be taking a different approach.
- Octocontrabass
- Member
Member - Posts: 5968
- Joined: Mon Mar 25, 2013 7:01 pm
- MichaelPetch
- Member
Member - Posts: 848
- Joined: Fri Aug 26, 2016 1:41 pm
- Libera.chat IRC: mpetch
Re: Problems with GRUB and QEMU
Post by MichaelPetch »
[引用]I hate to ask but are you sure the file is actually there and contains what you expect. I noticed your Makefile doesn't copy it there. The minimal prompt from GRUB is usually indicative of a missing grub.cfg or some problem with the contents of the file. What does your grub.cfg contain?
Re: Problems with GRUB and QEMU
grub.cfg
The makefile doesn't copy the config because it stays there and stays the same. From what I understand the grub mkrescue command automatically looks for the config file so there is no need to include it in the command or remove the file every time, however I could be wrong
Most of the rest of the code is the same as the tutorial
Code: Select all
menuentry "myos" {
multiboot /boot/myos.bin
}
Most of the rest of the code is the same as the tutorial
- MichaelPetch
- Member
Member - Posts: 848
- Joined: Fri Aug 26, 2016 1:41 pm
- Libera.chat IRC: mpetch
Re: Problems with GRUB and QEMU
Post by MichaelPetch »
Are you sure grub.cfg wasn't deleted? Anyway in WSL2 Ubuntu 22.04, I took the barebones tutorial as is but placed the files in the directories your Makefile expected them. I created src/kernel.c src/boot.s src/linker.ld. I created the iso tree with the command `mkdir -p iso/boot/grub`. I created the directories tmp and bin as well. I created the file iso/boot/grub.cfg with the contents you provided here (same as the barebones tutorial). I used your Makefile with the exception that I modified it so `COMPILER` pointed to my i686-elf cross compiler. I ran `make` on it and then used the command `make q` and it worked as expected. I also ran `make qw` and the results were as expected.
grub-mkrescue won't delete the grub.cfg file so if you don't delete it, it will remain. Are you absolutely sure there is a grub.cfg file in the directory iso/boot/ ? If I remove my grub.cfg file from iso/boot and run make on it I get the results you see with `make q`.
One thing to note is that grub-mkrescue doesn't need root privs (using sudo) to run properly.
grub-mkrescue won't delete the grub.cfg file so if you don't delete it, it will remain. Are you absolutely sure there is a grub.cfg file in the directory iso/boot/ ? If I remove my grub.cfg file from iso/boot and run make on it I get the results you see with `make q`.
One thing to note is that grub-mkrescue doesn't need root privs (using sudo) to run properly.
Re: Problems with GRUB and QEMU
thank you so much for your help. I feel very stupid because the config file was not correctly names. It was labeled grub.cgf, instead of grub.cfg.