Create a Kickstart netinstall with CentOS

November 22nd, 2009 by Crazy Leave a reply »

After looking on the internet after a good kickstart guide, there was not one that helped me set up everything from start to end.

I’m not one that likes to read allot. So after 10minutes together with Google the road to ‘the perfect kickstart’ started.

This is what the target was:
- Mount a small iso, about 10mb big
- Automatically start the installation
- Use all the settings that are predefined (disk/language/…)
- Install the packages, the target was a basic install + some extras
- Do some post install things

The test environment was two virtual machines, one kickstart server, the place where the kickstart config, rpm’s and post install scripts are located and a second virtual machine that will do the kickstart.

To start the installation an iso file is needed that will start using the kickstart file located on the server.
I used the CentOS 5.3 i386 net install ISO as a basis for this.
So download it from somewhere, for example:

cd /tmp
wget http://ftp.belnet.be/packages/centos/5.3/isos/i386/CentOS-5.3-i386-netinstall.iso

Now mount it by doing something similar to:

mkdir -p /cd/
mount -o loop -t iso9660 /tmp/CentOS-5.3-i386-netinstall.iso /cd/

Now copy the contents to a new location where the new iso file will be created:

mkdir –p /tmp/centos5.3_kickstart
cp –R /cd/* /tmp/centos5.3_kickstart

Now the isolinux.cfg file needs to be modified to start the installation with our kickstart config, this is the one I use:

default linux
prompt 0
timeout 1
 
display boot.msg
F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg
 
label linux
  menu label Crazy's Manga CentOS 5.3 Kickstart(32bit)
  menu default
  kernel vmlinuz
  append initrd=initrd.img ks=http://kickstart.crazytje.be/CentOS-5.3_i386-Kickstart.cfg text

Be setting the prompt to ‘0′ and timeout to ‘1′ the install is started right away.
The last line makes it so that the installation is started with the kickstart file located on the network:

append initrd=initrd.img ks=http://kickstart.crazytje.be/CentOS-5.3_i386-Kickstart.cfg text

Make sure this config is accessible for the machine you are kickstarting, so replace the part after ‘ks=’ to the location of your own kickstart config.

Once edited, the new ISO can be created, this is done with the following command:

mkisofs -o CentOS-5.3_i386-Kickstart.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -T .

Now that we have the ISO, the next step is the kickstart server and kickstart config.

The ISO is only needed to start the installation and get the kickstart file. Everything after that does not require any intervention of the ISO. This makes it easy to manage a large number of kickstarts. It’s not needed to notify everyone to use a new kickstart ISO, just change the config on the kickstart server and anyone that kickstarts will get the new set of instructions. Anyone with vi can do it :)

So let’s start setting up our kickstart server, first we need the rpm’s.
Because we’re going for a minimal install it’s not needed to copy or download all the rpm’s. The first CentOS 5.3 CD will be enough.
Other possibilities are using the dvd or rsync to get the latest version of a repository.

In this case, I downloaded this one:

cd /tmp
wget http://ftp.belnet.be/packages/centos/5.3/isos/i386/CentOS-5.3-i386-bin-1of6.iso

Now mount the ISO:

umount /cd
cd /tmp
mount -o loop -t iso9660 CentOS-5.3-i386-bin-1of6.iso /cd/

Create a world accessible directory, for example a web server and copy over the images and rpm directories:

mkdir –p /var/www/html/kickstart/centos/5.3/i386/
cp –R /cd/CentOS /var/www/html/kickstart/5.3/i386/
cp –R /cd/images /var/www/html/kickstart/5.3/i386/
cp /cd/repodata/comps.xml /var/www/html/kickstart/5.3/i386/

Now that we have the rpm’s and images, lets create the kickstart config file, I’ll give you mine as example:

## i386 kickstart config  installation
key d6dbc277d6578dc2
# Install OS instead of upgrade
install
# Use CDROM installation media
cdrom
# Network information
network --device eth0 --bootproto dhcp
# Repository Location
url --url=http://kickstart.crazytje.be/centos/5.3/i386/
#Root password
rootpw --iscrypted $1$rB3lJzDT$PmMFJJiLgVPbnvJF6UZ1x/
# Firewall configuration
firewall --disabled
# SELinux configuration
selinux --disabled
# System authorization information
authconfig --enableshadow --enablemd5
### Language Specification
lang en_US
langsupport en_US
# System keyboard
keyboard us
# System timezone
timezone --utc America/Chicago
# System bootloader configuration
bootloader --location=mbr --driveorder=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype ext3 --size=200
part pv.1 --size=2000 --grow
volgroup VolGroup00 --pesize=32768 pv.1
logvol swap --fstype swap --name=LogVol01 --vgname=VolGroup00 --size=384 --grow --maxsize=768
logvol / --fstype ext3 --name=LogVol00 --vgname=VolGroup00 --size=1024 --grow
# Run the Setup Agent on first boot
firstboot --disable
# Installation logging level
logging info
 
%packages
## groups
@base
@core
-anacron
-autofs
-yum-updatesd
-wireless-tools
-irda-utils
-nfs-utils
-NetworkManager
 
## editors
vim-enhanced
vim-common
 
## Webserver
httpd
httpd-devel
 
# PHP
php
php-devel
php-gd
php-mysql
php-pear
php-xml
php-xmlrpc
php-pecl-Fileinfo
 
#pecl and various
libxml2-devel
libxml2
perl-libwww-perl
 
#mysql
mysql
mysql-devel
mysql-server
 
#perl
perl-HTML-Parser
perl-DBI
perl-Net-DNS
perl-Digest-SHA1
 
# Mail
fetchmail
 
## Tools
#compilers
gcc
gcc-c++
 
#web
curl
curl-devel
wget
openssl
 
#compression
bzip2
unzip
zip
 
#other
ntp
 
#development
#subversion
phpmyadmin
 
%post
chvt 3
cd /tmp
wget http://kickstart.crazytje.be/centos/5.3/i386/postinstall.sh
bash postinstall.sh > /root/postinstall.log
chvt 1

The kickstart configuration file has a couple of sections.
The first are the settings used by the installer, that includes network configuration, where it can find the repository, firewall configuration, language settings and partition information.
Make sure to change the “url –url=http://kickstart.crazytje.be/centos/5.3/i386/” to your own repository location.
The root password in this config is ‘today12′. It’s passed encrypted with “rootpw –iscrypt”.

The second part is a list of packages the installer will install.
I include two groups, core and base, minus some small packages. Below that you’ll see allot of tools specific for a web server. Because this is was intended to be a test server for building websites.

For each package you add to the list, make sure to include it in the rpm’s directory ‘/var/www/html/kickstart/centos/5.3/CentOS/’.
The first cd downloaded in the beginning does not contain most of these.

The last part, is the post install. Most of the time this will be a script that is downloaded onto the machine. In the case of a web server, copy over a tar with php and apache settings for example. When you do not want a post install script, just delete everything below the %post.

Once your kickstart config is done and all your packages have been added to the CentOS(rpm) directory, we’ll run a test to check all of the dependencies:

mkdir –p /tmp/testdb
rpm --test --dbpath /tmp/testdb/ -Uvh /var/www/html/kickstart/centos/5.3/i386/CentOS/*.rpm

Most likely more rpm’s will have to be added. Keep adding them until there are no more dependencies missing.

Once the test succeeded, we can create a repository:

cd /var/www/html/kickstart/centos/5.3/i386/
createrepo -g comps.xml /var/www/html/kickstart/centos/5.3/i386/

That was it!, at least to start off.
When deploying for a larger group(this was only for myself), it might come in handy to add your own repository to yum(/etc/yum.repos.d) and copy over all the rpm’s from another up to date repository instead of a cd. That way the rpm’s are the latest version.

After this, mount the ISO, sit back, and enjoy the ride :)

Advertisement

Leave a Reply

You must be logged in to post a comment.