views:

2923

answers:

4

I have a laptop hard drive in an external enclosure which I use as a large pendrive. For an added twist, I have installed Linux on it, so I can boot any machine with my distribution of choice (e.g. for data recovery or repairing a b0rked system or just using a borrowed laptop without destroying the preinstalled Windows). The problem is that, depending on the hardware configuration, the USB hard drive may be visible under different paths. For grub configuration I just use (hda0,0) as it is relative to the device the grub was launched from. I have UUID entries in /etc/fstab. I also specify rootwait in the kernel parameters so that it waits for the USB subsystem to settle down before trying to mount the device.

What should I pass to the kernel as root= ? Currently boot from the pendrive once, check the debug messages to see what /dev/sdX device has been assigned to the USB drive by the kernel, then reboot and edit the grub configuration. I can't change anything on the PC besides enabling Boot from USB hard drive in BIOS and setting it to higher priority than internal hard drives.

There are various initrd generating scripts which include support for UUID in root device path, unfortunately the Gentoo native one (genkernel) does not support rootwait and I had no luck trying to use others.

The boot process goes like this (it is quite similar in Windows):

  1. The BIOS chooses the boot device and loads whatever is its MBR (which happens to be grub stage-1).
  2. Grub loads it's configuration and stage-2 files from device it has set as root, using (hd0) for the device it was loaded from by BIOS.
  3. Grub loads and starts a kernel (still the same numbering, so I can use (hd0,0) again ).
  4. Kernel initializes all built-in devices (rootwait does it's magic now).
  5. Kernel mounts the partition it was passed as root (this is a kernel parameter, not grub parameter).
  6. init.d starts the userland booting process, including mounting things from /etc/fstab.

Part 5 is the one giving me problems.

A: 

I could be mistaken or possibly just misunderstanding you, but isn't choice of boot device something that would be configured from the BIOS of the machine you're booting?

I would think it would be a matter of choosing the USB drive, which would have GRUB installed as its bootloader, and then choosing which distro you want to boot from the GRUB menu.

Justin Bennett
A: 

You misunderstood him somehow. But me too :) It is not clear whether he has another MBR where Grub is, but I presume there's an internal drive that is configured to boot from the BIOS, from there he want's to setup the grub configuration to have an entry for an external USB Pendrive/Harddrive/Etc.

Am I correct?

Martín Marconcini
A: 

I think the answer should be to use either root=LABEL=... or root=UUID=...

But you indicate that this doesn't work for you. I would suggest looking into if there is some problem with the actions of your initrd.

matli
I don't have an initrd, that's the whole problem. genkernel does not support "rootwait" option, and other do not work with Gentoo.
skolima
+1  A: 

I once wrote a guide to putting Debian/Xubuntu on a bootable USB drive. It's not quite complete, but fully explains how to set up GRUB: http://tonquil.homeip.net/~dlenski/linux-on-a-stick/

Dan
You use a stock Debian initrd. Gentoo has no such thing, and genkernel is not enough.
skolima