[NTLUG:Discuss] GRUB and USB drives.

Robert Citek robert.citek at gmail.com
Mon Sep 10 00:53:42 CDT 2007


On 09/09/2007 10:28 PM, Steve Baker wrote:
> I can't figure out what to tell GRUB to make it install a boot loader
> onto the USB drive that'll boot from the USB drive.  I can boot from a 
> SuSE Live-CD and run grub - but I can't figure out what to tell it.
> 
> The USB drive mounts as /dev/sda1  (system partition) and /dev/sda3
> (user partition).  Both are formatted 'Linux Native'.  The "must not 
> touch" hard drive is /dev/hda
> 
> Help!  Thanks!

This is possible to do.  In fact, I do this quite regularly, except with 
Debian and Ubuntu.  Here's how I do it:

1) use labels.  Instead of using /dev/sd* or /dev/hd*, use LABEL= in the 
files /etc/fstab and /boot/grub/menu.lst on the USB drive.  Here's an 
example from my fstab:

LABEL=foo  /  ext3  defaults,errors=remount-ro  0  1

and from my /boot/grob/menu.lst:

kernel /boot/vmlinuz-2.6.20-16-generic root=LABEL=foo ro quiet splash

You can label your filesystems with e2label or reiserfstune.

2) to install grub, boot from an install CD, mount the filesystem 
containing /boot, and then run grub-install.  For example, let's say 
your USB device is /dev/sda and /dev/sda1 is root with /boot/grub:

mkdir -p /tmp/foo
mount /dev/sda1 /tmp/foo
grub-install --root-directory=/tmp/foo /dev/sda

If you have a separate partition for /boot (e.g. /dev/sda2), then mount it:

mkdir -p /tmp/foo/boot
mount /dev/sda2 /tmp/foo/boot
grub-install --root-directory=/tmp/foo /dev/sda

This will install the grub boot loader in MBR of /dev/sda.  All that's 
left is to reboot without the CD and with the USB drive plugged in.

Good luck and let us know how things go.

Regards,
- Robert




More information about the Discuss mailing list