Booting Linux userland from an External USB Flash Disk

For a long time, it’s been possible to boot Linux from an external drive such as USB flash, without requiring an initrd (initial ramdisk). You can do this with the “root=/dev/sda1” kernel parameter, where sda1 is the partition on the USB flash device containing your userspace (may vary depending on your partitioning setup and if you have SCSI or SATA devices).

(Whether or not your BIOS can boot from USB or if you have to store the bootloader and kernel on a more common boot medium is another story)

As of Linux 2.6.10, the USB flash storage initialization changed, and a side effect of this made it no longer possible to boot Linux from USB flash like this. The change meant that, in situations like this, the kernel would try to mount the root filesystem (on the USB flash disk) before the usb-storage driver was fully initialized.

Users saw errors on bootup along the lines of:

VFS: Cannot open root device 'sda1' or unknown-block(8,1)
Please append a correct 'root=' boot option
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(8,1)

Reverting this change was not an option (it was justified) so we had to find an alternative way to solve this problem.

After a few discussions, we decided that at this point in time there was no safe and elegant solution to the problem, so we had to go for a more simplistic approach. I wrote a patch which was accepted into Linux 2.6.11.

My patch added a rootdelay kernel parameter, which allows the user to specify a delay (in seconds) that the kernel should wait before trying to mount the root device. Since the kernel performs tasks in parallel, the usb-storage driver will continue initializing while the block layer is waiting for the specified delay, thus correcting the sequence of events.

So, to overcome this problem, you might use a grub configuration section such as:

title=My kernel which boots userland from a USB flash disk
root (hd0,0)
kernel /bzImage-2.6.14 root=/dev/sda1 rootdelay=10

Most users will be able to get away with a shorter delay (try 5 seconds), but some flash devices will require a longer delay.

This is a relatively minor feature, the change occurred a fair while ago, and the parameter is documented in Documentation/kernel-parameters.txt, but I’m still seeing a fair few people running into this problem. Hopefully this post will make the solution easier to find, until a more transparent solution is developed.

15 thoughts on “Booting Linux userland from an External USB Flash Disk

  1. Chewi

    Could you not just make an option that tells it to wait until the partition (on whatever medium) becomes available?

  2. dsd Post author

    It’s not simple to implement that, but is probably the safest approach. I was contacted with someone who had a patch along these lines, and I asked him to send it upstream, but I don’t think that ever happened. I may dig it up and chase it myself.

  3. Wes

    Thanks a ton. This worked like a charm. Had seen other posts for kernel patches, but an additional grub option is much cleaner and easier to me.

  4. gilmore

    I obtain the same error trying the boot of redhat (kernel from connected external hard disk usb 2,0 to pcmcia card usb 2,0 on laptop. I have not understood like making to implement yours patch in order to insert the rootdelay. if I can have of the preciser detailed lists on like adding the patch. thanks. gilmore

  5. Dan Philpott

    This piece of your past helped me quickly realize what the problem in my configuration was. Thank you for saving me from a bout of frustration by taking the time to document this problem and it’s solution.

    It really is the little things that make a big difference to us end users.

  6. Dan Elharrar

    And still, this post continues to serve the people in 2008.
    I installed LFS-6.3 with kernel 2.6.22 on a USB stick, and couldn’t get it to work until I saw this pearl.
    Thank you so much!

  7. joe dai

    Dsd, thanks for your post that helps me to understand this issue. Unfortunately boot up delay is still problem to me as I’m told to reduce it. I’m wondering whether there is solution now on 2.6.18? I see other people says ( other solution. thanks for your reply.

  8. Torsten

    Thanks very much for this post. This really solved my issues with booting from my usb stick.

  9. Pingback: HOWTO: Install Debian (Linux) on USB flash memory, USB flash drives, USB jump drives | Organizing Linux information....

  10. Allan Arguelles

    Thank you very much! I’ve been stuck with this problem for a few hours now, this did the trick!

  11. Pingback: OSSIM : Volume Group Not Found Problem « My Ideas, Thoughts, Hacks, Bookmarks

Comments are closed.