grub-mkrescue not producing correctly bootable image

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
Overv
Posts: 2
Joined: Mon Jun 03, 2013 3:07 am

grub-mkrescue not producing correctly bootable image

Post by Overv »

Hi,

I have some simple kernel code that just writes hello world to the VGA memory in text mode right now.
I'm not interested in writing my own bootloader, so I decided to use GRUB.

I compile and link my kernel like this (it's only x86 assembly, no C):

Code: Select all

nasm -felf hellokernel.asm -o hellokernel.o
ld -T link.ld -o hellokernel.bin hellokernel.o
I followed the bare bones guide to make the binary bootable. I created the following file structure:

Code: Select all

iso
---boot
------grub
---------grub.cfg
------hellokernel.bin
The configuration looks like this:

Code: Select all

menuentry "hellokernel" {
    multiboot /boot/hellokernel.bin
}
I used the following command to produce my .iso file:

Code: Select all

grub-mkrescue -o hellokernel.iso iso
I then created a new VirtualBox virtual machine without a hard drive and mounted the .iso file as CD/DVD drive. Unfortunately I get the following output:

Code: Select all

FATAL: Could not read from the boot medium! System halted.
So I inspected the contents of the file by extracting it and only found the file structure shown above. It seems that GRUB is not even included in the output file! What could be causing this?
Overv
Posts: 2
Joined: Mon Jun 03, 2013 3:07 am

Re: grub-mkrescue not producing correctly bootable image

Post by Overv »

Turns out it's because 'grub-mkrescue' silently fails when there is no /boot/grub directory. This problem occured on the Debian VPS I was compiling on, but when running it on a normal Ubuntu install, it works fine.

It's not really a problem, but is there a way to manually install these required files or is there an equivalent command that isn't specifically designed to produce a rescue file for the local OS?
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: grub-mkrescue not producing correctly bootable image

Post by xenos »

Instead of using grub-mkrescue you could also try this:

http://wiki.osdev.org/Bootable_El-Torit ... RUB_Legacy

It also works with GRUB 2 - in that case replace the stage2_eltorito with a GRUB image built with grub-mkimage, as shown in the floppy (!) section here:

http://wiki.osdev.org/GRUB_2
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: grub-mkrescue not producing correctly bootable image

Post by sortie »

I recommend that you simple download the latest GRUB release and build it from source and install it somewhere convenient (such as --prefix=/usr/local/grub) and add that location to PATH. The needed boot files should be installed there so you can grub-mkrescue as far a I know. Otherwise check the command line options to grub-mkrescue as it allows you to use boot files from another location.
User avatar
darkinsanity
Member
Member
Posts: 45
Joined: Wed Sep 17, 2008 3:59 am
Location: Germany

Re: grub-mkrescue not producing correctly bootable image

Post by darkinsanity »

Overv wrote:Turns out it's because 'grub-mkrescue' silently fails when there is no /boot/grub directory. This problem occured on the Debian VPS I was compiling on, but when running it on a normal Ubuntu install, it works fine.
or is there an equivalent command that isn't specifically designed to produce a rescue file for the local OS?
I'm using this script to create an ISO-image with GRUB 2 on it and it worked fine on all systems I tried (Ubuntu, Debian 7, Arch). I don't know if it works when /boot/grub is missing, though.
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: grub-mkrescue not producing correctly bootable image

Post by xenos »

darkinsanity wrote:I'm using this script to create an ISO-image with GRUB 2 on it and it worked fine on all systems I tried (Ubuntu, Debian 7, Arch). I don't know if it works when /boot/grub is missing, though.
Well, this part of the script relies on /boot/grub (or in this case actually /grub, because of the -p switch) to exist, because it looks for the GRUB2 modules in that directory, from which it builds the GRUB2 image:

Code: Select all

grub-mkimage -p /grub -o core.img -O i386-pc biosdisk iso9660 multiboot configfile
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
darkinsanity
Member
Member
Posts: 45
Joined: Wed Sep 17, 2008 3:59 am
Location: Germany

Re: grub-mkrescue not producing correctly bootable image

Post by darkinsanity »

XenOS wrote:Well, this part of the script relies on /boot/grub (or in this case actually /grub, because of the -p switch) to exist, because it looks for the GRUB2 modules in that directory, from which it builds the GRUB2 image:

Code: Select all

grub-mkimage -p /grub -o core.img -O i386-pc biosdisk iso9660 multiboot configfile
The -p doesn't tell grub to search for the modules in that directory (that would be -d), it sets the prefix for the ISO-Image because boot.img and grub.cfg will be located in the grub-directory of the image. Also I have tried out the script a few minutes ago while there was no /boot/grub and it still worked, so I guess that grub-mkimage takes the modules from /usr/lib/grub/i386-pc (just like it says when you execute "grub-mkimage --help").
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: grub-mkrescue not producing correctly bootable image

Post by xenos »

Yes, indeed - I was confusing the -d and -p switches... Actually I'm using a quite similar script to create a bootable CD image.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
Post Reply