grub-mkrescue not producing bootable image

5,199

Solution 1

As it turns out, this happens when the system you're running this command on has no (accessible) /boot/grub directory. It will silently fail and produce an empty ISO file.

When running the same command on a normal desktop installation of Linux, the command produces a working bootable image.

Solution 2

The following steps produce a working image for me:

  • create a Multiboot hello world main.elf file. GRUB knows how to boot those files (GRUB also knows how to boot the Linux kernel, even though it is not Multiboot)

  • create a iso/boot/grub/grub.cfg file containing:

    menuentry "main" {
        multiboot /boot/main.elf
    }
    

    Place main.elf under iso/boot/

  • On Ubuntu 17.10, on an UEFI machine:

    sudo apt-get install grub-pc-bin
    

    as mentioned at https://wiki.osdev.org/Bare_Bones Otherwise it simply does not work and you have no idea way.

    TODO OMG really?! I have to learn to build GRUB from source to get rid type of this madness.

  • Generate an image and run it:

    grub-mkrescue -o main.img iso
    qemu-system-x86_64 -hda main.img
    

I have posted the exact code for this example at: https://github.com/cirosantilli/x86-bare-metal-examples/tree/d217b180be4220a0b4a453f31275d38e697a99e0/multiboot/hello-world

Share:
5,199

Related videos on Youtube

Overv
Author by

Overv

I'm just a student playing with languages such as Lua, C++ and PHP.

Updated on September 18, 2022

Comments

  • Overv
    Overv almost 2 years

    I'm trying to use the grub-mkrescue command to produce a rescue disk. I invoke it like this:

    grub-mkrescue -o grub.iso
    

    This produces the .iso file, but when I try to boot from it using VirtualBox, it says that the boot medium cannot be read. When I open the file with an archiver, the .iso turns out to have just an empty /boot/grub directory.

    I also noticed some people using the command like this:

    grub-mkrescue -o grub.iso /boot/grub
    

    But then it complains about that directory not existing. (Maybe it is relevant that I'm producing this on a Debian VPS, because I don't have access to an actual Linux PC currently.)

    What could be causing this problem? Is it missing the GRUB files to store into the bootable image or am I using the command the wrong way?

    • Overv
      Overv about 11 years
      Although the occurrence of this problem is quite rare, I think it is beneficial to keep this question with my own answer for Google searches.