Sample ks.cfg with a %post section

Here is an example ks.cfg file like the one I used when I created my custom RHEL 5.3 install DVD. As I learn more about what ks.cfg can do, hopefully I can make it smarter.  I would really like to be able to dynamically detect how much memory a system has, and size swap accordingly. Also, while the eject commands at the end of the file seemed to work on one of my lab machines, they didn’t on another one because the path to the cdrom drive was different.  Possibly I could use /dev/cdrom or /dev/dvd and have better luck.  I’ll be trying that later this week in the lab.

# Kickstart file automatically generated by anaconda.
# 20090904 dsw updated

key –skip
lang en_US.UTF-8
keyboard us
xconfig –startxonboot

rootpw –iscrypted <encrypted password here>

firewall –disabled
authconfig –enableshadow –enablemd5
selinux –disabled

timezone –utc America/Detroit

bootloader –location=mbr –driveorder=cciss/c0d0 –append=”rhgb quiet”

# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
clearpart –linux
part /boot –fstype ext3 –size=256
part pv.14 –size=69194
volgroup vg00 –pesize=32768 pv.14
logvol /var/crash –fstype ext3 –name=lvol9 –vgname=vg00 –size=2048
logvol /0b –fstype ext3 –name=lvol1 –vgname=vg00 –size=43456
logvol /home –fstype ext3 –name=lvol10 –vgname=vg00 –size=512
logvol swap –fstype swap –name=lvol2 –vgname=vg00 –size=2048
logvol /usr –fstype ext3 –name=lvol7 –vgname=vg00 –size=6976
logvol /tmp –fstype ext3 –name=lvol4 –vgname=vg00 –size=1024
logvol /var –fstype ext3 –name=lvol8 –vgname=vg00 –size=4096
logvol /home_local –fstype ext3 –name=lvol5 –vgname=vg00 –size=1024
logvol /opt –fstype ext3 –name=lvol6 –vgname=vg00 –size=6976
logvol / –fstype ext3 –name=lvol3 –vgname=vg00 –size=1024

<lots of packages listed here>

mkdir /mnt/dvd
mount /dev/scd0 /mnt/dvd
mkdir /opt/tools
cp /mnt/dvd/isolinux/EXTRAS/* /opt/tools
umount /mnt/dvd
rmdir /mnt/dvd

# unpack and install whatever tools we can
cd /opt/tools
gunzip -c hptools.tar.gz | tar xvf –

# Two commands because I wasn’t sure which one would work
eject /dev/scd0
eject cdrom

Creating a Red Hat Custom Bootable Install DVD


Log in to server.  Be root.
Place source DVD in tray. (Source DVD is the RedHat install DVD).
Execute “mount” command to figure out path to source DVD.

# mount
(examine output to see what the path is)
(in my case, path is /media/RHEL_5.3 i386 DVD)

# cd /media/RHEL_5.3\ i386\ DVD
(the backslashes are to escape the spaces in the pathname)

# du -sh .
(see how much space will be necessary to recreate this DVD on the server hard drive)

# df -h
(examine output and select a filesystem on the hard drive that has sufficient space to recreate the DVD there)
(on my system, I selected /0b)

# mkdir /0b/iso_tree
(create a working directory on your selected filesystem)

# pwd
(make sure you are in the top-level of mounted DVD)

# tar cvf – . | (cd /0b/iso_tree; tar xvpf -)
(recreate the DVD on your hard drive – should take 10 minutes or less)

Validation Check:
# ls -a /0b/iso_tree
(make sure you see a listing for .discinfo file)
# cd /0b/iso_tree/isolinux
# mkdir EXTRAS
(In my case, I create this subdirectory because I’ve written some code in my custom ks.cfg file which will copy the contents of the EXTRAS subdirectory into a directory on the server, in the post-installation steps)
(We want to put the custom ks.cfg file in the ./isolinux directory, as the deployment guide I’m writing for work expects to find the ks.cfg file there.)
(In my case, I have these files on a USB stick which is attached to my server at the mount point /media/disk)
# cp /media/disk/ks.cfg /0b/iso_tree/isolinux/ks.cfg
# cp /media/disk/tools.tar.gz /0b/iso_tree/isolinux/EXTRAS/tools.tar.gz

Here you can make it interesting, because you can actually put multiple versions of ks.cfg here, and can pretty much name them what you want; later when you go to build a new server, you will specify the path to the ks.cfg file anyway.
Make the custom ISO image file:
Decide what the ISO image will be called.  In my case, I decided to call it “RedHatLinux53-yyyymmdd.iso”, where yyyymmdd represents the year, month, day that I’m creating the file.

# cd /0b/iso_tree
# mkdir /0b/new_iso
(Here you are creating another working directory to put your custom ISO file in – mine needed a little less than 4Gb)

Now you execute the “mkisofs” command to create the custom ISO file.  This command is all on one line.  You might want to put it in a small shell script and execute it that way to avoid typo errors.

# mkisofs -A “Red Hat Linux 5.3” -V “Red Hat Linux 5.3” -J -R -v -T -b isolinux/isolinux.bin -c isolinux/ -no-emul-boot -boot-load-size 4 -boot-info-table -o /0b/new_iso/RedHatLinux53-20090901.iso .

(PLEASE NOTE THE “.” at the end of the command – this stands for “current directory”, don’t forget to put this at the end of the command!)
(Should take around 5 minutes to complete)

Mount the newly created ISO image on the loopback device so you can make sure it will work:

# mkdir /0b/mnt_iso
(here you are creating a mount point)

# mount -o loop /0b/new_iso/RedHatLinux5.3-20090901.iso /0b/mnt_iso
(make sure it mounts ok and you can find isolinux/ks.cfg and isolinux/EXTRAS/tools.tar.gz)

# umount /0b/mnt_iso
Now at this point you want to write the ISO image to DVD.  Being pressed for time at work, I chose not to investigate the options for using the “cdrecord” command on my Linux server to do that.  Instead, I chose to put the ISO file on a USB stick and transfer it over to my PC, then use Roxio to burn a DVD from the ISO image.  So here are the instructions for doing that:

# cp /0b/new_iso/RedHatLinux5.3-20090901.iso /media/disk
(On a slow server, took around a half hour)
# eject /media/disk

Remove USB stick from server and attach to PC.
Use Roxio.  Use DVD-R, as DVD+R etc. has sometimes caused a problem.  Use option to “Burn Image”.  Choose the option to “Verify”.  (Takes about 20 minutes)

Test DVD:
Place DVD in CD tray in the server you want to build.  It should boot from DVD.  At the Linux boot: prompt, type the command which will initiate the install, using the custom ks.cfg found at isolinux/ks.cfg.

On my server, the path to the DVD is /dev/sda1, so this is the boot command I use:
boot: linux ks=sda1:/isolinux/ks.cfg
(NOTE: you don’t have to type “boot:” that is the prompt you will see.)

If all goes well, the installation will carry on and you won’t be prompted for anything.