Friday, July 22, 2005

Installing grub on removable media

Grub is a really nifty boot loader. I especially love two things about it:
  • A command-line interface
  • No reinstallation for kernel changes
Even if the OS boot loader gets knackered, you can probably restore it if you have a grub floppy.

Installing grub on a floppy
Here's how to get grub on a floppy:
  • Kiss the prior contents of the floppy goodbye ;-)
  • Change to the directory /usr/share/grub/i386-redhat (on fedora) or /usr/lib/grub (on Suse) or /usr/share/grub/i386-pc if you built and installed grub yourself
  • Execute the commands:
    dd if=stage1 of=/dev/fd0 bs=512 count=1
    dd if=stage2 of=/dev/fd0 bs=512 seek=1
You ought to be able to get a grub prompt on booting with this disk.

Here's another way to do the same thing - not so destructively
  • Mount a ext2-formatted floppy to say /mnt/floppy
  • Copy the contents of the /usr/share/grub/i386*/{stage1,stage2,e2fs_stage1_5} to /mnt/floppy/boot/
  • Optionally create a /mnt/floppy/boot/menu.lst
  • Execute grub-install --root-directory=/mnt/floppy fd0
  • Umount the floppy
If you dont have grub-install, or are paranoid about using it, there's yet another way - boot into a grub prompt either using a floppy created using the destructive way outlined above, or on some machine with grub installed on the hard disk. Drop to a grub prompt. Then place the ext2 floppy in the drive and execute:
root (fd0)
setup (fd0)
You ought to have a grub-bootable on your hands now. I think the grub-install part ought to work with USB drives as well tho' I haven't really tried it.

Installing grub on a CD
  • mkdir -p iso/boot/grub
  • cp /usr/share/grub/i386-*/stage2_eltorito iso/boot/grub
  • Optionally create a iso/boot/grub/menu.lst.
  • Create an iso image:
    mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot \
    -boot-load-size 4 -boot-info-table -o grub.iso iso
  • Burn the grub.iso image to cd.
Hopefully if all goes right, you have a bootable grub CD. Of course, try this with rewriteable CDs if you *really* need to be sure :)

No comments: