Booting from USB Drives? 49
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?"
booting from pendrive (Score:2, Interesting)
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
Re:booting from pendrive (Score:5, Informative)
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
Re:booting from pendrive (Score:4, Insightful)
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. :-)
Re:booting from pendrive (Score:1)
Ah, good times messing with free Unix systems.
This is totally offtopic to the article. I just thought of a little story that was somewhat related to yours. Once, long ago (OK, 4 or 5 months ago) hacking the Linux VM for an OS class. An editing error (I cut some code to move it around, and ended up pasting it twice in two different spots) completely broke shared libraries (I think I may have disabled major portions of the copy on write semantics of fork, actually). Booting the system, even in single user mode, failed in fairly obscure way (init said "No more processes at this runlevel" and just sat there). Of course booting with init=/bin/sash worked very nicely.
Your story just made me think about this, and I felt like 'sharing'. (Awww...)
Re:booting from pendrive (Score:2)
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.
Re:booting from pendrive (Score:1)
The dumb way is to use a sleep() with a maximum number of tries. The smart way is to keep trying until all drivers are done initializing (and drive access times out -- it can take a while in a configuration where the mount is initiated by a boot-time audio message through the speaker and someone has to insert a disk...), or at least all drivers which are relevant, which is pretty hard to determine due to so many possibilities, particularly if networking is involved.
Re:booting from pendrive (Score:2)
Re:Booting from USB drive (Score:1)
SpatchMonkey's comments are:
1. In the article
2. Obvious
Re:And how about Firewire? (Score:2, Informative)
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.
Re:And how about Firewire? (Score:2)
Uh... I don't think so. Even in the fairly new Solaris 9, support for USB and 1394 hard drives is fairly sketchy.
Amptron (Score:4, Informative)
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.
Re:Amptron (Score:1)
Most likely they are lying to you.
PCChips and Amptron are virtually the same company. PCChips is the company that uses fake chipset names, fakes CPU speeds in BIOSes, fakes cache settings in BIOSes, uses plastic cache chips, and pirates BIOS code.
I wouldn't trust anything in a BIOS that's built for a PCChips board without a _lot_ of testing.
Oh, I can provide references to these little facts, too.
For Compact Flash... (Score:1)
Cheers
You'd have to open the case (Score:1)
USB was designed for simple, low throughput devices. You should use firewire
That defeats the purpose. Not all PC motherboards have integrated SCSI or FireWire controllers. (Most Macs have one or the other, but this article is about intel PCs.) By the time you've opened the case to install a 1394 or SCSI card, you could have re-arranged the ATA cables to boot from an ATA hard disk. The OP wanted a solution that worked without having to open the case.
Re:USB not for harddrives (Score:3, Funny)
Yeah, stick to ultra-fast devices like floppy drives.
Hmm......
Mac OS X and USB/Firewire (Score:3, Informative)
What does OF stand for? (Score:3, Funny)
Re:What does OF stand for? (Score:2, Informative)
It's sort of the Mac equivilent of a BIOS if you like
Re:What does OF stand for? (Score:2, Informative)
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.
Re:What does OF stand for? (Score:2, Informative)
nwp
Good idea but... (Score:1)
USB drives working with Sun Solaris? (Score:1)
Skip the USB (Score:2)
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.
Boot USB? Hell I can't get lilo to boot CF! (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?
Re:Boot USB? Hell I can't get lilo to boot CF! (Score:1)
Re:Boot USB? Hell I can't get lilo to boot CF! (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?
Boot from fd/cd, then mount the USB drive as / ? (Score:1)
This would be enough for me , as an alternative to booting directly from the USB. Does anyone know if this is easier, or even possible? It would -seem- to be easier, since the USB driver and fs could be modloaded instead of needing to be statically linked.
Anyone have any experience with this?
internal pcmcia reader (Score:1)
Re:internal pcmcia reader (Score:1)
With your sense of humor why don't tell him that he could replace the USB drive with a normal floppy drive or IDE disk...
Stupid, the matter som people are made of...