[clug] Re: Booting from USB [was: Ubuntu 7.04]
alex at mugofgrog.com
Wed May 2 10:08:05 GMT 2007
> Anyway, what I was hoping for was any good references to what the BIOS
> is actually looking for on the USB memory device in order to boot from
I believe the BIOS sets up an emulation of drive for the boot loader. So
if you select USB-FDD it'll look to the bootloader like a floppy disk
(so you'd need to put root (fd0) in your grub config), USB-HDD and it'll
look like a standard IDE disk.
As far as the actual layout of the disk is concerned though, all it does
is checks if the boot sector is non-zero and jumps there, the same as
booting off any normal drive.
> I have determined that it needs to be a VFAT (or FAT) filesystem,
As far as I know there's no requirement for a FAT filesystem. A lot of
people do use it, but that's just because the SYSLINUX bootloader only
understands FAT. If you use grub you can boot off ext2/3, reiserfs, xfs
> but where does the kernel need to be and what bootloader works?
The ones I've used are SYSLINUX, grub and the MS-DOS bootloader. I guess
just about any bootloader that can be used on a floppy or HDD will work.
As long as it uses normal BIOS calls for disk access so the BIOS can do
it's emulation magic.
> anyone found any good references on how to "roll your own", or a script
> that does it for you?
I just gave it shot on an SD card in a USB multi-card reader. It should
be the same for any old USB mass storage device.
Start off by partitioning:
# fdisk /dev/sde
I just created one big partition sde1.
Now format it as any filesystem grub understands. I just used ext2:
# mkfs.ext2 /dev/sde1
mke2fs 1.38 (30-Jun-2005)
OS type: Linux
.... output snipped ...
# mount /dev/sde1 /mnt/tmp/
Copy on some random kernel image. You'll probably want to use one with
USB mass storage support compiled in, otherwise you won't be able to
mount the root filesystem. ;-)
# cp ~/kernel-2.6.19-gentoo /mnt/tmp/bzImage
Copy on grub's various bits and pieces.
# mkdir -p /mnt/tmp/boot/grub
# cp /boot/grub/*stage* /mnt/tmp/boot/grub
Make device.map (this step is probably optional)
# vim /mnt/tmp/grub/device.map
# cat /mnt/tmp/grub/device.map
Make the grub config file. We throw in rootdelay=6 to make grub wait for
a while to make sure disk is ready.
# vim /mnt/tmp/grub/menu.lst
# cat /mnt/tmp/grub/menu.lst
Now just install grub as normal using the grub shell.
# umount /mnt/tmp
# grub --no-floppy
Probing devices to guess BIOS drives. This may take a long time.
GNU GRUB version 0.97 (640K lower / 3072K upper memory)
[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename. ]
grub> root (hd4,0)
Filesystem type is ext2fs, partition type 0x83
grub> setup (hd4)
Checking if "/boot/grub/stage1" exists... no
Checking if "/grub/stage1" exists... yes
Checking if "/grub/stage2" exists... yes
Checking if "/grub/e2fs_stage1_5" exists... yes
Running "embed /grub/e2fs_stage1_5 (hd4)"... 15 sectors are embedded.
Running "install /grub/stage1 (hd4) (hd4)1+15 p (hd4,0)/grub/stage2
Unplug the USB drive, stick it into the machine you want to boot from.
Select USB-HDD in the BIOS. You should get grub's loading screen, it
could take a while before the menu comes up so be patient. Hit enter and
after a bit of slow loading the kernel comes up and then panics because
it can't find anything to run. If you want to do something useful with
it you'd need to pop some executables on there (eg busybox) and give the
appropriate kernel command-line in grub's config (something like
More information about the linux