Search This Blog

Wednesday, February 18, 2009

Steps to make sipx installation cd with centos (command line)


This document is about how to create a single boot CD installation for sipX. It is based on CentOS 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 document 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.

2. 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



  • yum install system-config-kickstart




    1. 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




    1. 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.

Save as File: ks.cfg
####################################################
### Kickstart configuration file
### for sipXecs 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

#--- Network configuration
# Add some default or else Anaconda will pop a window and ask
network --device eth0 --bootproto static --ip 192.168.5.176 --netmask 255.255.255.0 --gateway 192.168.5.1 --nameserver 192.168.5.145 --hostname sipx.example.com

#--- Authentication and security
rootpw setup
firewall --disabled
selinux --disabled
authconfig --enableshadow --enablemd5

#--- Time zone
timezone America/New_York

#--- Boot loader
bootloader --location=mbr



#--- Partitioning
# The user will be prompeted to perform this step
#--- Reboot the host after installation is done
reboot

#--- Package selection
%packages --resolvedeps
e2fsprogs
grub
kernel
ntp
dhcp
bind
caching-nameserver
gdb
strace

# Used for SF build
sipxpbx
sipxconfig
sipxacd
sipxconfig-agent
sipxconfig-report
sipxvxml
sipxproxy
sipxregistry
sipxpublisher
sipxproxy-cdr
sipxconfig-tftp
sipxconfig-ftp
sipxtools

#--- Post-installation script
%post

#!/bin/sh


#...Mount the installation CD
/sbin/start_udev
/sbin/chkconfig --del smartd &> /dev/null
mkdir /tempdir
mount /dev/cdrom /tempdir

#...Setup initial setup script to run one time (after initial reboot only)
echo -e "\n/usr/bin/sipx_reset_cd\n" >> /root/.bashrc

# the script removes itself from the root .bashrc file when it completes
#...Place a copy of the RAID restore script in /sbin
cp /tempdir/restore-raid-drive /sbin/restore-raid-drive
chmod u=rwx /sbin/restore-raid-drive

#... Add logon message
echo -e "\nWelcome to Coral IPPBX\n" >> /etc/issue
echo -e "=============================\n" >> /etc/issue
echo -e "\nFirst time logon: user = root password = setup\n\n" >> /etc/issue

#... Boot kernel in quiet mode
sed -i 's/ro root/ro quiet root/g' /boot/grub/grub.conf

# Install SIPfoundry sipX repository and key
rpm --import /tempdir/RPM-GPG-KEY-sipX
cp /tempdir/sipx-fc.repo /etc/yum.repos.d

#...Install new splash image
cp /tempdir/splash.xpm.gz /boot/grub

#... Prevent it from being overwritten when upgrading the system using yum update
chmod 444 /boot/grub/splash.xpm.gz

#...Prevent sipxpbx from starting after first reboot as it is not yet configured
chkconfig sipxpbx off

# Postgresql will be started by sipxpbx
chkconfig postgresql off


# Turn off unused services that listen on ports
chkconfig portmap off
chkconfig netfs off
chkconfig nfslock off

# Make a backup copy of the CD if there is a /recovery partition
if test -d "/recovery" ; then
mkdir /recovery/linux
cp -a /tempdir/* /recovery/linux
cp -a /tempdir/.discinfo /recovery/linux
fi
umount /tempdir
rm -rf /tempdir
eject


Note: Make sure to use the i586 kernel. Also, the process cpu speed 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.

2.3 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 coraltele
prompt 1
timeout 0
display boot.msg
F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg
F7 snake.msg
label linux
kernel vmlinuz

append initrd=initrd.img ramdisk_size=8192
label memtest86
kernel memtest
append -
label coraltele
kernel vmlinuz
append initrd=initrd.img ramdisk_size=8192 ks=cdrom:/ks.cfg quiet

The file isolinux.cfg specifies that the splash screen to be displayed before starting the boot process is called boot.msg:

File: cd1/isolinux/boot.msg
^L
^Xsplash.lss

Press to start the installation.

WARNING: All data will be erased and the disk is formatted.
-----------------------------------------------------------
Root password is "coraltele".
^O02[F1-Main] [F2-Options] [F3-General] [F4-Kernel]^O07

Note: Adapt the other files options.mgs, general.msg, param.msg to your liking.

2.4 Changing the splash.lss File


The cd1/isolinux/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 given below:

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' splash.lss

Fourth Step: Copy the file splash.lss to the /isolinux directory.
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.



    1. 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 below:

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



3. Choose the appropriate RPMs to be in CentOS/RPMS




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.

3.1 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




    1. 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.

3.3 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.

3.4 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


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

4. 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

5 comments:

  1. Excellent post, helped me to copy files from the cd during the kickstart process.

    marc

    ReplyDelete
  2. Hi Vikas, How are you? I am Rahul Panwar "Coral"
    Remember!
    I am doing the same for our Servers in CentOS 5.4. I didn't use "createrepo" command. I manually edit the comps.xml file & create a custom group. i added all the packages in that group. Then add that group to ks.cfg file but after adding that group in ks.cfg i m receiving some error that cd is unmounted from /mnt/??? place.
    Do you know where is the problem? Is it mendatory to use createrepo command?

    Thanks for add this topic in your blog, it helps me a lot? :)

    ReplyDelete
  3. Hi Rahul im fine and U?
    Ofcource, i do remember u.

    createrepo commnad creates/updates comps.xml file.

    There may be some violations in comps.xml, as ur manually editing it. Any wrong rpm in file, or wrong entry in ks.cfg may lead to this problem.


    Use createrepo once, compare xml file then...
    look this post
    "Creating repo of sipX rpms using comps.xml and then writing to dvd"

    Gud Luck.

    ReplyDelete
  4. Hey thanks buddy,
    it works after creating repo.
    Actually i was changing the comps.xml file only but the information of group (added in comps.xml) need to add in repo databse.
    You can see the link http://createrepo.baseurl.org/

    Sorry for late response i was little busy on some other projects as usual ;)

    Please note down my email id if you want to contact me sometime.
    panwar.rahul@gmail.com

    I want to ask you one more question:
    Did you know about the preparation of a linux filesystem from scratch??

    ReplyDelete