Creating a Custom CentOS-5.5 ISO Image

I required a script to customize the installation of CentOS-5.5-x86_64 for minimalist installations in Fedora KVM. I wanted the option to install any type of server while installing as few packages as possible. The following files will create a usable image when created on a CentOS host but each file must be present in the same directory (along with both CentOS-5.5 DVD images) to work properly:
, ks.cfg, comps.xml,

Hope this helps someone out.

This is a step-by-step from the file listed above. This blog only covers the steps relating to the creation of a DVD repository and the creation of an ISO image file. For more information on using the files above, refer to the README file listed above.
##### BUILD THE DVD ######

The first step in creating an istallation repository is to mimic the structure found on the CentOS installation DVD:

# In the current directory, create an iso build directory:
timer “Building iso directory tree”

if [ $burntype == “kickstart” ]; then
mkdir -p ./kickstart_build/{isolinux,images,ks}
mkdir -p ./kickstart_build/{isolinux,images}

***Note the use of the curly braces for grouping of directories; this allows multiple directories to be created on the same branch of the installation tree.

The following directory tree of the Centos-5.5 DVD is going to be re-created in a custom directory, with a hand-picked selection of RPMs:

├── CentOS
├── images
│   ├── pxeboot
│   └── xen
├── isolinux
└── repodata

# Mount the CentOS DVD image, avoid read-only mount error message
mount -o loop ./CentOS-5.5-x86_64-bin-DVD-1of2.iso /mnt > /dev/null 2>&1

timer “Copying files to iso”

This directory contains kernel images that are maps to create directory structures on a new filesystem:

# Copy all the files from the isolinux directory on CentOS disc 1 into your kickstart_build/isolinux directory.
cp -R /mnt/isolinux/* ./kickstart_build/isolinux

The .discinfo file contains information about the installation disc such as release version, arch, number of discs and the location of installation directories. This is the .discinfo file from the CentOS-5.5 DVD:


# Copy .discinfo from the CentOS disc 1 into your kickstart_build/isolinux directory.
cp /mnt/.discinfo ./kickstart_build

This directory contains files that enable a bootable environment for both flash drives (diskboot.img) and cd-roms (boot.iso):

# Copy all the files from the images directory on CentOS disc 1 into your kickstart_build/isolinux/images directory.
cp -R /mnt/images/* ./kickstart_build/images

This file is parsed by the anaconda installer and contains information about software groups. The comps.xml serves as the outline for the package selection menu in the GUI installer, and gives the installer a framework for package selection in a kickstart installation.

# Copy your customized comps.xml to kickstart_build.
cp -f ./comps.xml ./kickstart_build/comps.xml
chmod 644 ./kickstart_build/comps.xml

A kickstart file is not normally found on an installation DVD, this file will enable the iso file to autoinstall according to your specific instructions:

# Your kickstart config file will go into the kickstart_build/ks directory.
if [ $burntype == “kickstart” ]; then
timer “Configuring kickstart files”
cp ./ks.cfg ./kickstart_build/ks/ks.cfg

These files need their permissions changed because the directory structure is READ ONLY; mkisofs will return an error if the filestructure is not read-only:

# Change permissions on 3 files:
chmod 664 ./kickstart_build/isolinux/isolinux.bin
chmod 664 ./kickstart_build/isolinux/isolinux.cfg
chmod 664 ./kickstart_build/ks/ks.cfg

This option uses openssl to insert password hashes into your custom kickstart for both the root and regular user:

# Change the root password in the ks.cfg file
createPassword “Please enter a root password.”
sed -i ‘s/^rootpw .*$/rootpw –iscrypted ‘$passhash’/’ ./kickstart_build/ks/ks.cfg

# Change the user password in the ks.cfg file
read -p “Please enter a username. ” username
createPassword “Please enter a user password.”
sed -i ‘s/^user .*$/user –name=’$username’ –password=’$passhash’ –iscrypted/’ ./kickstart_build/ks/ks.cfg

The next two modifications are necessary to redirect the installer to the kickstart file, otherwise, the installer would use the default GUI installer with user interaction:

# Modify the “isolinux.cfg” file, this is done so that the kickstart runs automatically.
# Change the line: “default linux” to “default ks”
sed -i ‘s/^default linux$/default ks/’ ./kickstart_build/isolinux/isolinux.cfg

# Change the line: “append ks initrd=initrd.img” to “append ks=cdrom:/CentOS-VM-ks.cfg initrd=initrd.img”
sed -i ‘s/^[ ]*append ks initrd=initrd.img$/ append ks=cdrom:\/ks\/ks.cfg initrd=initrd.img/’ ./kickstart_build/isolinux/isolinux.cfg

The createrepo software enables you to build update repositories as well as installation repositories:

# Install createrepo so that you can create a repository.
if [ ! $(rpm -q createrepo) ]; then
yum -y install createrepo

Now that the directory structure is in place and the necessary software is installed on the system, you can load RPMs into the DVD installation repository. Hopefully all the dependencies for RPM packages are resolved for all individual and group entries in your comps.xml file:

# Load RPMs on to new DVD.
timer “Copying RPM files”

if [ ! -d ./kickstart_build/CentOS ]; then
mkdir ./kickstart_build/CentOS

cp -R ./custom_rpms/* ./kickstart_build/CentOS

With all the RPMs in the directory tree, it is time to build the repository from the directory structure that has been created:

# Build repository on the new DVD
timer “Building repository”
cd ./kickstart_build

declare -x discinfo=$(head -1 .discinfo)
createrepo -u “media://$discinfo” -g comps.xml .

cd ../

Returning the status of any changed files to read-only is essential for the successful creation of an iso image file:

if [ $burntype == “kickstart” ]; then
# Change permissions back to default for “isolinux.cfg” and “isolinux.bin”
chmod 555 ./kickstart_build/isolinux/isolinux.cfg
chmod 444 ./kickstart_build/isolinux/isolinux.bin

# Create the iso file.
timer “Building image file”
mkisofs -r -N -L -d -J -T -b isolinux/isolinux.bin -c isolinux/ -no-emul-boot -V “$label” -boot-load-size 4 -boot-info-table  -o “$filename” kickstart_build/

Although this program (in its entirety) will produce a usable image, there are some aspects of the build that I was not able to get working completely:

# Add checksum to iso (not working !!!):
# implantisomd5 ./CentOS-VM.iso

# Record DVD automatically (not tested):
#growisofs -Z /dev/cdrom=./CentOS-VM.iso

umount /mnt

Writing this program forced me to look closely at the booting process for a RHEL-based installation DVD and also gave me some insight into: RPMs, kickstart files, repositories, and xml files. It also spawned the notion to create an update repository for my virtual machine network(s); the process of creating a network repository is quite similar to creating an installation repo.



About gr8can8dian

Certified Linux geek.
This entry was posted in SBR600. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s