Boot Debian from a USB Hard-Drive - Part 1
Note that I first performed these instructions back in September 2004 and there may be minor differences in the actual implementation.
Ever wanted to install Debian Linux on your laptop but haven’t got the space available to handle a dual boot configuration and don’t want to give away Windows? If you’ve got a spare hard-drive lying around, the solution might just be to purchase a USB2 HDD enclosure from EBay for as little as $15 and boot Linux by USB! Unfortunately this can be quite a challenging problem, but the following tutorial outlines how I solved it and is inspired by the article Boot Linux from a Firewire device over at IBM by Martyn Honeyford.
A few issues to note that make this problem tricky. Firstly, on BIOS’s that don’t support booting from a USB device directly, by default the USB drivers are loaded too late in the boot-chain to make it possible to boot to a USB device. Secondly, I’m using a Dell Latitude C640 which only has USB1, so I’m using a PCMCIA card with USB2 support when connecting to my removable HDD. Finally, I haven’t seen any one who’s done this for Debian, I was able to find a tutorial for Gentoo (the IBM link), and Redhat, but not for Debian. The solution is fairly similar but a few nity gritty details particularly around cramfs had me tearing my hair out at one stage.
Getting this setup working took me far longer than it probably should have, and the slightest differences in your configuration might make the situation more or less difficult. Persistance should eventually lead you to a working solution
To get started, remove your Windows HDD and install the soon to be Linux HDD into your laptop. Install Debian as you would normally, I chose unstable, but it really shouldn’t matter which build you choose. Complete your installation, boot into your fresh version of Debian and su as root. The first thing we want to is confirm that your mkinitrd.conf file is ready for the creation of our image. The following is how my one looks.
aflinux:~/usb-init# cat /etc/mkinitrd/mkinitrd.conf MODULES=most DELAY=5 ROOT=probe UMASK=666 MKIMAGE=’mkcramfs %s %s > /dev/null’ BUSYBOX=yes PKGSCRIPTS=yes INITRD_LD_LIBRARY_PATH=$LD_LIBRARY_PATH
The first things we want to do is create the default initrd image. Whilst a cramfs image is created by default, we want to create a directory version that we’ll edit ourselves before over-writing the automatically created cramfs version.
The following snippet prepares the directory we’re going to use.
aflinux:~# mkdir usb-init aflinux:~# cd usb-init/ aflinux:~/usb-init# mkinitrd -k -o usb.img /usr/sbin/mkinitrd: The working directory /tmp/mkinitrd.4432 will be kept. aflinux:~/usb-init# mv /tmp/mkinitrd.4432/initrd initrd
We now need to copy all the requried modules from our kernel folder into the relevant places. Make sure you’re copying all the relevant files for your kernel, when I first did this 2.6.7 was the latest kernel; the same instructions should apply for the latest version.
aflinux:~/usb-init/#
cd ~/usb-init/initrd/lib/modules/2.6.7-1-386/
aflinux:~/usb-init/initrd/lib/modules/2.6.7-1-386#
mkdir kernel/drivers/usb/host
aflinux:~/usb-init/initrd/lib/modules/2.6.7-1-386#
cp /lib/modules/2.6.7-1-386/kernel/drivers/usb/host/*
kernel/drivers/usb/host/
aflinux:~/usb-init/initrd/lib/modules/2.6.7-1-386#
cp /lib/modules/2.6.7-1-386/kernel/drivers/pcmcia/yenta_socket.ko
kernel/drivers/pcmcia/
Now we’ve got all the additional drivers we need on top of the ones included by the “most” directive in the mkinitrd.conf file. The following text should over-write the contents of the loadmodules file. It’s job is to load up the PCMCIA modules required to start my USB2/Firewire card, and enable USB storage support so that when the initrd ends we’re able to pivot to the new root stored on the USB Hard-drive.
aflinux:~/mkinitrd/initrd# cat loadmodules echo “Loading up PCMCIA Support” modprobe -k pcmcia_core modprobe -k yenta_socket modprobe -k ds echo “Loading up USB Support” modprobe -k usbcore modprobe -k scsi_mod modprobe -k sd_mod modprobe -k usb-storage modprobe -k uhci-hcd modprobe -k ohci-hcd modprobe -k ehci-hcd modprobe -k ide-generic modprobe -k ide-disk
Finally the script file defines the root as /dev/sda1. In some cases this /dev point might not have been established, but this long hand format works for me.
aflinux:~/mkinitrd/initrd# cat script ROOT=/dev/scsi/host0/bus0/target0/lun0/part1 unload_unused_ide ” generic
At this point we can bundle up our folder structure into a cramfs image that we can use as an initrd image!
aflinux:~/usb-init/initrd# cd ~/usb-init aflinux:~/usb-init# mkcramfs initrd/ usb.img Directory data: 8628 bytes Everything: 4400 kilobytes Super block: 76 bytes CRC: 31c2161a
We’ve now bundled our image. If we step back a directory and look at the size of the image; mine happens to be a little over a 4MB. Due to the “most” directive we ended up including a number of modules that we really didn’t have to, once you get this image working as it stands, you might wish to go back and remove redundant modules to lower the image size!
At this point I recommend you copy the usb.img file to /boot as usb-26.img. This way if you’re ever using a computer that supports direct booting from usb, by editing your grub boot parameters you should be able to use this initrd as it stands to boot into your portable hard-drive. At this point you can shutdown Linux and if you’re lucky you can remove the Linux HDD from your laptop for the first and last time, put it into the USB enclosure and put your Windows HDD back in.
What’s a touch more complicated is where your laptop doesn’t support usb booting at all (such as the case with my Latitude C640). In order to get around this we need to setup a version of GRUB on our Windows partition. This will be discussed in Part2 of this post…
Update: I noticed an old link of mine mentions how to do this process for Fedora Core 3. Those mkinitrd preload statements might work on Debian too; but I haven’t tested. The article is available at: http://www.simonf.com/usb/
Comments(0)


I’m not sure how long this has been around, but a month or so ago I discovered some XML HTTP functions by looking at the source code for 