The Fubra Blog

Unattended linux installation

This blog post what written on Wednesday 9th April 2008 by who has been working for Fubra. Our staff are encouraged to blog on this site, but the views expressed are individual and do not necessarily represent those of Fubra.

If you ever had to do multiple linux installations you know how laborious it can be. At times like this you may have wondered if it would be possible to carry out a fully automatic linux installation. Fortunately it is not only possible to prepare a fully hands-off installation, but also a one that does not require any discs. You can read how to perform a network installation on Paul’s blog, while in this post we will concentrate on making the installation fully automatic. Having a configuration described on Paul’s blog such installation is fairly easy to set up. There are four things we will have to do:

  • Prepare a kickstart file
  • Save the kickstart file in a place accessible for the installer
  • Prepare an installation source
  • Modify the PXE config so it instructs the kernel to use the kickstart file

1. Kickstart file is a text file which contains a set of instructions/answers for the linux installer so it automatically knows the answers to all the questions normally asked during the installation process (for example, what partition the system should be installed on, what file system is to be used, what are the network settings, what packages are to be installed etc.). You can either use a special tool called Kickstart Configurator (different for every distibution) which will generate a kickstart file for you after answering a set of questions, or create it from scratch yourself. The latter allows you to become familiar with the structure of this file, as well as is the only choice if there is no Kickstart Configurator for your linux distribution. An example kickstart file (which you can use as a template) for a CentOS distribution may look like this:

# System language
lang en_GB
# Language modules to install
langsupport en_GB
# System keyboard
keyboard uk
# System mouse
mouse
# Sytem timezone
timezone Europe/London
# Root password
rootpw root-password
# Reboot after installation
reboot
# Use text mode install
text
# Install OS instead of upgrade
install
# Use Web installation
url --url http://192.168.1.2/distros/centos5.1-iso
# 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 / --fstype ext3 --size 1 --grow
part swap --recommended
# System authorization infomation
auth  --useshadow  --enablemd5
# Network information
network --bootproto=dhcp --device=eth1
network --bootproto=dhcp --device=eth0
# Firewall configuration
firewall --disabled
# SELinux configuration
selinux --disabled
# Do not configure XWindows
skipx
# Package install information
%packages --resolvedeps
%post

I am not going to describe each of these options separately as they are all pretty obvious and intuitive. More in detail descriptions as well as the list of all available options can be found here. In short, the above kickstart file will install CentOS from web, without XWindows system, creating 3 ext3 partitions. If you want to use this file for installing other linux distributions you need to take into account that some options may be slightly different. If this is the case you should use an appropriate Kickstart Configurator or find an example kickstart file suitable for your distribution.

2. Once we have a kickstart file we need to make it available for the installer.
There are a few ways to do that. We can put the file on ftp, www or nfs server. We can even store the file directly inside the initrd.img file, so it is accessible for the installer the second the image gets expanded in the memory, although this is the most troublesome way. The most common and easiest way is to put the kickstart file on a www server.

3. Installer has to know where to obtain the packages once the installation process is started. You can choose from a few installation sources: nfs, ftp, http. Again, web installation is the most convenient option. Looking back at our kickstart config you can see that we provided a path to the centos directory:

url --url http://192.168.1.2/distros/centos5.1-iso

The directory is simply the content of a CentOS installation disc. If the only thing you have is an ISO file of the installation disc you can still make use of it by mounting the image on a desired directory. To do so you need to run the following command:

mkdir /var/www/distros/centos5.1-iso
mount -oloop,ro /path/to/centos-iso-file.iso /var/www/distros/centos5.1-iso

After that you should be able to browse the content of the image by entering the directory.

4. The last step is to modify the pxe config. Let us look at the CentOS label that we already have:

LABEL centos5.1
     KERNEL distros/centos5.1/vmlinuz
     APPEND initrd=distros/centos5.1/initrd.img ramdisk_size=6454 ip=dhcp

There are two other options that we need to append to the kernel to make it use our kickstart file. The first one is ‘ks’ which is a path to the kickstart file. In our case it will be:

ks=http://192.168.1.2/distros/kickstart.ks

and the other is ‘ksdevice’ which specifies what network interface should be used in order to retrieve the kickstart file. We may specify interface name like ‘eth0′ or ‘eth1′ however this is not a very handy solution. When you have a server with multiple interfaces you cannot be sure what interface you are actually using. Connecting network cable to the first port on your NIC does not necessarily guarantee that the kernel will recognize this interface as eth0. In such a situation the installer will not be able to retrieve your kickstart file. To avoid this, we can specify ‘bootif’ as the ksdevice. This will make the installer use the interface that we booted from. For this option to work, we also need to add ‘IPAPPEND 2′ option just above the ‘APPEND’ string.

To sum up, the modified label should look like this:

LABEL centos5.1
KERNEL distros/centos5.1/vmlinuz
IPAPPEND 2
APPEND initrd=distros/centos5.1/initrd.img ramdisk_size=6454 ip=dhcp nofb ksdevice=bootif ks=http://192.168.1.2/distros/kickstart.ks

One thing to note here is that the bootif option is not supported by all installers. Therefore if you are having problems with loading your kickstart file, try to specify the exact interface (bearing in mind that the first interface on your NIC does not have to be eth0 interface).

Tags: , , , ,

Comments

One Response to “Unattended linux installation”

  1. Ok, not that I really looked at this for debian. However would you find that this kickstart aproach wouldn’t work for a netinstall iso?

Leave a Reply