Simple Remastering of RHEL / Fedora / CentOS
By Flib
2009-05-22
Category: Linux
The Problem
It is often the case that you wish to automate some elements of an install CD (or DVD) but don't want to go through all the steps required of doing a complete remaster. What follows is the minimum steps to add (or edit) a couple of files on a CentOS CD.
The Solution
Overview
Remastering doesn't need to be difficult. If you don't need to integrate RPMs transparently into the image, then many steps can be omitted.
At its most simple, the following is all that is needed.
- Copy CD/Image contents to a temporary directory (with hidden files)
- Edit/Add the files in the directory.
- mkisofs with the contents of the directory
Thats it. You can optionally, as a last step, recreate the md5 checksum for the disk and insert it with implantisomd5 from the anaconda-runtime, but its not needed and to be honest, I personally prefer the md5sum the images afterwards so that on download you can check for corruption straight away rather than starting to use the image for an install and finding it corrupt.
The normal aim in my remasters is to add a couple of RPMs (generally extra repos) to the disk to be installed in the %post section of a custom kickstart file. To do this I don't need to touch any of the package manifests or other things that cause complexity in the remastering process. I just create a new directory, dump the files there and edit the isolinux/isolinux.cfg file to add my kickstart files as the default boot option.
The Details
Copying the disk
There are many ways to copy the files from a disk, many of them suffer from missing out any 'dotfiles' on the disk, for example .diskinfo. Without this file the disk wont be recognised as a valid install disk and will the install wont proceed. I'm assuming in the following you either have a real disk or an image loopback mounted on /mnt/CentOS
The easiest method is to use (assuming you are in the destination directory already)
rsync -a /mnt/CentOS .
If you then look at the contents with 'ls -la' you will see we have captured the dotfiles as part of the copy.
Adding / Editing files
I personally prefer to make my changes as superficial as possible to the image and then use a configuration manager such as cfengine or puppet to change the configuration from its default after installation. However your needs are probably very different.
To this end, I will be changing the message displayed on boot to make it obvious that this disk has been touched. This is done by editing /isolinux/boot.msg. You could also change the boot graphic by changing the splash.lss file, but I wont go into that here.
splash.lss
linux - Text mode install with Technomonk Additions (default)
text - Text mode install
graphical - Graphical install
memtest - memtest86
rescue - rescue boot
0f[F1-Main] [F2-Options] [F3-General] [F4-Kernel] [F5-Rescue]07
isolinux/boot.msg
boot.msg and the other message files all may contain special characters for loading graphics and changing colours.
The only essential modification besides adding a kickstart file to the disk if you wish to automate the install is to edit the isolinux/isolinux.cfg file.
default linux
prompt 1
timeout 600
display boot.msg
F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg
label linux
kernel vmlinuz
append initrd=initrd.img text ks=cdrom:/technomonk/ks.cfg
label text
kernel vmlinuz
append initrd=initrd.img text
label graphical
kernel vmlinuz
append initrd=initrd.img
label rescue
kernel vmlinuz
append initrd=initrd.img rescue
label memtest86
kernel memtest
append -
isolinux/isolinux.cfg
Note the default option has been edited. This could also have been accomplished by adding a new entry and changing the default at the top of the file.
The ks=cdrom:/technomonk/ks.cfg argument tells linux to use the kickstart file found in the technomonk subdirectory of the disk. There is nothing to stop you having many seperate kickstart scripts on the disk and associated menu entries. For example, for a LAMP server, for a base install, for a MySQL server etc.
Syslinux, the package that contains isolinux if you want to install it standalone on the server also contains memdisk a utility to allow booting floppy images from a menu such as this. (In fact this is how memtest used to be ran, a memtest floppy image with memdisk bootstrapping it.)
#System language
lang en_GB
#Language modules to install
langsupport en_GB
#System keyboard
keyboard uk
#System mouse
mouse
#Sytem timezone
timezone Europe/London
#Reboot after installation
reboot
#Use text mode install
text
#Install OS instead of upgrade
install
#System bootloader configuration
bootloader --location=mbr
#Clear the Master Boot Record
zerombr yes
#Partition clearing information
#clearpart --all --initlabel
#Disk partitioning information
part /boot --fstype ext3 --size 100
part swap --size 512
part / --fstype ext3 --size 1 --grow
#System authorization infomation
auth --useshadow --enablemd5
#Network information
network --bootproto=dhcp --device=eth0
#Firewall configuration
firewall --disabled
#SELinux configuration
selinux --disabled
#Do not configure XWindows
skipx
#Package install information
%packages
@ text-internet
%pre
%post
#
#custom code removed
#
#
technomonk/ks.cfg
This is a simple kickstart file to automate some of the choices made during install. Everything except the root password is automatically done for you. If the kickstart file was on the network instead of on the disk, you would need to specify a couple of extra arguments in the isolinux file to initialise the network and set your language choices.
Creating the image
Creating the image is pretty simple. The following command executed from the src directory will create an iso file in the parent directory.
# mkisofs -J -T -o ../centos5.3_custom.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -R -m TRANS.TBL .
Thats it. Burn it and test it (or use the image directly in a virtual machine)