CentOS 8. Automated installation using Kickstart

2 minute read

First of all if you have never seen a kickstart file before and you have installed a flavor of Redhat Linux on a system go look in the /root dir you should see a file called anaconda-ks.cfg open it up and you will see the parameters you entered during your install in the kickstart file.

It is a good way to understand by example (providing you can remember the options you selected at boot time).

Below I will give you an example of a kickstart file I use it in my work with remote servers. I chose to use a kickstart install with scripts over imaging software for the Linux installs as this enabled me to use the image on various types of hardware and with the tweak of a script I could greatly customize the installs in the future. Lastly I change the configuration (update packages, settings) using Ansible playbooks after I’ve install the system.

Define the Kickstart file

With this kickstart file, we will do the following actions:

  • Define installation source and additional repos (minimal and standart)
  • Define Root Password (see here and here to manual create crypted password)
  • Install the OS from entirely from the network
  • Accept de EULA
  • Establish the timezone and enable NTP time synchronization on the host
  • Format all drives
  • Auto-partition the disk (two parts):
    • /boot part - format ext4 part with 1024MiB size
    • LVM part on full space of disk with next LV:
      • / - 50000 MiB
      • /tmp - 30000 MiB
      • /var/log - 10000 MiB
      • free space - 10000 MiB
  • Remove swap part
  • Disable kdump
  • Skip X Windows packages
  • Activate first network device that linked up

Also I like to add post section with commands that allow remote access to the new system using ssh key file:

%post
/bin/mkdir /root/.ssh
/bin/chmod 700 /root/.ssh
/bin/echo -e 'ssh-rsa AAAAB3Nza.....9WhQ== admin@example.com' > /root/.ssh/authorized_keys
/bin/chown -R root:root /root/.ssh
/bin/chmod 0400 /root/.ssh/*

%end

Starting the Kickstart Installation

Installing CentOS using kickstart is a 3 step process

  1. Create the kickstart file (if you don’t already have one)
  2. Make the kickstart file available to the boot process (e.g. put kickstart file on a web server, e.g. in github like me)
  3. Access the boot prompt during the Centos installation and then tell the boot prompt where your kickstart file is located. Specified by the initrd boot parameter inst.ks=<YOUR_KS_CFG_DESTINATION> where <YOUR_KS_CFG_DESTINATION> should be change to real destination. Press ‘Tab’ button on first boot option to modify initrd boot parameter.

Ultimately you can modify the ISO file and the isolinux/isolinux.cfg and make it autostart and everything, but for this post it just wasn’t the right approach. Also you can run PXE server to automate full installation.

That’s all! Automatic Kickstart installations offer a great deal of benefits for system administrators in environments that they have to perform system installations on multiple machines the same time, in a short period of time, without the need to manually interfere with the installation process.

Additional information