MandrivaUsers.org : HOW TO Boot to a USB external hard disk - MandrivaUsers.org

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

HOW TO Boot to a USB external hard disk put that external drive to good use!

#1 User is offline   mevatron 

  • New Here
  • Group: New here
  • Posts: 7
  • Joined: 20-March 05

Posted 22 March 2005 - 09:10 PM

Okay,

I'm going to give the steps I took to boot from and external USB 2.0 Maxtor hard drive.

Problem Outline:
My main problem was that my Dell Inspiron 8200 did not support booting from USB drives in the BIOS. Also, I had only USB ver 1.1 built-in to my laptop so I also needed to worry about using an Adaptec USB 2.0 PCMCIA card.

Also I'm assuming you have Mandrake 10.X already installed on the /dev/hda right now. I haven't made a bootable CDROM yet almost there though.

Steps

Step 1: Installation
As you probably know if you've read some other posts on this topic, DiskDrake does not handle partitioning external drivers very well (err not at all might be more precise :)/>). So, you're going to need something like KNOPPIX or in my case I just used an old Gentoo LiveCD I had laying around.

Take a LiveCD of your choice (needs to have fdisk on it) and manually partition your hard drive. Gentoo has a nice step by step manual on how to do this if you are new to this sort of thing. It can be found here.

Once you have partitioned your USB HDD, keep following the gentoo manual on creating the filesystems. The critical one for me was creating the swap space because that's what my DiskDrake kept failing on. After you are finished partitioning and formatting, reboot with the Mandrake Installing CD 1.

This time when you get to the partitioning screen just say "Use existing partitions" and everything should be hunky dory.

Step 2: Creating your own initrd (the HARD part)
In this phase I spewed many explitive and smashed the keyboard several times, so if you get stuck don't feel bad :)/>.

Step 2A: Unpacking the initrd
In order to get the USB drive to boot you have to load all the usb modules and all the pcmcia modules before the kernel mounts the real root device because you want your USB disk to be the real root device!

Make sure to login as root.

# cd /boot
# cp initrd-2.6.8.1-12mdk /root
# cd /root
# mv initrd-2.6.8.1-12mdk initrd.mdk.gz
# gunzip initrd.mdk.gz
# mkdir /mnt/images
# mount initrd.mdk -o loop /mnt/images


Okay now you should have the default initrd file mounted under /mnt/images. Now, you need to make your own initrd so that you can copy an extra binary and some more kernel modules into it.

Step 2B: Make your own initrd
I'm just going to copy the steps given in The Loopback Root Filesystem HOWTO by Andrew Bishop.

mkdir /root/initrd
dd if=/dev/zero of=initrd.img bs=1k count=4096
mke2fs -i 1024 -b 1024 -m 5 -F -v initrd.img
mount initrd.img /root/initrd -t ext2 -o loop
cd initrd
[create the files] <-- don't worry about this step and the below steps yet.
cd ..
umount /root/initrd
gzip -c -9 initrd.img > initrdgz.img


In the tutorial, Andrew used count=1024 which will only give you 1MB of ramdisk, so I moved it up to 4096, which will give you 4MB of ramdisk to house the libraries, binaries, and the modules we'll need later.

Make sure you are in the newly created custom initrd folder. It should have like just a lost+found folder in it. Now let's copy everything from the default initrd over to our new one.

# cp -R /mnt/images/  .


Now, you should have everything from the default initrd in your new initrd. Forgive me if the above copies the images folder into your new initrd as well. If it does just do the following

# cd images
# mv * ../
# cd ..
# rmdir images


If the images directory is not in your new initrd folder then my copy worked yay, and never mind the above step.

Step 2C: Setting up the new initrd disk
You will need to collect all the nescessary modules for the USB disk onto the initial ramdisk.

# cd /lib/modules/KERNEL_VERSION_HERE/kernel/drivers

// first we'll get all the usb modules we need
# cd usb
# cd host
# cp echi-hcd.ko.gz ohci-hcd.ko.gz uhci-hcd.ko.gz /root/initrd/lib
# cd ..
# cd core
# cp usbcore.ko.gz /root/initrd/lib
# cd .. 
# cd storage
# cp usb-storage.ko.gz /root/initrd/lib

// now let's go get the pcmcia modules [optional use only if you need this]
# cd ../..
# cd pcmcia
# cp pcmcia_core.ko.gz /root/initrd/lib

// NOTE: you may not need the yenta_socket module if you card uses the i82365 driver so just use which ever one is generally listed when you type /sbin/lsmod
# cp yenta_socket.ko.gz /root/initrd/lib

// let's get the scsi modules we need
# cd ..
# cd scsi
# cp sd_mod.ko.gz /root/initrd/lib
# cp scsi_mod.ko.gz /root/initrd/lib


