This documents how you set up a USB drive to boot/install various things from it, without reformatting the disk by dumping a raw image onto it. This page documents elegantly moving only the necessary files to the USB drive, so that you can have one USB disk with many different install and boot possibilities.
Following these instructions, I have a USB drive that can boot Debian lenny installer i386/amd64, Ubuntu installer i386/amd64, and Debian lenny live.
Install grub onto it
See DebianNotes/Grub. Most of this document assumes that you have a working grub installation on your USB drive.
General overview
To boot something from a drive, you need:
- A bootloader (grub) that you can direct with certain options for different things.
- A linux kernel
- The initrd for the kernel to load, which the initial root filesystem, that tells
- (possibly) to pass various options to the kernel command line, to direct the
- To tell the bootloader to load those things.
The purpose of this page is to let you know where to get these things, and what grub entries you need to use them.
Debian/Ubuntu installer
Start off looking for the netboot installer, since you will want to put the minimum on the USB disk. You can directly download the vmlinuz or linux and initrd.gz files from debian mirrors. You'll just have to navigate to the right folder yourself, as a hint I found them at here:
http://ftp.us.debian.org/debian/dists/etch/main/installer-i386/current/images/netboot/
So look at dists/CODENAME/main/installer-ARCH/current/images/netboot
Make a subdirectory on your USB drive to hold these images (I use /boot/img/CODENAME-install-ARCH). That's it in terms of the files.
Next, you need to configure the bootloader. In your grub, do:
title Debian Etch i386 Netboot Installer from USB root (hd0,0) kernel /boot/img/etch-netboot-i386/linux initrd /boot/img/etch-netboot-i386/initrd.gz boot
There is also now a -gtk installer, and if you use that then you have to add extra parameters to the kernel in order to set up the video modes. To do that, look around in the directories to find a file containing the kernel boot parameters, for example here. All boot methods will have a file like this you can refer to to get extra boot parameters. Add these extra parameters to the kernel line in menu.lst.
Debian Live on a USB disk
There is a Debian Live, which is a very minor modification of regular Debian. They produce images for CDs and USB disks, but we don't want to have to lose our current filesystem on the drive. Thus, we extract the right files and set up grub to boot it.
Squeeze
- Go to the download site. Download a usb-hdd image (web images do not work anymore, they do not have usb-storage modules).
# get offset from fdisk + look at (sector offset*512) mkdir tmp sudo mount -o loop,offset=512 debian-live-6.0.3-i386-standard.img tmp/
- Copy live/initrd.img and live/vmlinuz.img too the USB drive, any directory you'd like on the USB drive
- Copy filesystem.squashfs over to the USB drive, too
Boot parameters are in syslinux/live.cfg. For grub2, use
menuentry "Debian live, squeeze, xfce, 686" { linux /boot/debian-live-squeeze-xfce/vmlinuz boot=live union=aufs live-media-path=boot/debian-live-squeeze-xfce/ live-config initrd /boot/debian-live-squeeze-xfce/initrd.img }
live-media-path=xxx/yyy/ is the path to filesystem.squashfs (or *.squashfs). live-config is needed in order to make it automatically generate a user and all.
References:
Lenny live
Lenny is much easier than etch.
Get one of the images at http://cdimage.debian.org/cdimage/release/current-live/i386/usb-hdd/ (find the right directory for your preferred distribution)
Harder method: You need to extract the required files from this. Losetup mount it:
# get offset from fdisk + look at (sector offset*512) sudo losetup -o 32256 -f debian-live-500-i386-xfce-desktop.img sudo mount /dev/loop0 tmp-mnt/
Copy over the /live/ directory from the desk to your USB drive. You can rename it to any path you'd like, my example uses /boot/img/live-lenny/ on my USB drive.
Easier method: I now noticed you can probably get all files you need from the 'web/' directory without having to losetup mount it yourself. All you need is initrd*, vmlinuz*, and one of the filesystems. The filesystem must be renamed to filesystem.squashfs (I think the live system is flexible enough to adjust the name, and probably even configure this, but I haven't gone that far yet... specifying just a directory is enough for me.)
- Now, to make it bootable... we simply configure grub for it:
title Debian Lenny Live from USB (i386) root (hd0,0) kernel /boot/live-lenny-i386/vmlinuz1 boot=live union=aufs live-media-path=boot/live-lenny-i386/ # append these options for failsafe mode: # noapic noapm nodma nomce nolapic nosmp vga=normal initrd /boot//live-lenny-i386/initrd1.img boot
Notice how you can specify the path to load the root filesystem from (live-media-path=boot/img/live-lenny). I never figured out how to do this with live for etch. This one option makes this live system _much_ easier, and easier to have multiple live systems on your drive at once. Other boot options:
toram - Load the image in RAM
root=LABEL=<partition_label> - look for the live image on this partition only.
live-media=removable-usb - Only look for the image image only on removable-usb things.
live-media=/dev/sdb1 - look only here for the live image
You can replace initrd1 and vmlinuz1 with initrd2 and vmlinuz2 for a 686-specific compiled version.
Etch (obsolete)
Copy vmlinuz and initrd.img files to the usb key, and copy the casper/ directory over (don't rename it, you can put the kernel and initrd anywhere you want). The kernel and initrd are non-specific to the main filesystem in the casper/ directory.
(more later)
See also http://web.glandium.org/blog/?p=175
If usb disk isn't initilized by mount time, try these kernel/initrd options:
break=mount reference
rootdelay=15