256
Logo

Customized RedHat Linux Kickstart Installation Cdrom

Copy CDs to Disk    Trim Packages    Kickstart    Make CD    Troubleshooting    RedHat 8
My customized files: Makefile    boot.msg    comps    ks.cfg    syslinux.cfg

The following document has been created because I've not been able to find a suitable alternative. Certainly there are numerous pages on how to install RedHat Linux using kickstart, but there are nuggets of information here that I still have been unable to find documented elsewhere about making custom boot CDs.

First things first. If you use the following procedures, please consider buying an official copy of RedHat Linux. You can usually get a copy for close to US$50 and I feel strongly that it is important to support the cause.


So I wanted to customize the RedHat installation CD which came with their 7.2 release. I wanted to:

  1. Automatically partition and install Linux on the system
  2. Specify a list of RPMs to install
  3. Execute a set instructions at the end of the install to customize the virgin system.
  4. Do it all on one (1) CD.

To help with some of the below instructions, I have written a Makefile.

Copying the Cdroms to the Hard-disk

First thing to do is to copy the 2 CDs to your harddrive. You will be modifying configuration files and boot images, and then writing a new CD from this directory. You will need at least 1.4gb free for this operation.

  1. # Load the first CD into the drive
  2. mount /mnt/cdrom
  3. mkdir /somepath/cdrom_files
  4. cd /mnt/cdrom
  5. tar -cf - . | ( cd /somepath/cdrom_files ; tar -xvpf - )
  6. cd /somepath/cdrom_files
  7. umount /mnt/cdrom
  8. # Load the second CD into the drive
  9. mount /mnt/cdrom
  10. cd /mnt/cdrom/RedHat/RPMS
  11. tar -cf - . | ( cd /somepath/cdrom_files ; tar -xvpf - )
  12. cd /somepath/cdrom_files
  13. umount /mnt/cdrom

Trimming Down the Packages

The next stage of the process is to trim down the list of packages until you get below the 700mb that will fit onto one CD. In general, I sorted the RedHat/RPMS directory by size and started at the top and moved down removing the rpms that I knew I did not need. You need to be careful here because there are dependencies between packages that aren't always expected.

Checking RPM Dependencies

To check for dependencies, you can use the following commands. If you have my Makefile installed, you can enter make depend to do this.

mkdir /tmp/testdb
rpm --initdb --dbpath /tmp/testdb
cd cdrom/Redhat/RPMS
rpm --test --dbpath /tmp/testdb -Uvh *.rpm
rm -rf /tmp/testdb

I'm not positive on what output from these commands to watch for which insures a "correct" list of RPMs but if you get any "is needed by" messages, they definitely need to be fixed before you can cut your CD. You will get two different types of dependencies. A certain number will be extraneous packages which you can remove because they are not needed on your CD. If you remove a package you might create other dependency problems, so make sure you run the above commands multiple times until you get no "is needed by" messages. However, others dependency errors will be RPMs that you want to install however can't because they depend on other packages. You will have to add to the RPMS directory the RPMs which satisfies these dependency problems. Make sure to remake the hdlist after adding or removing any RPMs.

If you get no "is needed by" lines and you get to the "Preparing" message with a progress bar then I think this means that you are good to go. It also seems like the 143 error code is okay while 144 and 145 are bad and need to be fixed.

NOTE: It may take a couple of cycles of adding packages, resolving dependencies, trimming packages to make more space for new packages, etc..

Comps File

In the RedHat/base directory on the 1st CD is the comps file which is what anaconda reads when it displays the various packages of RPMs. It is also used used by the %packages section of the ks.cfg file. An example the comps file is:

4

1 Base {
  MAKEDEV
  anacron
  ...
}


0 --hide Network Server {
  @ Network Support
  (arch !i386): vnc
  finger-server
  ? X Window System {
    i386: compat-libstdc++
    libpcap
  }
  ...
}

