Booting Gentoo from USB Hard Disk

I installed my Gentoo on my internal hard disk. Due to mobility I think about moving my system to a portable USB hard disk. The first idea was to use an initial ram disk image to load the USB drivers and load the main system. I read some things about creating an inital ram disk image (initrd) by using mkinitrd and come to the end, that there has to be a solution which is more easier than using an initrd.

The main problem when booting from USB is the following: First of all, the BIOS is setting up its USB drivers to load the kernel into the RAM. After this step, the BIOS makes the kernel booting. When the kernel is booting, it unloads the BIOS USB drivers to load the kernel specific USB drivers. There is some time between unload the BIOS drivers and loading the kernel drivers where no USB driver is active – without an USB driver, the kernel cannot access the root filesystem and panics.

The solution is to delay the kernel boot process until the kernel USB drivers are loaded and the kernel can access the root filesystem. I found the rootdelay boot parameter in my current kernel documentation:

 rootdelay = [KNL] Delay (in seconds) to pause before attempting
 to mount the root filesystem

So booting your linux distribution from an USB disk is quiet easy:

  • Just append the rootdelay parameter to your boot loader configuration (in my case, this is grub):

    $ cat /boot/grub/grub.cfg
    # 2.6.22-suspend2-r1
    title 2.6.22-suspend2-r1
    root (hd0,1)
    kernel /boot/vmlinuz-2.6.22-suspend2-r1 root=/dev/sdb2 video=vesafb-tng:mtrr,ywrap resume2=swap:/dev/sdb5 rootdelay=5

  • When you boot your system from USB, you have to think about changing device names. If your device was at /dev/hda, the USB device will be at /dev/sda. So you have to figure out your USB device name, adjust the fstab configuration and the root kernel parameter in your grub configuration.
  • Finally you have to make sure, that you build-in the needed USB drivers into your kernel. So I set the following options in my kernel configuration:
    Device Drivers  --->
         USB support  --->
              < *> Support for Host-side USB
               [*]   USB device filesystem
              < *>   EHCI HCD (USB 2.0) support
               [*]     Full speed ISO transactions (EXPERIMENTAL)
               [*]     Root Hub Transaction Translators (EXPERIMENTAL)
               [*]     Improved Transaction Translator scheduling (EXPERIMENTAL)
              < *>   UHCI HCD (most Intel and VIA) support
              < *> USB Mass Storage support
  • It depends on your architecture whether you have to build-in EHCI, OHCI or UHCI. Just use lspci to detect you requirements. In my case I got the following output:

    $ lspci | grep -i UHCI
    00:1d.0 USB Controller: Intel Corporation 82801G (ICH7 Family) USB UHCI #1 (rev 01)
    00:1d.1 USB Controller: Intel Corporation 82801G (ICH7 Family) USB UHCI #2 (rev 01)
    00:1d.2 USB Controller: Intel Corporation 82801G (ICH7 Family) USB UHCI #3 (rev 01)
    00:1d.3 USB Controller: Intel Corporation 82801G (ICH7 Family) USB UHCI #4 (rev 01)
    ws1 linux # lspci | grep -i OHCI
    ws1 linux # lspci | grep -i EHCI
    00:1d.7 USB Controller: Intel Corporation 82801G (ICH7 Family) USB2 EHCI Controller (rev 01)
    ws1 linux #

Leave a Reply

You must be logged in to post a comment.