Kickstart Installs From A USB Drive

04 13 2009

When installing a lot of identical or near-identical systems, having an installer answer file makes things go much quicker. By eliminating the need to manually select the same values over and over again, an answer file saves time and minimizes human error. Linux distributions with the Anaconda installer, like RedHat and CentOS, using a kickstart file for this purpose.

The challenge with kickstart files (and other installer answer files) has always been how to provide the file to the installer application. Since the OS media is generally read-only, the file has to be made available somewhere else.

In the olden days, kickstart configuration files were copied onto a floppy. That was simple and easy, but floppies were slow and had limited storage capabilities. As networks got faster, network-based installs became the leading installation method of choice, and floppy disks slowly disappeared from systems.

While network-based installation is still the best choice in most situations, it’s not feasible in situations where you have little control over the network infrastructure. Since floppy drives are extinct, the obvious next choice is to install from a USB drive (flash or hard disk). However, there’s one big gotcha: By default, Anaconda installs Linux onto all available drives, including the USB drive you’re trying to install from. Worse, most kickstart files uses the “clearpart” option, which erases the partition table on all drives, also including the USB drive you’re trying to install from. Not good.

If all your hardware is the same, there’s an easy solution: hard-code the disk drive device name into your kickstart file. That way, Anaconda won’t touch the USB drive you’re installing from. For example, if your target disk drive is /dev/sda:

clearpart –all –drives=/dev/sda –initlabel
part / –fstype=ext3 –size=75 –ondisk=/dev/sda

But what if your hardware isn’t all the same and the target disk drive name varies? Managing multiple kickstart configuration files that are identical except for the disk drive device name is a big headache. There has to be an easier way.

%pre sections to the rescue! The %pre section of a kickstart configuration file contains a script that is run before Anaconda begins the OS installation. At first glance this may seem a bit useless — why run a script before the OS is installed? The answer is that the true power of %pre is to generate parts (or all) of your kickstart configuration dynamically, at install time. In this case, a script in the %pre section can figure out the correct disk drive device to install to, and then generate the appropriate kickstart configuration. For example:

%include /tmp/partitions

%pre
#!/bin/sh

# find the first drive that doesn’t have removable media and isn’t USB
DIR=”/sys/block”
ROOTDRIVE=”"
for DEV in sda sdb sdc sdd sde hda hdb hdc hdd hde; do
  if [ -d $DIR/$DEV ]; then
    ls -l $DIR/$DEV/device | grep -q /usb
    if [ $? -ne 0 ]; then
      REMOVABLE=`cat $DIR/$DEV/removable`
      if (( $REMOVABLE == 0 )); then
        if [ -z $ROOTDRIVE ]; then
          ROOTDRIVE=$DEV
        fi
      fi
    fi
  fi
done

# Check for RAID controller disks
if [ -z $ROOTDRIVE ]; then
  for DEV in c0d0 c0d1 c0d2 c1d0 c1d1 c1d2; do
    if [ -d $DIR/cciss!$DEV ]; then
      if [ -z $ROOTDRIVE ]; then
        ROOTDRIVE=cciss/$DEV
      fi
    fi
  done
fi

cat << EOF > /tmp/partitions
bootloader –location=mbr –driveorder=$ROOTDRIVE
clearpart –all –drives=$ROOTDRIVE –initlabel
part /boot –fstype=ext3 –size=75 –ondisk=$ROOTDRIVE
part / –fstype=ext3 –size=4096 –ondisk=$ROOTDRIVE –asprimary –grow
part swap –size=2048 –ondisk=$ROOTDRIVE
EOF

This %pre section scans for the first non-USB, non-removable-media disk drive on the system, and then dynamically generates the kickstart partition directives hard-coded to that device. This ensures that Anaconda will not install to or erase the USB drive.

One side note: the “removable” flag in Linux is set for devices with removable media (e.g. DVD drives); it is not set for devices that are themselves removable/hot-swappable (e.g. USB drives). This is why the %pre script above checks explicitly for USB devices.


Actions

Informations

One response to “Kickstart Installs From A USB Drive”

05 31 2009

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>