The leading 4 is the version number of the file. The 1 Base { defines a collection of RPMs associated with the Base package. The 1 means that it is enabled by default. The 0 --hide Network Server { defines the Network Server package which is off by default. The --hide means that it should be hidden from the user's package selection tool in anaconda.

Here is my version of the comps file. I don't think that I edited it at all although you may need to if you have specific package requirements that don't map well into the Base and other standard package collections.

The @ Network Support line means that the Network Server package includes the Network Support package. The (arch !i386) line allows certain packages to be installed if (or in this case if not) installing on specific architecture. The ? X Window System { line means that if X windows is installed then the packages in subsection are included in Network Server package.

In any case, by looking at this file, you can see which RPMs you use when you install a Network Workstation and which ones are candidates for removal if you don't install X11 stuff. Again, be careful because there are dependencies, often obtuse, which may require packages that you would not expect.

NOTE: you should not need to include RPMs that you have in your directory because of dependencies in the comps file. They should be loaded automatically.

Rebuilding the hdlist File

After you have trimmed down your packages, it has been recommended that you use the anaconda-runtime tool check-repository.py (located in the /usr/lib/anaconda-runtime/ directory) to check the comps file. This utility checks to make sure every package listed in the comps file is present in the RedHat/RPMS/ directory. If there are no errors the installation should not fail. Thanks Vito!

If you have removed RPMs from the directory, you will need to rebuild the hdlist file which lists which RPMs are available on the first CD. I think it assumes that if it is not on the first CD then it must be on the second one. You will need to build the genhdlist utility which should be included in the anaconda source release.

ftp://ftp.redhat.com/pub/redhat/redhat-7.2-en/os/i386/SRPMS/anaconda-7.2-7.src.rpm

In the utils directory in the source tarball, should be the genhdlist.c which should be buildable with make genhdlist. Once you have the utility you can chdir into your unpackages CD directory and type:

genhdlist --withnumbers --hdlist RedHat/base/hdlist `pwd`

If you have my Makefile installed, you can enter make hdlist to do this. I'm not sure what the --withnumbers does and it may not be necessary. At some point I was trying to fix a warning message that I saw. If you rebuild the hdlist file, make the CD, and try to install and it prompts for the 2nd CD in the set then you probably missed a dependency. See the section on how to resolve dependencies.

Kickstart

RedHat Linux (maybe others) has a built in automatic installation system called kickstart. For more details see the good documentation on the RedHat site. The Anaconda installation program uses the ks.cfg configuration file to automatically perform the installation. Here's a taste:

timezone America/New_York
rootpw _foobarbaz_
part /boot --fstype ext3 --size 52 
firewall --medium --ssh 

The previous excerpt from my ks.cfg file sets the timezone to EDT, sets the root password, creates a 52mb /boot partition on the disk, and enables a medium strength firewall which allows in ssh connections.

Here is the full ks.cfg file that I use. There are a post script section at the end of the file which you can use to do any localized configurations such as adding accounts, enabling sudo, starting ntp, disabling the sendmail init.d script, etc..

WARNING: if you are not careful, you can blow away an entire system in seconds with kickstart on an installation CD. It is designed to be fast and efficient and it will repartition your drive very quickly if you aren't careful.

NOTE: to enable kickstart installation you have to tune the kernel options in the syslinux.cfg boot config file.

Installing Kickstart File onto the CD

So I just got a message from a user who was able to get the ks.cfg to work on Redhat Enterprise 3 just by putting it in the root of the CD #1 and adding the ks=cdrom to the boot options. This means that you may not have to put the ks.cfg file inside of the cdrom boot image as described below. Not sure on what other versions this works for.

It took me a couple of tries to find the proper place to put my ks.cfg so that it would be seen by the installer. On the cdrom there is the dosutils/autoboot/cdboot.img file which is a 2.88mb floppy image. This floppy is what the cdrom uses to boot. It contains the bootstrap information, initial kernel, and file system to load. The ks.cfg file needs to be placed in the /tmp directory in the memory filesystem, which happens to be a gziped ext2 filesystem -- seriously.

Here are the steps needed to copy the ks.cfg file onto the CD. If you have my Makefile installed, you can enter make ks to do this.

  1. mount -o loop /somepath/cdrom_files/dosutils/autoboot/cdboot.img /mnt/floppy
  2. # decompress the memory filesystem on the floppy
  3. gzip -dc /mnt/floppy/initrd.img > floppy.initrd
  4. mkdir /tmp/redhat
  5. # mount the compressed filesystem from the floppy
  6. mount -o loop floppy.initrd /tmp/redhat
  7. # install the ks.cfg file into the /tmp directory on the memory filesystem
  8. install -c -m 644 ks.cfg /tmp/redhat/tmp
  9. umount /tmp/redhat
  10. gzip -9 floppy.initrd
  11. mv floppy.initrd.gz /mnt/floppy/initrd.img
  12. umount -f /mnt/floppy
  13. rmdir /tmp/redhat

Warning: You need to be careful how much you add to the floppy image so that it does not run out of space.

NOTE: If this doesn't work when you boot, see the top of this section on a different location for the ks.cfg file.

Kernel Boot Options

So now you have edited your kickstart config file and have installed it into the floppy image on the CD. You now need to edit how it boots from the floppy. If you have my Makefile installed, you can enter make editflop to do this.

  1. mount -o loop /somepath/cdrom_files/dosutils/autoboot/cdboot.img /mnt/floppy
  2. $(EDITOR) /mnt/floppy/*
  3. umount -f /mnt/floppy

This mounts the boot floppy image again and edits the directory.

The files in the boot image
boot.msg Initial screen shown by the bootloader
expert.msg Screen you get by pressing F3
general.msg Screen you get by pressing F2
initrd.img Compressed memory filesystem
ldlinux.sys DOS boot loader I suspect
param.msg Screen you get by pressing F4
rescue.msg Screen you get by pressing F5
syslinux.cfg Boot loader configuration file including kernel arguments and options
vmlinuz Linux kernel to load

To get the kickstart to work automatically, you will need to tune the kernel boot parameters in the syslinux.cfg file. You should add the ks=floppy option to allow it to boot with kickstart enabled by pressing enter on the boot screen. This is required to get kickstart working.

My syslinux.cfg file is available, by adding ks=floppy and text and removing the vga=788 I caused it to install by default using the kickstart config file in text mode.

Aside from adding the ks.cfg file to the initrd.img and tuning the boot options, I have also customized the boot.msg file to add my own messages on the initial boot screen (you'll have to figure out the format of the file yourself).

Making the CD

So you have adjusted your RPM list to get below 700mb and remade the hdlist file. You have added your ks.cfg kickstart file with all of your favorite initialization settings and written it into the cdboot.img file. You have also tuned the boot options and boot screen messages. Now you are ready to burn a new CD. Make sure that your CD can hold the files in your cdrom directory. You can redirect the mkisofs command below into a file (or pipe through wc -c) to see how big it is.

If you have my Makefile installed, you can enter make cdr to make a CD-R, make cdrw to make a CD-RW, or make cd_image to make a CD image file. Below are the instructions on how to do this.

  1. You will need the mkisofs and the cdrecord programs.
  2. You may want to do a man on mkisofs and figure out specifically which options you want to use. There are a large number.
  3. You will need SCSI support on your system. If you are trying to get your ATAPI cdrom drive working, you may need to:

    Make sure that the IDE-CD modules are not installed:

    1. rmmod ide-cd
    2. rmmod cdrom

    And make sure that the IDE-SCSI and SCSI-generic modules are installed:

    1. modprobe ide-scsi
    2. modprobe sg
  4. Run (for CD-RW disks):
    mkisofs -b dosutils/autoboot/cdboot.img -l -J -R -r -T \
      -V 'Custom RH Install' . | \
      cdrecord -v blank=fast speed=4 dev=0,0,0 -
    
  5. If you are writing to a CD-R disk, you will need to remove the blank=fast argument to cdrecord.
  6. Notice that it assumes a 4x cdrom (speed=4) which you may want to increase or decrease.

You should be all set. Put your new CD in a computer which can be blown away and reboot it so it boots from the cdrom. Enjoy!

Troubleshooting

  1. When you add an RPM to your CD but do not include all of the RPMs that it depends on, the installation program will fail. As far as I know, it requests CD #2 or crashes with an "an unhandled exception" in anaconda if it detects an unprovided package or file. You may be able to scroll through the exception details and find the package in question. Often if you press Alt-F3 (to switch to another virtual terminal in the text install) you can see which package(s) had problems. See the section on how to resolve dependencies to fix this issue.
  2. If you need to copy files off of the install media to the new installation then you'll need to do something like the following:
    %post --nochroot
    # the --nochroot is necessary to not change root into the new installation
    cp /mnt/source/dir/file /mnt/sysimage/dir/file
    # where /mnt/source is the install media
    # and /mnt/sysimage is the new installation
    

Redhat 8 TIps

Thanks to Arvind Singh for the following notes.

  1. To boot from the CD, ks.cfg has to be put in /tmp of initrd.img as mentioned above. This is true even if you have USB floppy drive.
  2. To have kickstart to get all RPMs from one CD you will need to edit the .discinfo file in the root on each CD. Modify the file to tell it by putting the number of cds. If you have 1 CD then the first line should just contain the number one. If you have 3 CDs then it should be 1,2,3
  3. Modifying the comps.xml file is a pain. It is recommended that you use ks.cfg to install and remove the packages.
  4. In the post section of ks.cfg, anaconda umounts the cdrom. If you need to copy files from the cdrom you have to temporarily mount the cdrom by creating a directory and mounting it as ISO.

    mkdir /tmp/one
    mount -t iso9660 /tmp/cdrom /tmp/one
    cp /tmp/one/yourfiles  /mnt/sysimage/root/
    umount -f /tmp/one
    rmdir /tmp/one
    
  5. Use boot.img to create all kickstarts for CD, floppy, and USB floppy. Use bootnet.img for nfs or http/ftp network installs.
  6. All floppy boot image files are in /images directory of first CD.

Please submit your own feedback about these instructions.

Free Spam Protection   ORMLite Java ORM   Android ORM   Simple Java Magic   JMX using HTTP