A Kickstart CD for sipX on CentOS
From SIPfoundry sipx, The Open Source SIP PBX for Linux - Calivia
[edit] Introduction to Using Kickstart
[edit] Introduction
This page is about how to create a single boot CD installation for sipX. It is based on CentOS 4 and we are using the kickstart technology included with CentOS and Fedora to script the Anaconda installer. In addition to creating an automated install, this page also describes how to create a custom distribution of CentOS that includes only the needed RPMs including the sipX RPMs and all necessary dependencies. The distribution fits on one CD and is self-contained resolving all its dependencies. No network connection is required to install it.
[edit] Installing Necessary Tools
The scripts required to perform all the necessary operations are part of the CentOS / Fedora distribution.
yum install anaconda-runtime createrepo yum-utils anaconda anaconda-help busybox-anaconda mkisofs
CentOS / Fedora also provides a graphical tool that allows creating and editing kickstart configuration files. This might be useful and is mentioned here for completeness. The description below is focused on manually editing the config files as this is almost easier than using a graphical tool. Start it by choosing Applications → System Tools → Kickstart. (Or: /usr/sbin/system-config-kickstrart).
yum install system-config-kickstart
Red Hat Anaconda Project: Anaconda Project
Manual: RHEL4 Kickstart Manual
[edit] Create a Working Copy of the CentOS Installation Disk
We are using CentOS 4 to start with. Only CD 1 is required as we are interested in a customized minimal installation. Mount the CD and copy its content to a working directory:
mkdir centos-cd1 cd1 sudo mount /dev/cdrom centos-cd1 rsync -a centos-cd1/* cd1 cp centos-cd1/.discinfo cd1 sudo umount centos-cd1
[edit] Create a Kickstart Configuration File - ks.cfg
The most important file is the kickstart configuration file (ks.cfg). This file has to be copied to the root directory of the new CD. It provides all the parameters to Anaconda for an automated installation, determines what packages to install and allows some post installation scripts to be executed.
| File: ks.cfg |
################################################## ### ### Kickstart configuration file ### for SIPX distribution CDs ### ################################################## #--- Installation method (install, no upgrade) and source (CD-ROM) install cdrom #--- Debugging (uncomment next line to debug in the interactive mode) #interactive #--- Language and input support lang en_US.UTF-8 langsupport --default=en_US.UTF-8 en_US.UTF-8 keyboard us mouse generic3ps/2 #--- X-Windows (use "skipx" directive to skip X-Windows configuration) skipx #--- Authentication and security rootpw --iscrypted $1$nIbsWYcm$AJ3Dm/kvbhDP3f30j2EKy/ firewall --disabled selinux --disabled authconfig --enableshadow --enablemd5 #--- Time zone timezone America/New_York #--- Boot loader bootloader --location=mbr #--- NON_RAID Disk partitioning (LVM) zerombr yes clearpart --all --initlabel part /boot --fstype ext3 --size=128 part swap --size=1024 part /recovery --fstype ext3 --size=1024 part / --fstype ext3 --size=4096 part /var --fstype ext3 --size 1 --grow #--- Reboot the host after installation is done reboot #--- Package selection %packages --resolvedeps e2fsprogs grub kernel ntp sipxpbx sipxproxy-cdr sipxconfig-tftp sipxconfig-ftp #--- Pre-installation script %pre #--- Post-installation script %post #!/bin/sh #...Disable the utility 'cpuspeed'. If run the VIA C3 Nehemia processor based systems will crash #/sbin/service cpuspeed stop #chkconfig cpuspeed off #chkconfig irqbalance off #...Make copy of installation CD to the "/recovery" partition /sbin/start_udev /sbin/chkconfig --del smartd &> /dev/null mkdir /recovery/linux mkdir /tempdir mount /dev/cdrom /tempdir cp -a /tempdir/* /recovery/linux cp -a /tempdir/.discinfo /recovery/linux umount /tempdir rm -rf /tempdir #...Create initial setup script to run one time (after initial reboot only) cp /recovery/linux/sipx_reset_cd /root/sipx_reset_cd chmod u=rwx /root/sipx_reset_cd echo -e "\n/root/sipx_reset_cd\n" >> /root/.bashrc # the script removes itself from the root .bashrc file when it completes #...Install new splash image cp /recovery/linux/splash.xpm.gz /boot/grub |
Note: Using CentOS 4 on a VIA C3 Nehemia processor: Make sure to use the i586 kernel. Also, the process cpuspeed needs to be stopped and disabled (/sbin/service cpuspeed stop & chkconfig cpuspeed off). Otherwise the VIA C3 system will crash anytime cpuspeed tries to throttle the CPU back. An excellent description of this problem is here.
[edit] Creating a Custom Installer
Next we want to create a custom installer including our own splash screen and boot options. The file isolinux.cfg tells the grub bootloader where to look for the kernel. It should be familiar to you as it is identical to the common grub/grub.conf file.
| File: cd1/isolinux/isolinux.cfg |
default sipx prompt 1 timeout 0 display boot.msg F1 boot.msg F2 options.msg F3 general.msg F4 param.msg label linux kernel vmlinuz append initrd=initrd.img ramdisk_size=8192 label memtest86 kernel memtest append - label sipx kernel vmlinuz append initrd=initrd.img ramdisk_size=8192 ks=cdrom:/ks.cfg |
The file isolinux.cfg specifies that the splash screen to be displayed before starting the boot process is called boot.msg:
| File: boot.msg |
^L ^Xsplash.lss Press <ENTER> to start the installation. WARNING: All data will be erased and the disk is formatted. ----------------------------------------------------------- Root password is "pingtel". ^O02[F1-Main] [F2-Options] [F3-General] [F4-Kernel]^O07 |
Note: Adapt the other files options.mgs, general.msg, param.msg to your liking.
[edit] Changing the splash.lss File
The splash.lss file is the splash file that displays in the very first screen after the machine restarts and presents the user with the boot options. This file is in the directory /isolinux. An excellent description of how to do this is here.
First Step: Create an image file of the format 640 x 220 pixels using The Gimp. Downsample the color depth to 14 colors. This is done in GIMP by going to ->Image->Mode - select "indexed". Then save the file in the PPM format in RAW mode.
Second Step: The created .PPM file needs to be edited. Using an editor open the file and remove the 2nd line where it says that GIMP created this file. The next step does not handle comments in PPM files.
Third Step: Using ppmtolss16 convert the file to .lss;
./ppmtolss16 '#c0cfc0=7' <image.ppm >splash.lss
Fourth Step: Copy the file splash.lss to the /isolinux directory.
Additional Notes on Downsampling Color Depth in GIMP: Our target number of colors is 16. However, consider setting this to 15 or 14 to save one or two slots in the index table for one or two text colors. Alternatively, you can select suitable text colors from your resulting image and use them in your boot.msg (or whatever your welcome screen text is called).
In The Gimp indexing dialog, you can also select an appropriate palette optimization method. For images originating in photos with a large number of color shades use one of the Floyd-Steinberg dithering methods. This produces mellow random noise in the resulting image, greatly reducing the effects of low color depth. If you have a flat-color company logo, choose "no dithering" - your company colors will be slightly shifted but clean.
Please note that if you're already in indexed mode, e.g. as a result of loading an 8bpp GIF as a master image of your splash screen, you need to swich to RGB mode first and then back to indexed in order to get to the index generation screen, to get the palette down to 16 colors. The color palette can be checked using [context menu]->dialogs->indexed palette.
[edit] Changing the Splash Image displayed by Grub (splash.xpm.gz)
- Start the GIMP.
- Click on File->New or type Ctrl+N
- In the new image dialog, change Width to 640 pixels and Height to 480 pixels. (The image should be of size 640x480 pixels.) Now click OK.
- Create the image which you would like to be the splash image. It's quite fun to experiment with the various tools of the GIMP!
- After you have finished creating the image, hit Alt+i or right click on the image and click on Image->Mode->Indexed...
- In the Indexed Color Conversion dialog that appears, click on the radio button "Generate optimal Palette" and in "# of colors" enter 14. Click OK.(The image should be of only 14 colors)
- Now right-click on the image and click on File->Save As...Save the file as splash.xpm in a directory of your choice.
- Now open a terminal window and navigate to the directory where you have saved splash.xpm
- Now key in gzip splash.xpm
- You will find that a file named splash.xpm.gz is created in the directory where splash.xpm used to exist.
- Copy this splash.xpm.gz to the /boot/grub directory. You may want to back up the pre-existing splash.xpm.gz file in the /boot/grub directory first.
[edit] Customizing Anaconda
Anaconda is the program that provides all the installation services and displays all the graphics during the installation process. It is included in the directory cd1/CentOS/base in a file called stage2.img. An excellent explanation of how to edit this image manually can be found here.
[edit] Understanding Package Metadata
CentOS 4, like Fedora Core 3, ships with 5 different encapsulations of the RPM package metadata:
- comps.rpm
- hdlist and hdlist2
- yum .hdr files in the headers directory
- rpmdb-CentOS or rpmdb-fedora
- repodata (xml-metadata)
There is a lot of redundant data here and Red Hat and the Fedora community are working on consolidating this in future releases. Possible consolidation could look like this, which would leave us with just repodata eventually.
- The yum .hdr files should be able to go away after FC3
- comps.rpm is only used for system-config-packages. It includes comps.xml, hdlist and hdlist2
- The hdlists are used only by anaconda. It should get migrated to use the repodata files for installs
- rpmdb-CentOS or rpmdb-fedora. This is used by 'rpm --redhatprovides', 'rpm --aid' and 'rpm --redhatrequires' for querying what was in the original installation tree.
The objective would be a single metadata type in the installation media. As long as we still have several types of metadata, we need to create them when customizing the distribution.
[edit] Changing the Graphics displayed by Anaconda
The following describes a crude way of changing the artwork used by Anadonca during the installation process. They cleaner way would be to use buildinstall to create a new installer. In this case we start with an existing installer and modify it.
The image of the Anaconda installer can be found in cd1/CentOS/base. The image file is called stage2.img. We will now mount this image so that we can look inside.
mkdir ~/anaconda mount -o loop cd1/CentOS/base/stage2.img ~/anaconda
Now we need to copy the contents to a directory where we can alter the files. A simple cp command was claimed to not work because of some hard links included in the image. For this reason we use tar to package the contents of the directory and then untarred them where we could work on them.
cd ~/anaconda tar -cvf ~/stage2.tar . cd ~ mkdir stage2 cd stage2 tar -xvf ../stage2.tar
Now we can alter the images used by the installer located in usr/share/anaconda/pixmaps and the images used in the installation slideshow in usr/share/anaconda/pixmaps/rnotes. You can also edit the text in the left sidebar, which is in HTML format, in usr/share/anaconda/help/[locale].
After you've made the desired modifications, we need to compress this information back into an .img file.
cd ~ mkcramfs stage2/ stage2.img.new
Then, copy the altered stage2.img to the CentOS/base directory.
cp stage2.img.new cd1/CentOS/base/stage2.img
[edit] Creating a Customized CentOS Distribution
The next steps describe how to create a customized distribution of CentOS that includes only the packages we want and their dependencies. This is the most time consuming step as it is an iterative process where you select packages and then test for dependencies until all dependencies are resolved.
[edit] Choose the appropriate RPMs to be in CentOS/RPMS
This is the most difficult step. It involves selecting a set if RPMS that comprise all the necessary elements for Linux to install and boot. In addition it requires all the RPMS required for a sipX system. In addition, all the dependencies have to be resolved. And lastly, its size must not exceed what can fit onto a single CD.
We started with the first CD of the CentOs 4 distribution. The list of RPMs we deleted is long.
In addition, it is possible to update the RPMs to their latest patch level which makes it unnecessary to run yum update after the system is installed.
[edit] Test if all dependencies for all the RPMs in CentOS/RPMS are resolved
The following test is absolutely crucial. Inevitably once you start removing or adding RPMs to the repository, you will have to make sure that all dependencies are resolved properly. Once the test below passes, you have succeeded to create a self-contained repository that will install properly.
cd ~ mkdir testdb rpm --initdb --dbpath $PWD/testdb rpm --test --dbpath $PWD/testdb -Uvh cd1/CentOS/RPMS/*.rpm
[edit] Create repodata using createrepo
cd cd1 createrepo --baseurl="media://1142383043.889895" -g CentOS/base/comps.xml CentOS/RPMS/
Note: Make sure the number in --baseurl corresponds to the first line in the file cd1/.discinfo. Should you have trouble with this command try using absolute path names.
[edit] Create hdlist and hdlist2
cd cd1 export PYTHONPATH=/usr/lib/anaconda export PATH="$PATH:/usr/lib/anaconda-runtime"
# Write CentOS/base/hdlist and hdlist2: genhdlist --hdlist /home/test/cd1/CentOS/base/hdlist --productpath CentOS /home/test/cd1
Note: Absolute path names are required for the command genhdlist to work properly.
[edit] Create a Package Order File
The package order determines the order by which RPMs are installed by Anaconda. This order matters as RPMs only install if all the required dependencies are already installed on the system. The command pkgorder in a recursive process calculates the correct package order.
cd cd1 pkgorder /home/test/cd1 i386 CentOS > /home/test/cd1/pkgorder.txt
[edit] Run genhdlist again, this time with package order
Now that we have the proper package order calculated we can create the final hdlist files for Anaconda to use:
genhdlist --withnumbers --fileorder /home/test/cd1/pkgorder.txt \ --hdlist /home/test/cd1/CentOS/base/hdlist --productpath CentOS /home/test/cd1
[edit] Create the ISO Image
cd ~ mkisofs -R -J -T -no-emul-boot -boot-load-size 4 -boot-info-table -V "sipX 3.4" \ -A "Created on 8/6/2006" -P "SIPfoundry" -p "SIPfoundry" -b isolinux/isolinux.bin \ -c isolinux/boot.cat -x "lost+found" -o sipx.iso cd1 Optional: /usr/lib/anaconda-runtime/implantisomd5 sipx.iso
The ISO image can now be burnt to a CD for test.
[edit] Some Additional Tricks
[edit] Running Anaconda Using a Repository on Harddisk
We are still working on finding out how the created recovery partition can be used to restore the system without needing a CD-ROM drive. Using the command line below, anaconda can be started to use the repository in the recovery partition. However, the difficulty still is that anaconda itself will run out of the current installation, which it is supposed to restore.
anaconda --kickstart=ks.cfg --text --rootpath=/tmp --method=nfs://i386
[edit] chroot Installation
I personally dislike this since it installs too many packages you'll never need (cups, freetype and even xorg-x11-Mesa-libGL! welcome to dependancy hell). yum resolves dependancies, so this builds a _minimal_ system where you can do networking, ssh-login, editing with vi and install everything you need via yum:
#!/bin/bash
RPM_INSTALL_CHR=chroot
echo " --> Setting up chroot env in $RPM_INSTALL_CHR"
if [ `id -u` = "0" ] ; then
mkdir -p $RPM_INSTALL_CHR/etc $RPM_INSTALL_CHR/dev $RPM_INSTALL_CHR/proc \
$RPM_INSTALL_CHR/sys $RPM_INSTALL_CHR/var/tmp $RPM_INSTALL_CHR/var/cache/yum
touch $RPM_INSTALL_CHR/etc/fstab
mknod $RPM_INSTALL_CHR/dev/null c 1 3
chmod 666 $RPM_INSTALL_CHR/dev/null
mount --bind /proc $RPM_INSTALL_CHR/proc
mount --bind /sys $RPM_INSTALL_CHR/sys
rpm --root $PWD/$RPM_INSTALL_CHR --import http://fedora.redhat.com/about/security/4F2A6FD2.txt
rpm --root $PWD/$RPM_INSTALL_CHR -Uvh --nodeps --force ftp://ftp.linux.ncsu.edu/pub/fedora/linux/core/5/i386/os/Fedora/RPMS/fedora-release-5-5.noarch.rpm
# yum -y --installroot=$PWD/$RPM_INSTALL_CHR groupinstall "Base"
yum -y --installroot=$PWD/$RPM_INSTALL_CHR install yum rootfiles bind-utils crontabs passwd anaconda
umount $RPM_INSTALL_CHR/proc
umount $RPM_INSTALL_CHR/sys
else
echo " *** Sorry, you must be root to setup a chroot environment"
exit 1
fi
mkdir -p $RootDir/{etc,dev}
cat > $RootDir/etc/fstab <<EOF /dev/sda1 / ext3 defaults 1 1 none /dev/pts devpts gid=5,mode=620 0 0 none /proc proc defaults 0 0 none /sys sysfs defaults 0 0 none /dev/shm tmpfs defaults 0 0 EOF
# at least /dev/null must be present before "yum install" for i in console null zero ; do MAKEDEV -d $RootDir -x $i ; done
# beware: this mounts $RootDir/proc!
yum --installroot $RootDir -y install yum rootfiles bind-utils gnupg \
mailx openssh-server vim-enhanced vixie-cron crontabs passwd
mv $RootDir/lib/tls $RootDir/lib/tls.disbled
chroot $RootDir # now personalize & configure your VM exit # exit the chroot
umount $RootDir/{proc,}
[edit] References
- http://directory.fsf.org/All_Packages_in_Directory/kickstart.html
- http://kickstart-tools.sourceforge.net/howkickstartworks.html
- http://www.exmachinatech.net/01/novi/examples/
- http://www.linuxdevcenter.com/pub/a/linux/2004/11/04/advanced_kickstart.html
- http://www.users.on.net/~rgarth/weblog/fedora/patch_cd.autumn
- http://fedora.redhat.com/docs/fedora-install-guide-en/fc5/sn-automating-installation.html
- http://www.redhat.com/docs/manuals/linux/RHL-9-Manual/pdf/rhl-cg-en-9.pdf
- http://download.fedora.redhat.com/pub/fedora/linux/core/4/i386/os/images/
- http://www.users.on.net/~rgarth/weblog/fedora/karsten.htm
- http://www.redhat.com/archives/kickstart-list/2005-September/msg00030.html
- http://syslinux.zytor.com/faq.php
