Search in uioop.blogspot.com

Blog Archive

Thursday, March 24, 2011

[Linux] How to Set Up a USB Key to Install CentOS

Source from: http://wiki.centos.org/HowTos/InstallFromUSBkey

" src="http://wiki.centos.org/wiki/modern-CentOS/img/attention.png" title="" height="15" width="15"> Some of the Alternatives at the bottom are preferred by other users.

The procedure has been tested with multiple installs but may not cover all eventualities. Let the installer beware.

Motivation

Many recent systems, particularly netbooks and small notebooks, may not have a CD or DVD drive and a network install may be difficult, impractical, or impossible, depending on network connectivity and installer support for the available network hardware. This procedure allows a CentOS install without network connectivity and with no media other than a bootable USB device and the target system disk.

Prerequisites

  1. A target system for the installation that supports booting from USB media. This may need to be configured in the BIOS setup.
  2. A USB key with sufficient capacity to hold the installation media - also known as: memory stick, flash drive, thumb drive, etc. CentOS 5.4 i386 should fit on a 4GB drive, x86_64 requires more than 4GB, a minimal install from CD#1 should be possible with a 1GB drive. The same technique should be usable with a USB hard drive. It is assumed that this procedure is being performed in a GUI (GNOME/KDE/etc.) environment so automounting of the USB media will be performed.
  3. A working Linux system (probably another computer with Linux installed, running from a live CD, or in a Virtual Machine) with syslinux ("yum install syslinux" or install using the native package manager for the distribution, if not already installed). The author encountered problems using the CentOS-5.3/5.4 syslinux package. The package supplied by the CentOS LiveCD Tools repo worked.

  4. A set of CentOS installation CD ISO images, or DVD ISO image, for the desired architecture.

It may be necessary to change device names, architecture, and/or syslinux paths to match your installation distribution, situation, and preferences.

Use caution when copying/pasting commands below to adjust for your situation!

Procedure

Assume the USB key shows up as /dev/sdg (adjust for your situation - will likely be different) and CentOS 5.4 i386 is being installed.

  1. Become root. Create a small VFAT partition (10 MB should be sufficient) and a big Linux one on the USB media. Make the VFAT partition active.

    fdisk /dev/sdg
    In fdisk use "m" to see the the menu options. The sequence of commands goes something like the following (without "#" comments):
    d # delete existing partition - repeat as necessary
    n # new partition
    p # primary
    1 # partition number
    # take the default
    +10m # add 10 MB
    t # change the type
    1 # partition number
    b # VFAT
    n # new partition
    p # primary
    2 # partition number
    # take the default
    # take the default
    a # toggle bootable flag
    1 # partition number
    w # write to disk
    Should look something like this when done:
    Disk /dev/sdg: 7948 MB, 7948206080 bytes
    81 heads, 10 sectors/track, 19165 cylinders
    Units = cylinders of 810 * 512 = 414720 bytes
    Disk identifier: 0x00000000

    Device Boot Start End Blocks Id System
    /dev/sdg1 * 1 65 26320 b W95 FAT32
    /dev/sdg2 66 19165 7735500 83 Linux
  2. Make the filesystems:
    mkfs.vfat -n BOOT /dev/sdg1
    mkfs.ext2 -m 0 -b 4096 -L DATA /dev/sdg2
    Unplug/plug the USB media. The partitions should mount under /media/BOOT and /media/DATA.
  3. Copy the CentOS ISO[s] to the ext2 partition. For CD ISOs:
    cd /dir/of/iso/images
    mkdir /media/DATA/centos
    mkdir /tmp/cdimage
    mount -ro loop CentOS-5.4-i386-bin-1of6.iso /tmp/cdimage
    cp *sum* /media/DATA/centos
    for i in 1 2 3 4 5 6; do cp -v CentOS-5.4-i386-bin-${i}of6.iso /media/DATA/centos/; sync; done
    cd /media/DATA/centos
    grep of6 sha1sum.txt | sha1sum -c - CentOS-5.4-i386-bin-?of6.iso
    For DVD media replace the "for" loop above and the next two lines with
    cp -v CentOS-5.4-i386-bin-DVD.iso /media/DATA/centos/; sync
    cd /media/DATA/centos
    grep DVD sha1sum.txt | sha1sum -c - CentOS-5.4-i386-bin-DVD.iso
  4. Install and configure syslinux on the VFAT partition and MBR:
    syslinux -s /dev/sdg1
    dd if=/usr/share/syslinux/mbr.bin of=/dev/sdg
    cd /media/BOOT
    cp -rv /tmp/cdimage/isolinux syslinux
    mv syslinux/isolinux.cfg syslinux/syslinux.cfg
    rm -f syslinux/isolinux.bin
    umount /tmp/cdimage
    syslinux/syslinux.cfg
    Add to the "append" statements in the various sections:
      method=hd:sda2:/centos
    To use kickstart:
      ks=hd:sda2:/ks.cfg method=hd:sda2:/centos
  5. Use the GUI to "Safely Remove" the USB media. Move to the target system, boot and install.

