[CentOS] Creating a USB Flash Installation Drive

Fri Oct 21 14:48:18 UTC 2005
Aleksandar Milivojevic <alex at milivojevic.org>

Quoting Karanbir Singh <mail-lists at karan.org>:

> nethub at gmail.com wrote:
>> With the decreasing price of USB Flash Memory Drives, I was 
>> wondering how I would go about creating a USB Flash Drive that could 
>> be used the same as CD 1 to install CentOS on my servers.
>
> While you can boot from the USB Key, install from the usb key is not 
> supported directly under anacoda. What you might need to do is ( if 
> you have a 2.5 gig USB Key ), copy the install media onto the usb 
> key, and then manually mount that under /mnt/sources at the right 
> time.

I guess doing "linux askmethod" and then selecting hard drive (where 
hard drive
is USB key) might work too.  Never attempted that though.  For minimal 
install,
copying first CD might work.  Also making "custom" insatallation tree 
containing
only RPM packages he needs might work too (see
http://www.linuxjournal.com/article/6473 for details, it's for RH8, see
comments section for changes needed for more recent distros).

> you need to  get the diskboot.img file from the /images directory on 
> CD1 ( or on mirror.centos.org/centos/4/os/<arch>/images/ ) and copy 
> that onto the key ( eg. dd if=diskboot.img of=/dev/sdc ). reboot the 
> machine, select boot from usb in the BIOS. And you are done.

Not so fast.  There's no "standard" organization of data on USB key that every
BIOS will recognize and boot.  The most common are:

- emulate big floppy
- emulate USB HD
- emulate USB ZIP

Most will boot from "big floppy" type of USB key.  Majority support USB ZIP
(kinda complicated to make, see below).  USB HD is a bit more rare to find
(well, at least in my rather limited experience).  I guess most BIOS
manufacturers simply don't really care about booting from USB key (or USB
devices in general)

I'll use /dev/sdc in examples, change this to whatever device your USB 
key is!!!

The "Big floppy" USB key is what Karanbir described.  No partitions on 
USB key,
you just dd the image to the master device (for example /dev/sdc).  
This is the
least usefull configuration of the USB key, since you will be 
dedicating it for
doing your installs (no point in storing your data on something you are going
to flush from time to time).

For BIOSes that support booting from USB HD.  You would use fdisk to create
partition(s) on USB key (fdisk /dev/sdc), make one of them bootable, flush the
image onto it (for example /dev/sdc1).  In some cases you would need to use
syslinux to install MBR onto /dev/sdc.  When making partitions, and if 
you plan
to use your USB key on Windows too, note that Windows will detect all 
partitions
on USB key, but it will refuse to access file systems on anything but 
partition
1!?.  It's just one of the Windows stupidities, you learn to live with it.

For BIOSes that support booting from USB ZIP.  This is the most complicated to
prepare (at least for general case and/or if you have picky BIOS).  Much like
USB HD, but you must have very special USB key organization.

First zero out any garbage you might have in first few blocks of you USB key
(and you really want to do this, or your USB key might fail to boot after you
go thruogh all the trouble preparing it).  dd if=/dev/zero of=/dev/sdc 
count=10
will do the job.  You need to use expert mode of fdisk to change number of
"heads" to 64 and number of "sectors/track" to 32.  These numbers are 
from real
ZIP diskettes, and this is what your BIOS will expect to find.

Calculate how many cylinders you'll need (you must change this if you change
number of heads or sectors/track).  See output of dmesg or check messages file
to see how many blocks your device has and then make calculus based on 
that. For example, my Kingston reports "SCSI device sdc: 1006592 
512-byte hdwr
sectors (515 MB)".  That gives 1006592/64/32 = 491.5, round down to 491
cylinders (do not round up, you'll exceed the device size).

Back to normal mode, and create partition 4.  The partition 4 must be at the
beggining of the disk (cylinder 0).  Again, this is how real ZIP 
diskette looks
like, and your BIOS expects to find.  Some BIOSes don't care if this partition
is not entire USB key (so you can create partitions 1, 2, and/or 3 
after it for
some other purposes).  Do not make this partition bootable (some BIOSes don't
recognize it as USB ZIP if you do, some will even choke if there's syslinux in
MBR, some simply don't care).  Finally, dd the image to this partiton (example
/dev/sdc4) and hope it will boot.

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.