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.
Post Reply
User avatar
MrLuck
Posts: 4
Joined: Thu Jul 31, 2025 3:55 pm
Libera.chat IRC: MrLuck

Problems with GRUB and QEMU

Post by MrLuck »

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.
Screenshot 2025-07-31 181247.png
Screenshot 2025-07-31 181247.png (11.53 KiB) Viewed 35604 times
Screenshot 2025-07-31 181259.png
Screenshot 2025-07-31 181259.png (9.47 KiB) Viewed 35604 times
The code is exactly the same as the Bare Bones tutorial, with compilations through a Makefile listed here:

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 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.
Octocontrabass
Member
Member
Posts: 6245
Joined: Mon Mar 25, 2013 7:01 pm

Re: Problems with GRUB and QEMU

Post by Octocontrabass »

Where is your grub.cfg?
User avatar
MrLuck
Posts: 4
Joined: Thu Jul 31, 2025 3:55 pm
Libera.chat IRC: MrLuck

Re: Problems with GRUB and QEMU

Post by MrLuck »

The cfg file is iso/boot/grub/grub.cfg
MichaelPetch
Member
Member
Posts: 857
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Problems with GRUB and QEMU

Post by MichaelPetch »

MrLuck wrote: Fri Aug 01, 2025 6:40 am The cfg file is iso/boot/grub/grub.cfg
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?
User avatar
MrLuck
Posts: 4
Joined: Thu Jul 31, 2025 3:55 pm
Libera.chat IRC: MrLuck

Re: Problems with GRUB and QEMU

Post by MrLuck »

grub.cfg

Code: Select all

menuentry "myos" {
	multiboot /boot/myos.bin
}
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
MichaelPetch
Member
Member
Posts: 857
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.
User avatar
MrLuck
Posts: 4
Joined: Thu Jul 31, 2025 3:55 pm
Libera.chat IRC: MrLuck

Re: Problems with GRUB and QEMU

Post by MrLuck »

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.
Post Reply