Howto Kickstart a Linux installation
What is Kickstart?
Kickstart is a function that gives you the ability to install a complete operating system based on a predefined list (kickstart file). Whenever you install an operating system on Red Hat Enterprise Linux, CentOS, Fedora or another Red Hat based Linux distribution, your installation choices are automatically recorded in a kickstart file called "anaconda-ks.cfg". This file is located within the home area of the root user: /root/anaconda-ks.cfg.
If you take a look at this file after an installation has been carried out, you will see that it reflects the entries that were entered during the installation. These entries would be installation type (new installation/upgrade), locale settings for keyboard and timezone, Networking information such as dhcp or static, disk partitioning information, package selections and much more. Many of these options we will cover in more detail.
The main function of the kickstart file is to give an administrator the ability to carry out network installations of Linux quickly. Another advantage is that you can create servers based on a proven build (standard build configuration). This functionality is very useful if you have to create a lot of servers of the same build frequently. You can even specify commands to be run after installation, such as the creation of new accounts. The normal method of using a kickstart file is to locate the file from an exported nfs directory or make it available via a web server, however, other options are available. We will cover the process involved for using nfs and a web server in the following examples.
In the examples that follow I will be using VirtualBox as my testing environment and CentOS 6.5 as the Linux Operating System. Here I will create a single server that will act as a nfs server and web server for our installations. It is this server that will contain the customized kickstart configuration files. Below are the instructions for creating the nfs/web server configuration used in this example.
Minimal Build - NFS/Web Server
For the server that will contain our kickstart files I have chosen to go with a minimal build. A video link is available that indicates how the VirtualBox environment has been defined. In this example this server will be called kicks01. I have given the server 1 CPU, 512MB of Memory and a Virtual Disk of 8GB in size. For networking I have gone for a Bridged connection. The Bridge connection will allow my server to communicate with other servers on the same network. This server will then obtain its IP address automatically via DHCP.
The installation images used in this example can be downloaded from the following location: CentOS Downloads For the build of the minimal server, I will be assuming that you have installed a basic server configuration previously. If not, refer to the video link as a quick overview of the process involved.
Install Minimal Server
Define VirtualBox Machine
Specify No of CPUs, Memory, size of Virtual Disk and Network type of Bridged
Amend hostname - Added kicks01
Edit /etc/sysconfig/network-scripts/ifcfg-eth0 - Change onboot to yes
Reboot - Server to check our changes - shutdown -r now
Check Access to network/Repositories - yum repolist
Check IP Address - ip a s
Install NFS Components
Install NFS components
yum install nfs-utils nfs-utils-lib -y
Check the status of the rpcbind daemon
service rpcbind status
Start rpcbind daemon
service rpcbind start
Set rpcbind to start automatically at system reboot
chkconfig rpcbind on
Check status of NFS
service nfs status
service nfs start
Set NFS to start automatically at system reboot
chkconfig nfs on
Specify location of our NFS export. Add an entry into /etc/exports
Create the directory kickstart
cd /;mkdir kickstart
Install Web Server
Install Web Server
yum install httpd -y
Start Web Server
service httpd start
Set Web Server to start automatically at System reboot
chkconfig httpd on
For the purposes of the following examples I have chosen to disable SELinux and Flush out the default firewall rules. However, in a real environment you would probably need to configure firewall access and modify your SELinux settings. For more information regarding these see the iptables and SELinux Introduction
To set SELinux to Permissive mode, issue the following command: setenforce 0 and issue the command iptables -F to flush out any rules defined within the firewall.
Video Overview of Creating a Minimal Build Server with NFS and Web Server components
Kickstart file created from the above installation
Below is the "anaconda-ks.cfg" file that was created during the installation of our nfs/web server. The kickstart file is generally broken down into multiple sections. An explanation of the main sections can be found here: Kickstart - Keywords
[root@kicks01 ~]# cat /root/anaconda-ks.cfg # Kickstart file automatically generated by anaconda. #version=DEVEL install cdrom lang en_US.UTF-8 keyboard uk network --onboot no --device eth0 --bootproto dhcp --noipv6 rootpw --iscrypted $6$s5ULtB6RfHZCYLn$ZsT4sylGgZHu9SYo5SFUBql9dyaeyXnyS.elp8RIWbI12FHk7hl58tj8evdO1VW4jMVsQr3nYNkXJrMdFPRR60 firewall --service=ssh authconfig --enableshadow --passalgo=sha512 selinux --enforcing timezone --utc Europe/London bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet" # The following is the partition information you requested # Note that any partitions you deleted are not expressed # here so unless you clear all partitions first, this is # not guaranteed to work #clearpart --linux --drives=sda #volgroup VolGroup --pesize=4096 pv.008002 #logvol / --fstype=ext4 --name=lv_root --vgname=VolGroup --grow --size=1024 --maxsize=51200 #logvol swap --name=lv_swap --vgname=VolGroup --grow --size=819 --maxsize=819 #part /boot --fstype=ext4 --size=500 #part pv.008002 --grow --size=1 repo --name="CentOS" --baseurl=cdrom:sr0 --cost=100 %packages --nobase @core %end
Creating a Server from a kickstart file
Now that we have a server that can be used for either a NFS or Web Server installation, we can place our customized kickstart (ks.cfg) file into the /kickstart directory that was created earlier or it can be placed into the DocumentRoot directory of our web server /var/www/html
Kickstart Using NFS
For the example that follows a customized kickstart file has been created called ks.cfg. This file has been copied into the /kickstart directory we created earlier. This kickstart file contains custom partition information and specifies that we will be using a static IP address.
Once you have created this file, you will need to make sure the file can be read. To achieve this we can issue the command:
chmod +r ks.cfg (This command adds the read attribute to the file, thus allowing anyone to read the file)
# Custom Kickstart file #version=DEVEL install cdrom lang en_US.UTF-8 keyboard uk # Static IP addressing Information network --device eth0 --bootproto static --ip 192.168.0.47 --netmask 255.255.255.0 --gateway 192.168.0.1 --nameserver 192.168.0.1 --hostname kicks02 rootpw --iscrypted $6$s5ULtkM6RfHZDYLn$ZsT3sylGfWHu8SYo5SFUBql9dbacyXnyR.elp8RIWbI21FHk7hl62tj8evdO1VW7jMVsQr1nYPkXJrMdFPRR60 firewall --service=ssh authconfig --enableshadow --passalgo=sha512 selinux --enforcing timezone --utc Europe/London bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet" #Custom Partition Information zerombr clearpart --all --drives=sda #################################### part /boot --fstype ext4 --size=500 part swap --size=1024 part pv.01 --size=1000 --grow --ondisk=sda volgroup vg00 pv.01 logvol / --vgname=vg00 --fstype=ext4 --size=2048 --name=lv_root logvol /var --vgname=vg00 --fstype=ext4 --size=1024 --name=lv_var logvol /tmp --vgname=vg00 --fstype=ext4 --size=512 --name=lv_tmp %packages --nobase @core %end
Create a VirtualBox Definition for the New Server
Before we proceed, we first need to create a machine/server definition for the new server that we are going to create. Here we will specify that we are using a single CPU, 512MB of Memory, a 8GB Virtual Disk and a Bridged Network Connection. The machine definition name will be the same as the hostname specified in the kickstart file. (kicks02)
Once the machine has been defined to VirtualBox, we will use the same iso image to install our server. The following video below will guide you through the process that is involved.
Now when we initiate our installation, at the installation screen, we will need to specify the location of the remote ks.cfg file that will be used. To specify this you will need to press "Escape" at the initial installer menu, this will then take you to a "boot: prompt. In this example our kickstart file is residing on a server with the IP address 192.168.0.26 in a directory called /kickstart.
So from the boot prompt we enter the following information:
This command specifies that the location of the kickstart file ks.cfg can be found on a NFS mount at IP address 192.168.0.26 within a directory called /kickstart.
Once this command has been entered, you should have no further involvement during the installation. Our network information and partition information will be used to build our server. Once the installation has completed, remember to remove the installation media! before rebooting. Below is a Video overview of this process. You will notice that there is no manual intervention during the installation.
Video Overview of Creating a Minimal build server Using a NFS mounted kickstart file
Kickstart using a webserver
The process of using a webserver is almost the same as that of the NFS installation. The main difference here is that we copy the kickstart configuration file to the root document directory. You can confirm this location on your web server by looking for the line "DocumentRoot" within the following configuration file: /etc/httpd/conf/httpd.conf
By default the DocumentRoot is : "/var/www/html
Extract from: /etc/httpd/conf/httpd.conf
# # DocumentRoot: The directory out of which you will serve your # documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations. # DocumentRoot "/var/www/html"
Once the file has been placed into the default DocumentRoot area, you can use a browser to confirm that the file is available by typing the IP address of our remote server along with the path to the ks.cfg file: 192.168.0.26/ks.cfg
You should now see that your ks.cfg file has been displayed. If not, check that your web server is running by using the following commands:
service httpd status - Displays whether web server is running or not
service httpd restart - Restarts web server
service httpd stop - Stops web server
service httpd start - Starts web server
Create a definition for the new server within VirtualBox
Again we are going to use the same specification of 1 CPU, 512MB of memory and a 8GB Virtual Disk with a Bridged Network connector. We are now going to amend the kickstart file to change the hostname and the IP address to be used. In this example, the IP address has been set to 192.168.0.48 and the hostname has been set to kicks03.
Once these changes have been made to our ks.cfg file, we can initiate the installation process.
Again as before, we need to press "Escape" at the installation screen to take us to a boot prompt. This time we are going to specify that we will be carrying out an installation using a web server. To do this we need to specify the following at the boot prompt:
Here we are instructing the Anaconda installer to use a web server at the specified IP address and to use a file called ks.cfg from its root directory.
Video Overview of Creating a Minimal build server Using a Web Server
For an overview/explanation of the keywords used within these examples take a look at Kickstart Keywords.
To install and use a GUI (Graphical User Interface) for the creation and editing of kickstart files take a look at Kickstart GUI.
For basic partitioning examples using LVM see Partitioning.
As newer versions of Red Hat are shipped, certain commands will become deprecated and newer options will appear. The best place to keep track of these changes is to visit the official Red Hat documentation pages. These can be found at: Red Hat Documentation