Page 1 of 1

grub-mkrescue not producing correctly bootable image

Posted: Mon Jun 03, 2013 3:20 am
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?

Re: grub-mkrescue not producing correctly bootable image

Posted: Mon Jun 03, 2013 3:49 am
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?

Re: grub-mkrescue not producing correctly bootable image

Posted: Mon Jun 03, 2013 5:18 am
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

Re: grub-mkrescue not producing correctly bootable image

Posted: Mon Jun 03, 2013 5:34 am
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.

Re: grub-mkrescue not producing correctly bootable image

Posted: Tue Jun 04, 2013 5:46 am
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.

Re: grub-mkrescue not producing correctly bootable image

Posted: Tue Jun 04, 2013 8:01 am
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

Re: grub-mkrescue not producing correctly bootable image

Posted: Thu Jun 06, 2013 6:53 pm
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").

Re: grub-mkrescue not producing correctly bootable image

Posted: Thu Jun 06, 2013 11:42 pm
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.