boot gentoo linux iso from usb

| No Comments | No TrackBacks
I got a new laptop and decided to go "balls to the wall" with my linux experience and put a gentoo install on it. Gentoo is known to be one of the more challenging linux distrobutions because it requires a lot of work onthe user side of things to get all of the operating system parts compiled specifically to the users hardware. This has a benefit of giving the user the best performance but requires a lot of knob turning.

Now that I have my hardware, the next step is begining the install by booting the machine using an install ISO file or LiveCD.  Unfortunately I don't have any blank CDs laying around.  I do have a 1gb USB flash drive though!  I have always heard/read about people booting computers using linux that is installed onto a USB flash drive. 

Well... if we are using gentoo to really get down and dirty... what better way to start then figuring out how to install the gentoo install-x86-minimal-2008.0.iso onto the flash drive.  No need for a blank CD.
I began my journey looking for instructions from people that have done this before.  Unfortunately the info was a bit sparse and if it was detailed it was too detailed and specific to a particular distrobution. 

The gentoo doc even have a walkthrough but it is geared towards the user already having a gentoo distro up and running.  I don't have that. I am working from a kubuntu system.  Here is a link to the instructions that I started with.  Below is the tale of my journey.  Enjoy!

Use fdisk to set up a FAT16 bootable partition

    > fdisk /dev/sdd1

    Command (m for help): p

    Disk /dev/sdd1: 1055 MB, 1055899648 bytes
    33 heads, 62 sectors/track, 1007 cylinders
    Units = cylinders of 2046 * 512 = 1047552 bytes

         Device Boot      Start         End      Blocks   Id  System

    Command (m for help): o
    Building a new DOS disklabel. Changes will remain in memory only,
    until you decide to write them. After that, of course, the previous
    content won't be recoverable.

    Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

    Command (m for help): n
    Command action
       e   extended
       p   primary partition (1-4)
    Partition number (1-4): 1
    First cylinder (1-1007, default 1):
    Using default value 1
    Last cylinder or +size or +sizeM or +sizeK (1-1007, default 1007):
    Using default value 1007

    Command (m for help): a
    Partition number (1-4): 1

    Command (m for help): t
    Selected partition 1
    Hex code (type L to list codes): 6
    Changed system type of partition 1 to 6 (FAT16)

    Command (m for help): p

    Disk /dev/sdd1: 1055 MB, 1055899648 bytes
    33 heads, 62 sectors/track, 1007 cylinders
    Units = cylinders of 2046 * 512 = 1047552 bytes

         Device Boot      Start         End      Blocks   Id  System
    /dev/sdd1p1   *           1        1007     1030130    6  FAT16

    Command (m for help): w
    The partition table has been altered!

    Calling ioctl() to re-read partition table.

    WARNING: Re-reading the partition table failed with error 22: Invalid argument.
    The kernel still uses the old table.
    The new table will be used at the next reboot.

    WARNING: If you have created or modified any DOS 6.x
    partitions, please see the fdisk manual page for additional
    Syncing disks

Validate the partition....

    > fdisk -l /dev/sdd1

    Disk /dev/sdd1: 1055 MB, 1055899648 bytes
    33 heads, 62 sectors/track, 1007 cylinders
    Units = cylinders of 2046 * 512 = 1047552 bytes

         Device Boot      Start         End      Blocks   Id  System
    /dev/sdd1p1   *           1        1007     1030130    6  FAT16

Now that we have the partition set up we need to actuall establish the filesystem. It needs to match the system type that we set the partition to, so it should be FAT16.

    > mkdosfs -F 16 /dev/sdd1
    mkdosfs 2.11 (12 Mar 2005)

This was the easy part.  Next we need to put a Master Boot Record on the drive. I was using a kubuntu distro to do all of this. One set of instructions that I was following pointed me toward the `install-mbr` cmd.

    > install-mbr --help
    Usage: install-mbr [options] 

I had a lot of trouble with this and never got it to work. Eventually I was able to find a mbr socked away in the syslinux package that I downloaded later.


In order to get this onto the drive you need to copy it to one device level higher then the partition on the device. Don't try to put it on /dev/sdd1, it is supposed to get on /dev/sdd. This maybe why the install-mbr was not working for me. I finally realized that the MBR doesn't go IN the partition it goes in front of it.

    > dd if=./mbr/mbr.bin of=/dev/sdd
    0+1 records in
    0+1 records out
    404 bytes (404 B) copied, 0.0027343 seconds, 148 kB/s

Now that this is done we should be able to mount it.

    > sudo mount -t vfat /dev/sdd1 /mnt/usb/

If you get errors at this stage, that means that something went wrong in the steps before this. Start back with fdisk. Remove all partitions. Set up the new partitions, establish the filesystem, and copy the MBR. If everything goes well you should be able to mount the drive as a vfat filesystem.

Next I followed the gentoo instructions to mount the iso and move the files over to the flash drive.

    >sudo mkdir -p /mnt/cdrom
    >sudo mount -o loop,ro -t iso9660 livecd-i686-installer-2007.0.iso /mnt/cdrom

    > sudo cp -r /mnt/cdrom/* /mnt/usb
    > sudo mv /mnt/usb/isolinux/* /mnt/usb
    > sudo mv /mnt/usb/isolinux.cfg /mnt/usb/syslinux.cfg
    > sudo rm -rf /mnt/usb/isolinux*

    (The memtest86 kernel needs to be renamed for loading it via syslinux)
    > sudo mv /mnt/usb/memtest86 /mnt/usb/memtest

Now make some adjustments to the config file

    > sudo sed -i \
        -e "s:cdroot:cdroot slowusb:" \
        -e "s:kernel memtest86:kernel memtest:" \

Next... the gentoo instructions told me to unmount the drive and issue the syslinux cmd.

    > sudo umount /mnt/usb
    > sudo syslinux /dev/sdd1
    syslinux: Command not found.

syslinux? wtf! Turns out syslinux was not installed on my system. The gentoo guide makes it sound like this is just a normall cmd. I guess it isn't. You can find a copy of it here:

Pick a version, unpack it, cd into the dir and make it.

NOTE: Remember back when we were trying to put the MBR onto the flash drive.  If you can't get `install-mbr` to work there is a copy of an mbr.bin file located in this package.  You should be able to find in the mbr/ dir of the package root.

 Then make install it. Yay now we have syslinux and we can do this...

    > sudo syslinux /dev/sdd1
    sh: mcopy: command not found
    syslinux: failed to create ldlinux.sys

mcopy? wtf! Apparently because we are doing a bunch of stuff on a msdos partition with FAT16 the regular linux cp is not sufficient for some of the actions of the syslinux cmd. mcopy is part of the mtools package which can be found here:

Pick a version unpack it and make it. For some reason when I ran make... it just made the mtools inside the extracted package dir. Which through me for a loop in the beginning but ended up just running the syslinux cmd from within that dir and everything worked out.

    > sudo syslinux /dev/sdd1

And you're done!

Now... pull the drive, plug it into the machine you want to boot. make sure the BIOS is set to read the usb first and you be golden!

No TrackBacks

TrackBack URL:

Leave a comment

About this Entry

This page contains a single entry by published on March 6, 2009 11:00 AM.

Linux on my new laptop? was the previous entry in this blog.

sphinx is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.


Powered by Movable Type 4.23-en