Slashdot Mirror


Booting from USB Drives?

GilesP asks: "With so many USB flash drives around (like the pendrive, Targus Go-Anywhere, and others), and with the demise of the floppy disk, I began to wonder if it would be possible to boot from a USB drive? So your BIOS is going to need to support booting from a USB device, but what else would be involved? I'm primarily thinking about Linux here, but other OSes would be interesting too. These devices come in a range of sizes from 8Mb up to 1Gb, so there is plenty of room to hold a Linux installation. Has anybody done anything like this?"

17 of 49 comments (clear)

  1. booting from pendrive by xFallenAngel · · Score: 2, Interesting

    All you need to do is to tell your bios to boot
    from USB, as long as your bios allows this.

    Then just install a system on the pendrive,
    kernel and all, usb support compiled in.
    That should be sufficient. rdev/lilo as needed

    -Fallen

    1. Re:booting from pendrive by GoRK · · Score: 5, Informative

      Ehrm, no.

      OK, here is the real answer.

      Some pc BIOS can boot off of an ATAPI device hooked to USB, such as an Iomega Zip drive or a compact flash card or somesuch; however, the implementations vary WILDLY on how this is accomplished. Booting from said devices involves much fakery in what is usually presented to a bootloader as either a virtual floppy drive or a virtual hard disk. The fakery involved in booting from USB is even more complicated than booting from a CD-ROM, for which there is (at least) a standard that most bioses somewhat support.

      Your bootloader (lilo, grub, etc.) can indeed bootstrap the kernel from a USB connected boot media; however, you will have to configure it differently based on which kind of device (floppy or HDD) your bios simulates for a USB boot. IE if your bios simulates a floppy drive, you'll have to tell lilo/grub/etc to load the kernel from the bios's floppy drive (here, bios calls to the floppy drive are rerouted to the usb device). Incedentally, this is the way CD-ROM booting works, but CD-ROM booting is MUCH simpler since an image file in a special area of the CD-ROM sits in for the virtual drive.

      Anyway, most USB booting bioses are going to be simulating hard drives anyway due to the size of most usb media, so all you have to do is set up lilo to boot from the first bios hdd (ie 0x80) and you're set there.

      Now on the subject of actually bringing the OS up - well that is the fun part. You can not (as the parent post said) just have "usb support compiled in" to make linux boot. USB doesnt exactly work that way in Linux. You can indeed have your usb controller driver, the usb mass storage driver, etc. all compiled statically with the kernel (not modules), but you're still going to have to start the hotplug daemon to get the setup functional to where you can use the connected device, and that's not going to happen without a root filesystem.

      So, you need an initrd. No problem provided you can get lilo or grub or whateverelse to find and load it. All your initrd needs to do is to load up your USB modules, mount your root fs off of usb mass storage (/dev/sda1 or whatever weird devfs name you use) and then pivot_root over to it. This is mostly equivalent to an initrd setup for something like a network booting system that uses NFS root or fibre channel or something like that. Any initrd HOWTO will cover setting up an initrd that loads modules and performs configuration to mount the root device that the kernel cannot do on its own.

      Sorry for the long ramble. Booting linux from USB is possible; however, it is not for the faint of heart. If you get it to work, it will probably not work for every motherboard that claims to allow usb booting. Any modern version of Windows will most not boot this way. (Well, technically you could load windows 3.11 or earlier in real mode like this, and maybe even windows 95/98 in safe mode)

      FYI, a good place to start looking is the HOWTO's that involve installing linux onto subnotebooks without internal CDROM or Floppy. A lot of these sites provide floppy images that can boostrap an installation system (ie linux) from a USB connected floppy or cdrom drive. The USB booting on these laptops is probably quite a bit more solid than the equivalent on any desktop motherboard.

      ~GoRK

    2. Re:booting from pendrive by disappear · · Score: 4, Insightful
      So, you need an initrd. No problem provided you can get lilo or grub or whateverelse to find and load it. All your initrd needs to do is to load up your USB modules, mount your root fs off of usb mass storage (/dev/sda1 or whatever weird devfs name you use) and then pivot_root over to it. This is mostly equivalent to an initrd setup for something like a network booting system that uses NFS root or fibre channel or something like that. Any initrd HOWTO will cover setting up an initrd that loads modules and performs configuration to mount the root device that the kernel cannot do on its own.

      You missed a step:
      The initrd has to have about a one-second delay before you attempt to mount the drive from USB. This is because it takes a little while to detect it.

      If you make this one change (a little static binary that does 'sleep 1', essentially) to a standard Red Hat 'mkinitrd' ramdisk, you can indeed do USB if your BIOS supports it.

      I've done it. It was a @!#$% to debug the first time around: every time I dropped into sash everything worked, but if I didn't drop into sash it didn't. :-)

    3. Re:booting from pendrive by tenman · · Score: 2

      What happens if you have more than one bootable USB device? USB assigns ID's to devices dynamically, so that sda1=drive1 is not ALWAYS true. USB polls for devices, and then waits for the devices to respond. Device ID's are handed out "first come, first served" basis. While that's great for cameras, where there software looks for a device with a particular media type in it's QMS response, a bios will not have the luxury of obtaining a particular QMS signature (again where there is more than one bootable usb drive) before it begins the boot sequence. Not in today's BIOS anyway.

    4. Re:booting from pendrive by david.given · · Score: 2
      I'm working on a run-from-CD system. To speed up testing, I'm doing the development by booting the kernel off CD and then using a USB disk for the root filesystem.

      Setting it up's pretty easy; just tell Linux that the root is /dev/sda1, insert the mass storage driver into the kernel, etc. No initrd or user daemon is necessary.

      However, the delay-before-detection bit me. USB seems to be initialised last, so by the time Linux tries to mount the root filesystem the USB bus is still powering up and Linux panics because it can't find the root. I fixed this by patching the kernel to have a 3s delay just before mounting the root filesystem. What I'd really like to do is to move the USB initialisation so that it occurs before the IDE initialisation; as detecting the IDE devices takes about three seconds anyway, that would give time for the USB stuff to come up without slowing down the boot process.

  2. Amptron by theNote · · Score: 4, Informative

    I just bought a new Amptron MOBO and the BIOS supports this.

    The BIOS also has some network features built in, but I haven't checked them out yet.

    Go try one out, they're pretty cheap.

  3. Re:And how about Firewire? by Anonymous Coward · · Score: 2, Informative

    A mac maybe?
    It can boot from Firewire and USB and even the net with standards, no s**ty pxe, just bootp/dhcp and tftp and nfs (or afp or any other network file system).

    I think Sun also have this capitable.

  4. Mac OS X and USB/Firewire by norwoodites · · Score: 3, Informative

    On macs with os X, the OF reads from the devices and then the os sends messages to the of to read particular blocks from the device to get the driver and then loads the drive and lets the driver take over. In fact this is how they do scsi and ide. The OF(BIOS) contains generic drivers to load the kernel and also to read from the device.

  5. What does OF stand for? by Mustang+Matt · · Score: 3, Funny

    I know, stupid question, but I'm missing it.

    --
    The man who trades freedom for security does not deserve nor will he ever receive either. - Benjamin Franklin
    1. Re:What does OF stand for? by riggwelter · · Score: 2, Informative

      OpenFirmware

      It's sort of the Mac equivilent of a BIOS if you like

      --
      Listening for the sound of the coming rain...
    2. Re:What does OF stand for? by Tsk · · Score: 2, Informative

      Open Firmware.
      Basicly it's a forth interpreter that initialises the processor, initialises various chips on the mother board and initialises PCI cards. It's avaiables on MacIntosh since the PPC switch and on sun Hardware.
      Booting from a USB drive on a mac would not be difficult you'de just specify the path of the system blessed folder, be it a linux, Open, Net, Darwin or Mac OS X system.

      --
      none Yet.
    3. Re:What does OF stand for? by luphus · · Score: 2, Informative

      Actually its available ever since the switch to PCI from Nubus, which happened slightly after the PPC switch. 61xx, 71xx, and 81xx (and possibly others?) are Nubus based and do not have Open Firmware. Not intending to be nitpicky :)

      nwp

  6. Skip the USB by Perdo · · Score: 2

    Use a flash memory to IDE converter like this.

    Then you realize flash memory costs more per MEG than hard drives per GIG and is SLOW.

    Skip the fancy stuff unless you are just looking for toys.

    --

    If voting were effective, it would be illegal by now.

  7. Boot USB? Hell I can't get lilo to boot CF! by tzanger · · Score: 2

    I have an IDE-CF bay, a PCMCIA-CF adaptor and a USB-CF adaptor. Now linux sees the CF in the USB adaptor as a scsi disk but the others are straight IDE.

    I cannot for the life of me get lilo to correctly install on CF when in my laptop, and then boot in another computer. The CF reports itself as the same CHS whether it is in my PCMCIA slot or in the final computer's primary master CF-IDE bay. I've tried linear, lba32, with and without compact.

    Example setup: install CF into PCMCIA adaptor, install adaptor into laptop. Laptop sees /dev/hde. mount /dev/hde1. /mnt/sbin/lilo -b /dev/hde -r /mnt. Lilo says it installs fine. umount, remove from laptop and place CF into CF-IDE adaptor on final computer. Boot. Disk is detected with same CHS as it was in the PCMCIA-CF adaptor but lilo will either say "LI" or "LI 0x01 0x01..." (0x07 is another common one.)

    According to the LILO documentation that's illegal command and invalid initialization. Fun. Boot from a floppy on the target machine, run lilo from there, all is well. Unfortunately that isn't an option for me in all cases.

    groups.google.com suggests that this is a longstanding problem with LILO (booting CF) but has no suggestions. Other than Grub which seems to be an excercise in bloat, has anyone got a solution to this?

  8. Re:Boot USB? Hell I can't get lilo to boot CF! by tzanger · · Score: 2

    Grub, eh? It looked like a huge time sink last time I looked at it, but perhaps it's time for a new look. :-) Thanks.

    BTW have you ever tried to set the media write-lock on CF?

  9. Re:USB not for harddrives by AyeRoxor! · · Score: 3, Funny

    "USB was designed for simple, low throughput devices."

    Yeah, stick to ultra-fast devices like floppy drives.

    Hmm...... :P

  10. Re:And how about Firewire? by rakslice · · Score: 2

    >>I think Sun also have this capitable.

    Uh... I don't think so. Even in the fairly new Solaris 9, support for USB and 1394 hard drives is fairly sketchy.