Bootable El-Torito CD with GRUB Legacy: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
m (→‎Make the image from different files and folders: changing folder structure to dotted lists)
m (added source tags + minor fixes)
Line 13: Line 13:
In Ubuntu you can install the required software like this:
In Ubuntu you can install the required software like this:


<source lang="bash">
$ sudo aptitude install genisoimage grub
sudo aptitude install genisoimage grub
</source>


We need a place to store the files on the CD image:
We need a place to store the files on the CD image:


<source lang="bash">
$ cd # Go to your home directory.
cd # Go to your home directory.
$ mkdir -p isofiles/boot/grub
mkdir -p isofiles/boot/grub
</source>


You now created an <tt>isofiles</tt> directory in your home folder and a <tt>boot/grub</tt> sub-folder inside that. We need the stage2 file. It is installed from the grub package. Just copy it:
You now created an <tt>isofiles</tt> directory in your home folder and a <tt>boot/grub</tt> sub-folder inside that. We need the stage2 file. It is installed from the grub package. Just copy it:


<source lang="bash">
$ cp /usr/lib/grub/i386-pc/stage2_eltorito ~/isofiles/boot/grub/
cp /usr/lib/grub/i386-pc/stage2_eltorito ~/isofiles/boot/grub/
</source>


=== Windows ===
=== Windows ===


