972
edits
[unchecked revision] | [unchecked revision] |
m (→Make the image from different files and folders: tree structure) |
m (Bot: Replace deprecated source tag with syntaxhighlight) |
||
(22 intermediate revisions by 11 users not shown) | |||
Line 1:
{{Rating|1}}
This tutorial guides you through making a bootable CD .iso image with GRUB Legacy. We are going to create
== Requirements ==
Line 6:
You will need the following:
* [[mkisofs]], which is in fact superseeded by [[genisoimage]].
* A (Multiboot compliant) kernel that [[GRUB Legacy]] can boot.
* The El-Torito GRUB Legacy stage2 file, called <tt>stage2_eltorito</tt>.
=== Ubuntu/Debian ===
In Ubuntu or Debian you can install the required software like this:
<syntaxhighlight lang="bash">
sudo apt-get install genisoimage grub
</syntaxhighlight>
We need a place to store the files on the CD image:
<syntaxhighlight lang="bash">
cd # Go to your home directory.
mkdir -p isofiles/boot/grub
</syntaxhighlight>
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:
<syntaxhighlight lang="bash">
cp /usr/lib/grub/i386-pc/stage2_eltorito ~/isofiles/boot/grub/
</syntaxhighlight>
=== 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
== 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. 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. -->
<syntaxhighlight lang="bash">
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.
</syntaxhighlight>
In GRUB there's a concept called root. It's the disk drive or partition where you access the files, like the kernel image and modules. When booting from CD using <tt>stage2_eltorito</tt> you don't need to set the root as it is already set to "<tt>(cd)</tt>".
== Create the .iso image ==
Line 45 ⟶ 56:
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:
<syntaxhighlight lang="bash">
genisoimage -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4
-boot-info-table -o bootable.iso isofiles
</syntaxhighlight>
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:
{| {{Wikitable}}
|-
| -R
| Use the Rock Ridge protocol, which enables lower-case filenames on the CD. This is needed by GRUB.
|-
| -b ''file''
| The file to boot (the filename is in the created [[ISO 9660]] file system).
|-
| -no-emul-boot
| Enables no emulation El-Torito boot.
|-
| -boot-load-size 4
| 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 boot file to contain info about the CD image. It's needed by GRUB.
|-
| -o bootable.iso
| The filename of the resulting .iso image.
|-
| isofiles
| Other arguments are the files and folders that should be included on the CD. In this case it's only the content of ''isofiles''.
|}
== Advanced stuff ==
Line 61 ⟶ 91:
=== Give it a label ===
You want to label your CD image, so you can later recognize it when loading your CD. Just pass a '''-
=== Make it be quiet ===
Line 71 ⟶ 101:
=== 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.
<!-- Fancy Unicode/ascii art tree. Created in Ubuntu command line: "tree -A -F --dirsfirst" -->
<pre>
project/
├── build/
│ ├── modules/
│ │ ├── iso9660.mod
│ │ └── kbdrv.mod
│ └── my-kernel.elf
├── src/
│ ├── grub/
│ │ └── menu.lst
│ └── ...
├── thirdparty/
│ └── grub/
│ └── stage2_eltorito
└── Makefile
</pre>
You don't want to copy those files around in order to create the .iso image. Just use the '''-graft-points''' argument, like this:
<syntaxhighlight lang="bash">
genisoimage -graft-points # ...other arguments here...
boot/grub/stage2_eltorito=thirdparty/grub/stage2_eltorito
modules/=build/modules/
</syntaxhighlight>
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 [http://forum.osdev.org/ the forums].
=== mkisofs says Uh oh, I cant find the boot image ===
The output of mkisofs looks like this:
<pre>
mkisofs: Uh oh, I cant find the boot image 'isofiles/boot/grub/stage2_eltorito' !
</pre>
This problem arises because mkisofs/genisoimage looks for its boot image as a subdirectory of the filesystem on the CD; make sure that the path you specify starts with 'boot/' rather than the name of your ISO directory ('isofiles/' in this example).
Source: [[topic:20102|this thread]]
=== I get a permission denied error in Linux ===
The output of genisoimage looks like this:
<pre>
Size of boot image is 4 sectors -> No emulation
genisoimage: Permission denied. Error opening boot image file 'isofiles/boot/grub/stage2_eltorito' for update.
</pre>
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:
<syntaxhighlight lang="bash">
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).
</syntaxhighlight>
== See Also ==
=== Articles ===
* [[mkisofs]]
* [[Bootable CD]] - using floppy disk emulation
* [[GRUB]] - for info on using GRUB 2 to make a bootable CD with modern GRUB
=== Forum ===
* [[topic:19050|Thread about making your own .iso image from scratch without tools]]
=== External Links ===
* [http://www.geocities.com/imulgrew/grub_files.tar.gz Package containing the GRUB stages] (including <tt>stage2_eltorito</tt>)
* [ftp://alpha.gnu.org/gnu/grub/grub-0.97.tar.gz Source for GRUB Legacy] to build it yourself
[[Category:Tutorials]]
[[Category:Bootloaders]]
[[Category:GRUB]]
|