Notes

  • For general information see the Installation Guide.

  • During testing of this procedure some MicroSDHC media failed to work and got write errors for all iso images, even after repartitioning and reformatting. Another similar piece of media from a different manufacturer worked fine. If errors are encountered try different media, or reformat and try again. The Windows (unfortunately - sorry) SDHC Formatter has proven very useful for non-cooperative SD media. Use the full format option with erase and size adjustment, not the quick option.

    Format type - FULL(Erase ON)
    Format size adjustment ON
  • It may be necessary to use the CD ISOs because the DVD image has been reported by some to be corrupted on the USB key. Both the CD and DVD images worked for the author.
  • Attempting to install with the USB media write-protected generates numerous errors about the media being write protected. Did not try an install after those warnings.

" src="http://wiki.centos.org/wiki/modern-CentOS/img/attention.png" title="" height="15" width="15"> During installation, make sure that the Anaconda installer writes the boot record to the correct location and not to the USB key. It will probably be necessary to use "Advanced bootloader options" for GRUB and change the device order so the target boot device shows up at the top of the list to assure proper GRUB installation. If this is not done the GRUB bootloader will be written to the USB key, making it unusable without restoring the syslinux MBR, and the system unbootable. If you do find yourself in this predicament, see the TipsAndTricks/ReinstallGRUB article, and/or have a look at SuperGRUB.

  • Using extlinux rather than syslinux may be preferable as that eliminates the need for a FAT partition.

Thanks to John Doe in the following CentOS Users mailing list post for the basic material: http://lists.centos.org/pipermail/centos/2009-June/077860.html


Additional comments from the OP: Hum, my bad... I am myself using a kickstart file and I forgot I had to use the following line in it (and I use HP raid controlers):

 bootloader --driveorder=cciss/c0d0,sda --location=mbr

For the kickstart, I use the following:

  • In syslinux/syslinux.cfg:

append initrd=initrd.img ks=hd:sda2:/ks.cfg method=hd:sda2:/centos

  • In /media/DATA/ks.cfg (in their respective sections):

  harddrive --partition=sda2 --dir=/centos
ignoredisk --drives=sda
bootloader --driveorder=cciss/c0d0,sda --location=mbr

And, to be honest, I should not really get credit for this; I found most of the info on the web... _

And I also reported earlier that:

  1. My server HP does not seem to want to boot on a write protected USB key.
  2. Anaconda tries to fetch the ks.cfg too early... If, once the detection is over (just 2-3 seconds later), I retry, it works.
  3. There is an error message "cannot mount read/write, will mount read-only" (I like to write protect)

Alternatives

A forum user recommends this procedure.

UNetbootin has both Windows and Linux executables and allows you to create bootable Live USB drives for a variety of Linux distributions, including CentOS. There is a current anaconda bug that may render the media unusable.

A CentOS ML member recommends Pendrivelinux.com.

Yet another procedure for Building an install disk on a USB key.

An alternative approach if no network is available is to boot from diskboot.img on a USB key as documented in the Installation Guide and do a hard disk install with ISO images on the target computer.

No comments:

AVG Internet Security 2013

Total Pageviews

Contributors