Grub is the most common bootloader. Starting with squeeze, grub2 is the default.

For testing the bootloader on external drives, you can use kvm (unmount it first, otherwise I've found it won't sync even if you tell it to):

kvm -hda /dev/sdb

Grub 2

Install on a USB drive

sudo grub-install --root-directory /media/sdb1/ /dev/sdb

Grub 2 config file

/boot/grub/grub.cfg

Some sample menu entries:

set root=(hd0,1)

set menu_color_normal=cyan/blue
set menu_color_highlight=white/blue

menuentry "Debian live, 505 i386" {
        linux   /boot/debian-live-505-i386/vmlinuz boot=live union=aufs live-media-path=boot/debian-live-505-i386
        initrd  /boot/debian-live-505-i386/initrd.img
}

menuentry "Ubuntu 10.04 Lucid amd64" {
        linux   /boot/ubuntu-lucid-10.04-amd64/linux
        initrd  /boot/ubuntu-lucid-10.04-amd64/initrd.gz
}

menuentry "Squeeze install, i386, netboot, 2010-09-12" {
        linux   /boot/squeeze-i386/linux
        initrd  /boot/squeeze-i386/initrd.gz
}

menuentry "Ramanujan boot" {
        insmod lvm
        insmod raid
        set root=(ramanujan-root)
        linux   /boot/vmlinuz-2.6.32-5-amd64 root=/dev/mapper/ramanujan-root ro
        initrd  /boot/initrd.img-2.6.32-5-amd64
}

Utilities

Other

Grub 1

Install on a USB drive

Copy files over

I make a /boot/grub directory on the drive. You should copy stage1, stage2, menu.lst, and optionally one or more filesystem_stage1_5. stage2 is the most important part, since that has the core grub menu and booting things. stage1 contains the bootloader that goes into the MBR. The stage1.5's are useful to allow the stage1 to read filesystems to find the stage2 in case the exact blocks on disk change.

The easiest way, if everything works properly, is to enter the grub shell (sudo grub) and run

setup (hd1) (hd1,0)

Look at the documentation for the setup command. Make sure you use the proper (hd1) device - try tab completing with the cat command to check files on the device, to make sure it is correct`

things below this point hasn't been revised recently

Here is how I installed grup bot my usb disk. This is a file I found I had stored away, I haven't tested it in a while. Note that whenever I've done this, it's been complicated and required reading of help files and I can't generalize it to fit everyone right now.

grub> install --stage2=/mnt/usb-dev/boot/grub-stage2.img  --force-lba (hd1,0)/boot/grub-stage1.img  (hd1) (hd1,0)/boot/grub-stage2.img p (hd1,0)/boot/menu.lst

Here is another install command, from a menu.lst. Not sure which is best to use...

install (hd0,0)/boot/grub-stage1.img (hd0) (hd0,0)/boot/grub/grub-stage2.img (hd0,0)/boot/menu.lst

mkdir /media/sda1/boot
cp -r /boot/grub/ /media/sda1/boot/

sudo grub
grub> root (hd1)   # whatever yours is -- check!
grub> setup (hd1)

# you could use the install command to be more flexible...

Reinstall on a computer

root (hd1,4)    # this is the partition that contains /boot/* (or the boot partition- whatever contains the files to embed)
setup (hd1)     # This is the partition to enbed into

Output from a `setup` command

This may be useful for reference for someone...

grub> root (hd1,0)     
 Filesystem type is fat, partition type 0x6

grub> setup (hd1)
 Checking if "/boot/grub/stage1" exists... yes
 Checking if "/boot/grub/stage2" exists... yes
 Checking if "/boot/grub/fat_stage1_5" exists... yes
 Running "embed /boot/grub/fat_stage1_5 (hd1)"...  17 sectors are embedded.
succeeded
 Running "install /boot/grub/stage1 (hd1) (hd1)1+17 p (hd1,0)/boot/grub/stage2
/boot/grub/menu.lst"... succeeded
Done.

DebianNotes/Grub (last edited 2011-04-24 02:05:56 by RichardDarst)