Whew! That was a lot of typing :)/>. Okay, now go back to /root/initrd/lib
# cd /root/initrd/lib
# gunzip *.gz


Now all the modules are in place now let's update that linuxrc file!

Step 2D: Modifying the linuxrc file
# cd /root/initrd
# vi linuxrc

// now copy and paste the following into linuxrc

#!/bin/nash

echo "Loading pcmcia_core.ko module"
insmod /lib/pcmcia_core.ko
echo "Loading yenta_socket.ko module"
insmod /lib/yenta_socket.ko
echo "Loading usbcore.ko module"
insmod /lib/usbcore.ko
echo "Loading ehci-hcd.ko module"
insmod /lib/ehci-hcd.ko
echo "Loading ohci-hcd.ko module"
insmod /lib/ohci-hcd.ko
echo "Loading uhci-hcd.ko module"
insmod /lib/uhci-hcd.ko
echo "Loading scsi_mod.ko module"
insmod /lib/scsi_mod.ko
echo "Loading sd_mod.ko module"
insmod /lib/sd_mod.ko
echo "Loading usb-storage.ko module"
insmod /lib/usb-storage.ko
sleep 10
echo "Loading reiserfs.ko module"
insmod /lib/reiserfs.ko
echo Mounting /proc filesystem
mount -t proc /proc /proc
echo Mounting sysfs
mount -t sysfs none /sys
echo Creating device files
mountdev size=1M,mode=0755
echo starting udev
udevstart
echo -n /sbin/hotplug > /proc/sys/kernel/hotplug
echo Creating root device
mkrootdev /dev/root
/bin/sfdisk -R /dev/sda
sleep 5
echo Mounting root filesystem with flags notail,noatime
mount -o notail,noatime --ro -t reiserfs /dev/root /sysroot
echo 0x0100 > /proc/sys/kernel/real-root-dev
pivot_root /sysroot /sysroot/initrd
umount /initrd/sys
umount /initrd/proc
echo Initrd finished


Okay, now you have a cool linuxrc, but it won't work without that nice little sfdisk binary on the initial ramdisk, so let's fix that now.

Step 2E: Move sfdisk binary over to initrd

# cd /root/initrd/bin
# cp /sbin/sfdisk .
# ldd sfdisk
linux-gate.so.1 => (0x...)
libc.so.6 => /lib/tls/libc.so.6 (0x...)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x...)
# cp -L /lib/libc.so.6 /root/initrd/lib
# cp -L /lib/ld-linux.so.2 /root/initrd/lib
# cd /root/initrd/lib
# mkdir tls
# cd tls
# ln -s ../libc.so.6 libc.so.6


Before we're through I had to make one more mod to the initrd file (NOTE: my drive booted without this step, but when i left it out one of my ethernet cards would initialize properly so you can try it without it and see if yours works).

# cd /root/initrd/etc/udev/rules.d
# vi 00-me.rules

// paste this line in the file and save it
BUS="usb", KERNEL="sd*", SYSFS{serial}="Your devices serial number goes here", NAME="%k", SYMLINK="usbhd%n"


To get my devices usb serial number i just followed this guys cool udev guide here

Okay now let's pack this bad boy up and put it onto the /boot partition of the current mandrake partition.

# cd /root
# umount /root/initrd
# gzip initrd.img
# cp initrd.img.gz /boot



Step 3: Booting the darn thing FINALLY!
Now you need a GRUB floppy or LILO ( if you must :)/>)
Here's the GRUB instructions for that
GRUB Floppy Install

Boot to the floppy
grub> kernel (hd0,0)/vmlinuz root=/dev/sda3 resume=/dev/sda2
// status info is printed
grub> initrd (hd0,0)/initrd.img.gz
// more status blah blah
grub> boot

and voila your external hard drive should begin purring to life!!

Step X: I added this so you can boot to a CD to start your external hard drive
Now that you have your external hard drive booting you'll probably want to be able to boot to a CD so you don't have to keep typing all that stuff in.

I'm going to just tell you how to do it with an easy GRUB CD. Just follow these instructions from the GRUB Online manual located here.

Now just copy the kernel (vmlinuz-2.6.8.1-12mdk) and the initrd image (initrd.img.gz) to the iso directory you created for your bootable iso. Then burn the iso image to a CD using xcdroast or something like that. Now boot back up with the CD and you can follow the steps like booting off the floppy except this time the information is on the CD so you can just type.

grub> kernel /vmlinuz-2.6.8.1-12mdk root=/dev/sda3 resume=/dev/sda2
// address stuff
grub> initrd /initrd.img.gz
// more address stuff
grub> boot


and you're done. Now you can use that internal hard drive for something else :)/>. Let me know if you need any help with this.

-Will

This post has been edited by mevatron: 22 March 2005 - 11:40 PM

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users