Look at [[mkisofs#Under windows|this article about how to install and use mkisofs]]. We need a place to store the files on the CD image. Create a folder <tt>isofiles</tt>, which contains the sub-folder <tt>boot\grub</tt> needed by GRUB. We need the stage2 file. You can get it by [http://www.geocities.com/imulgrew/grub_files.tar.gz downloading a package] and unpack it using your favourite unpack application. Find the file <tt>stage2_eltorito</tt> and copy it to <tt>isofiles\boot\grub</tt>.
Look at [[mkisofs#Under windows|this article about how to install and use mkisofs]]. We need a place to store the files on the CD image. Create a folder <tt>isofiles</tt>, which contains the sub-folder <tt>boot\grub</tt> needed by GRUB. We need the stage2 file. You can get it by [http://www.geocities.com/imulgrew/grub_files.tar.gz downloading a package] and unpack it using your favourite unpacking application. Find the file <tt>stage2_eltorito</tt> and copy it to <tt>isofiles\boot\grub</tt>.


== Install a kernel ==
== Install a kernel ==


Get a kernel of your own choosing and copy it to wherever you like inside the <tt>isofiles</tt> folder. Preferably it should be placed in the <tt>boot</tt> sub-folder. Now create a <tt>menu.lst</tt> file. It must be placed in the GRUB folder <tt>boot/grub</tt> and contain something like this:
Get a kernel of your own choosing and copy it to wherever you like inside the <tt>isofiles</tt> folder. Preferably it should be placed in the <tt>boot</tt> sub-folder. Now create a <tt>menu.lst</tt> file. This file controls what menu entries GRUB should provide and how the kernels are booted. It must be placed in the GRUB folder <tt>boot/grub</tt> and contain something like this:


<!-- Not really Bash, it's Grub scripting, but lang="bash" makes nice syntax highlighting. -->
default 0
<source lang="bash">
#timeout 30
default 0
#timeout 30
#title Boot from hard disk

#chainloader (hd0)+1
#title Boot from hard disk
#chainloader (hd0)+1
title My kernel

kernel /boot/kernel-file # Edit it to the filename of your kernel.
title My kernel
kernel /boot/kernel-file # Edit it to the filename of your kernel.
</source>


== Create the .iso image ==
== Create the .iso image ==
Line 45: Line 54:
In the following I use the command <tt>genisoimage</tt>, but you can change it to <tt>mkisofs</tt> if that is what its called on your system. Open a command prompt/terminal and go to where the <tt>isofiles</tt> folder is located. It is your home directory on Ubuntu. Issue the command:
In the following I use the command <tt>genisoimage</tt>, but you can change it to <tt>mkisofs</tt> if that is what its called on your system. Open a command prompt/terminal and go to where the <tt>isofiles</tt> folder is located. It is your home directory on Ubuntu. Issue the command:


<source lang="bash">
genisoimage -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4
genisoimage -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4
-boot-info-table -o bootable.iso isofiles
-boot-info-table -o bootable.iso isofiles
</source>


Now you have a file called <tt>bootable.iso</tt>. Test it using your favourite emulator or burn it to a CD and test on a real computer. I will just explain the command line arguments we used for genisoimage:
Now you have a file called <tt>bootable.iso</tt>. Test it using your favourite emulator or burn it to a CD and test on a real computer. I will just explain the command line arguments we used for genisoimage:


* '''-R''' is using the Rock Ridge protocol, which enables lower-case filenames on the CD.
* '''-R''' is using the Rock Ridge protocol, which enables lower-case filenames on the CD. This is needed by GRUB.
* '''-b''' option takes the filename of the El-Torito boot file (inside the created [[ISO 9660]] file system).
* '''-b''' option takes the filename of the El-Torito boot file (inside the created [[ISO 9660]] file system).
* '''-no-emul-boot''' enables no emulation El-Torito boot.
* '''-no-emul-boot''' enables no emulation El-Torito boot.
* '''-boot-load-size''' option specifies the number of 512-bytes sectors to load. Four 512-byte sectors (2048 bytes) is one CD sector and is the number supported by most BIOS.
* '''-boot-load-size''' option specifies the number of 512-bytes sectors to load. Four 512-byte sectors (2048 bytes) is one CD sector and is the number supported by most BIOS.
* '''-boot-info-table''' patches the El-Torito boot file to contain info about the CD image.
* '''-boot-info-table''' patches the El-Torito boot file to contain info about the CD image. It's needed by GRUB.
* '''-o''' gives the output .iso image filename.
* '''-o''' gives the output .iso image filename.
* Other arguments are the filenames/folders that should be included on the CD. In this case it's only '''isofiles'''.
* Other arguments are the filenames/folders that should be included on the CD. In this case it's only '''isofiles'''.
Line 91: Line 102:
You don't want to copy those files around in order to create the .iso image. Just use the '''-graft-points''' argument, like this:
You don't want to copy those files around in order to create the .iso image. Just use the '''-graft-points''' argument, like this:


<source lang="bash">
genisoimage -graft-points ...other arguments...
genisoimage -graft-points # ...other arguments here...
boot/my-kernel.elf=build/my-kernel.elf
boot/grub/menu.lst=src/grub/menu.lst
boot/my-kernel.elf=build/my-kernel.elf
boot/grub/stage2_eltorito=thirdparty/grub/stage2_eltorito
boot/grub/menu.lst=src/grub/menu.lst
modules/=build/modules/
boot/grub/stage2_eltorito=thirdparty/grub/stage2_eltorito
modules/=build/modules/
</source>


You can use both files and folders together with the -graft-points argument.
You can use both files and folders together with the -graft-points argument.
Line 107: Line 120:
The output of genisoimage looks like this:
The output of genisoimage looks like this:


<pre>
Size of boot image is 4 sectors -> No emulation
Size of boot image is 4 sectors -> No emulation
genisoimage: Permission denied. Error opening boot image file 'isofiles/boot/grub/stage2_eltorito' for update.
genisoimage: Permission denied. Error opening boot image file 'isofiles/boot/grub/stage2_eltorito' for update.
</pre>


The problem is that you use the -boot-info-table command line argument that patches the boot file to include information about the CD, but the boot file is not writable by genisoimage. The solution is to make it writable, like this:
The problem is that the -boot-info-table command line argument patches the boot file to include information about the CD, but the boot file is not writable by genisoimage. GRUB needs the boot file to be patched in order to access the CD properly. The solution is to make it writable, like this:


<source lang="bash">
$ chown myself isofiles/boot/grub/stage2_eltorito # Make sure you are the owner of the file. Replace "myself"
chown myself isofiles/boot/grub/stage2_eltorito # Make sure you are the owner of the file. Replace "myself"
# with your username. Maybe you need to use sudo.
# with your username. Maybe you need to use sudo.
$ chmod u+w isofiles/boot/grub/stage2_eltorito # Make the file writable for the owner of the file (you).
chmod u+w isofiles/boot/grub/stage2_eltorito # Make the file writable for the owner of the file (you).
</source>


== See Also ==
== See Also ==

Revision as of 15:28, 13 May 2009

Difficulty level

Beginner

This tutorial guides you through making a bootable CD .iso image with GRUB Legacy. We are going to create an El-Torito "no-emulation" bootable CD, which is different from a bootable CD emulating a floppy disc.

Requirements

You will need the following:

  • mkisofs, which is in fact superseeded by genisoimage.
  • A (Multiboot compliant) kernel that GRUB can boot.
  • The El-Torito GRUB Legacy stage2 file, called stage2_eltorito.

Ubuntu

In Ubuntu you can install the required software like this:

sudo aptitude install genisoimage grub

We need a place to store the files on the CD image:

cd                            # Go to your home directory.
mkdir -p isofiles/boot/grub

You now created an isofiles directory in your home folder and a boot/grub sub-folder inside that. We need the stage2 file. It is installed from the grub package. Just copy it:

cp /usr/lib/grub/i386-pc/stage2_eltorito  ~/isofiles/boot/grub/

Windows

Look at this article about how to install and use mkisofs. We need a place to store the files on the CD image. Create a folder isofiles, which contains the sub-folder boot\grub needed by GRUB. We need the stage2 file. You can get it by downloading a package and unpack it using your favourite unpacking application. Find the file stage2_eltorito and copy it to isofiles\boot\grub.

Install a kernel

Get a kernel of your own choosing and copy it to wherever you like inside the isofiles folder. Preferably it should be placed in the boot sub-folder. Now create a menu.lst file. This file controls what menu entries GRUB should provide and how the kernels are booted. It must be placed in the GRUB folder boot/grub and contain something like this:

default 0
#timeout 30

#title Boot from hard disk
#chainloader (hd0)+1

title My kernel
kernel /boot/kernel-file    # Edit it to the filename of your kernel.

Create the .iso image

In the following I use the command genisoimage, but you can change it to mkisofs if that is what its called on your system. Open a command prompt/terminal and go to where the isofiles folder is located. It is your home directory on Ubuntu. Issue the command:

genisoimage -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4
            -boot-info-table -o bootable.iso isofiles

Now you have a file called bootable.iso. Test it using your favourite emulator or burn it to a CD and test on a real computer. I will just explain the command line arguments we used for genisoimage:

  • -R is using the Rock Ridge protocol, which enables lower-case filenames on the CD. This is needed by GRUB.
  • -b option takes the filename of the El-Torito boot file (inside the created ISO 9660 file system).
  • -no-emul-boot enables no emulation El-Torito boot.
  • -boot-load-size option specifies the number of 512-bytes sectors to load. Four 512-byte sectors (2048 bytes) is one CD sector and is the number supported by most BIOS.
  • -boot-info-table patches the El-Torito boot file to contain info about the CD image. It's needed by GRUB.
  • -o gives the output .iso image filename.
  • Other arguments are the filenames/folders that should be included on the CD. In this case it's only isofiles.

Advanced stuff

Give it a label

You want to label your CD image, so you can later recognize it when loading your CD. Just pass a -A command line argument to genisoimage followed by the name you want.

Make it be quiet

Some day you probably want to create an .iso image directly in your Makefile. If you don't like the output that genisoimage creates, just pass the command line argument -quiet.

Sometimes you get a warning about the input character set used. If that is a problem just pass the argument -input-charset ascii (or utf8 if that is what you use on your filesystem).

Make the image from different files and folders

When you are building your kernel the parts on the .iso image could be located at different paths. Imagine your project files are like this:

  • project/
    • Makefile
    • build/
      • my-kernel.elf
      • modules/
        • iso9660.mod
        • kbdrv.mod
    • src/
      • grub/
        • menu.lst
      • ...
    • thirdparty/
      • grub/
        • stage2_eltorito

You don't want to copy those files around in order to create the .iso image. Just use the -graft-points argument, like this:

genisoimage -graft-points # ...other arguments here...
            boot/my-kernel.elf=build/my-kernel.elf
            boot/grub/menu.lst=src/grub/menu.lst
            boot/grub/stage2_eltorito=thirdparty/grub/stage2_eltorito
            modules/=build/modules/

You can use both files and folders together with the -graft-points argument.

Solving problems

If you don't find a solution to your problem below, please ask in the forums.

I get a permission denied error

The output of genisoimage looks like this:

Size of boot image is 4 sectors -> No emulation
genisoimage: Permission denied. Error opening boot image file 'isofiles/boot/grub/stage2_eltorito' for update.

The problem is that the -boot-info-table command line argument patches the boot file to include information about the CD, but the boot file is not writable by genisoimage. GRUB needs the boot file to be patched in order to access the CD properly. The solution is to make it writable, like this:

chown myself isofiles/boot/grub/stage2_eltorito    # Make sure you are the owner of the file. Replace "myself"
                                                   # with your username. Maybe you need to use sudo.
chmod u+w isofiles/boot/grub/stage2_eltorito       # Make the file writable for the owner of the file (you).

See Also

Articles

External Links