-   Slackware (
-   -   How to boot an USB hard disk with a boot cd (

mscole 10-15-2006 11:31 AM

How to boot an USB hard disk with a boot cd
Here is how I built a cd to boot Slackware 11.0 from a USB hard disk, on any computer that can boot from the cdrom but not from an external drive. This has to be done on a working Linux system (preferably Slackware 11.0, running the generic kernel from install cd 2, /extra).


This is dangerous if you do not know what you are doing. I hosed a perfectly good Slackware system while working out these steps. I was able to recover it because I backed up my /boot directory before I started. BACKUP before you start.

The following were used in making this guide:

Slackware 11.0 install cd 1

Slackware 11.0 install cd 2


Here it is, step by step.

1) Connect the USB drive to the computer you want to boot from the external drive, boot the Slackware 11.0 install cd 1, and install Slackware to the USB disk. *Be careful not to mount, format or install anything on the internal hard disks.* Use the default kernel, Do not bother making a boot floppy, because it won't work anyway, and you do not need to install lilo unless you think you will need it for some reason.

2) Go to a computer that already has Slackware installed, and boot Slackware from your internal hard disk.

3) If the computer you are working from does not have the generic kernel installed, you will have to install it from the /extra directory on the Slackware 11.0 install cd 2 (or the install dvd). Back up your /boot directory before you start, and restore it when you finish, unless you want to run the generic kernel from that computer. I have not tried making a boot cd with other kernels, but it should work, as long as they do not have USB support compiled in. With USB support compiled in, the kernel tries to mount the root partition too soon, and fails.

4) open a terminal window if you are not at the command prompt.

5) su

6) cd /boot

7) Make an initrd for the filesystem you will use. If you do not know what to do, see /extra/linux- on install cd 2.
Do not specify a root partition. Here is the command for my system:

mkinitrd -c -k -m jbd:ext3 -f ext3

8) Copy the USB modules to the initrd-tree. If you are using a 2.4 kernel the paths and filenames will be different.

cp /lib/modules/ /boot/initrd-tree/lib/modules/
cp /lib/modules/ /boot/initrd-tree/lib/modules/
cp /lib/modules/ /boot/initrd-tree/lib/modules/
cp /lib/modules/ /boot/initrd-tree/lib/modules/

9) Check to make sure the modules are all there. If you do not use ext3, you will not have ext3.ko or jbd.ko in the directory. If you use reiserfs you will have reiserfs.ko.

ls /boot/initrd-tree/lib/modules/

10) Add the modules to the load_kernel_modules file. I like to use Pico, but you purists will probably want to use emacs:

pico initrd-tree/load_kernel_modules

Here are the lines to append:

insmod /lib/modules/$(uname -r)/uhci-hcd.ko
insmod /lib/modules/$(uname -r)/ehci-hcd.ko
insmod /lib/modules/$(uname -r)/ohci-hcd.ko
insmod /lib/modules/$(uname -r)/usb-storage.ko

11) If the file is not executable, make it so:

chmod 755 initrd-tree/load_kernel_modules

12) Add a sleep to the linuxrc file to give the USB system time to come up before the kernel tries to mount the root partition:

pico initrd-tree/linuxrc

Append the line "sleep 10" just after the section that loads the modules (see example below).

from linuxrc
# Load kernel modules:
if [ ! -d /lib/modules/`uname -r` ]; then
echo "No kernel modules found for Linux `uname -r`."
elif [ -x ./load_kernel_modules ]; then # use load_kernel_modules script:
echo "/boot/initrd.gz: Loading kernel modules from initrd image:"
. ./load_kernel_modules
else # load modules (if any) in order:
if ls /lib/modules/`uname -r`/*.*o 1> /dev/null 2> /dev/null ; then
echo "/boot/initrd.gz: Loading kernel modules from initrd image:"
for module in /lib/modules/`uname -r`/*.*o ; do
insmod $module
unset module

sleep 10

# Initialize LVM:

13) if the linuxrc file is not executable, make it so:

chmod 755 initrd-tree/linuxrc

14) Run mkinitrd without any parameters:


15) Create a directory in which to build the tree for your cd:

mkdir /home/~/bootcd

16) Assuming you are still in the /boot directory:

cp -a initrd-tree /home/~/bootcd/

17) cp initrd.gz /home/~/bootcd/

18) cp vmlinuz-generic- /home/~/bootcd/vmlinuz

19) Mount the Slackware Install Disk 1 cdrom

cp -a /mnt/cdrom/isolinux /home/~/bootcd/

This will also put some extra stuff in there that you don't need, but who cares?

20) You can edit the message at the boot prompt so it doesn't tell you the wrong information. I deleted all the original text and replaced it with a message about how to boot the USB disk:

cd /home/~/bootcd

pico isolinux/message.txt

Here is what I put in the file, your message will vary, depending on where your root partition is. The name of the disk may also change from one computer to another:

Enter the name of the kernel and any parameters at the promt.

For example, if the Linux system were on the USB disk /dev/sdb3

boot: /vmlinuz initrd=/initrd.gz root=/dev/sdb3 ro

21) Build the disk image. Make sure you are in the /home/~/bootcd directory:

mkisofs -o bootusb.iso \
-R -J -A "USB harddisk boot cd" \
-hide-rr-moved \
-v -d -N \
-no-emul-boot -boot-load-size 32 -boot-info-table \
-sort isolinux/iso.sort \
-b isolinux/isolinux.bin \
-c isolinux/isolinux.boot \
-V "bootusb" .

(don't forget the final space and dot).

This will put a file called bootusb.iso in your bootcd directory. The file will be about 15 megs. Burn it to a cd (I use K3B, but again, you purists out there will probably want to use cdrecord).

That should give you a bootable cd. Connect the USB drive to the computer you want to boot, put in your boot cd, power up, and at the boot: promt enter the name of the kernel with the appropriate parameters. In my case it looks like this:

boot: /vmlinuz initrd=/initrd.gz root=/dev/sdb3 ro

22) I am not a programer or a sysadmin, so there may be better ways to do some of these steps that I do not know about. Comments and corrections welcome.

Mike Cole.

All times are GMT -5. The time now is 02:25 AM.