Unattended installation of CentOS 7 with Kickstart

While setting up my first Hadoop cluster I faced with the dilemma of how to perform installations of CentOS 7 on multiple servers at once. If you have 20 data nodes to deploy, anything you chose to automate an installation will greatly reduce the deployment time, but most importantly, it will eliminate the possibility of human error (typo for example).

Initially, I started looking at the disk cloning direction. Since all my data nodes are identical, I was thinking to prepare one data node server, then dd the system drive, place it on a NFS share, boot the server and re-image the system drive using dd image from the share. Clonezilla and DRBL seem to be the perfect pair for a such scenario. And although you will spend some time configuring, testing and tuning it, it was still worth to look into it.

Then I realized that even if I manage to establish the setup above, I’ll still have to deal with manual post-installation tweaks, like regeneration of SSH keys and probably adjusting of MAC addresses. On top of that, to transfer raw dd image (in my case it was ~30GB) might take longer than initial installation itself. Therefore I ended up using Kickstart method. I’m pretty sure there are more efficient solutions and if you happen to know one I’d love to hear your comments.

For this to work, you’ll need the following components:

  • a kickstart file, which contains configuration directives. You can either build it yourself or as I did, perform one clean installation and get it from the /root/ directory. In CentOS 7 this file is called anaconda-ks.cfg and it will be generated by Anakonda;
  • working DHCP server. You’re going to boot your server using CentOS installation media and the server has to have networking working in order to grab the Kickstart file;
  • working web server. This is where you’re going to place the Kickstart file.

Below is my example of the Kickstart file. Use it as an example of what could be put there. For detailed explanation refer to the Red Hat Kickstart syntax reference.

  1. # System authorization information
  2. auth —-enableshadow —-passalgo=sha512
  3.  
  4. # Use CDROM installation media
  5. cdrom
  6.  
  7. # Use graphical install
  8. graphical
  9.  
  10. # Run the Setup Agent on first boot
  11. firstboot —-enable
  12. ignoredisk —-only-use=sda
  13.  
  14. # Keyboard layouts
  15. keyboard —-vckeymap=us —-xlayouts='us'
  16.  
  17. # System language
  18. lang en_US.UTF-8
  19.  
  20. # Disable firewall and selinux
  21. firewall —-disabled
  22. selinux —-disabled
  23.  
  24. # Accept Eula
  25. eula —-agreed
  26.  
  27. # Reboot after installing
  28. reboot
  29.  
  30. # Network information
  31. network  —-bootproto=dhcp —-device=eno1 —-onboot=off —-noipv6
  32. network  —-bootproto=dhcp —-device=eno2 —-onboot=off —-noipv6
  33. network  —-bootproto=dhcp —-device=eno3 —-onboot=off —-noipv6
  34. network  —-bootproto=dhcp —-device=eno4 —-onboot=off —-noipv6
  35. network  —-bootproto=dhcp —-device=enp0s20u1u5 —-onboot=off —-noipv6
  36. network  —-bootproto=static —-device=ens4f0 —-gateway=10.9.37.254 —-ip=10.9.37.81 —-mtu=9000 —-nameserver=10.9.12.1,10.9.12.2 —-netmask=255.255.255.0 —-noipv6 —-activate
  37. network  —-bootproto=dhcp —-device=ens4f1 —-onboot=off —-noipv6
  38. network  —-hostname=hadoop-kickstart
  39.  
  40. # Root password
  41. rootpw —-iscrypted $XXXXX
  42.  
  43. # System services
  44. services —-disabled="chronyd"
  45.  
  46. # System timezone
  47. timezone Europe/London —-isUtc —-ntpservers=10.9.12.1,10.9.12.2
  48.  
  49. user —-groups=wheel —-name=someextrauser —-password=$XXXXX —-iscrypted —-gecos="Some extra user"
  50.  
  51. # System bootloader configuration
  52. bootloader —-location=mbr —-boot-drive=sda
  53.  
  54. # Partition clearing information
  55. clearpart —-all —-initlabel —-drives=sda
  56.  
  57. # Disk partitioning information
  58. part pv.1125 —-fstype="lvmpv" —-ondisk=sda —-size=29824
  59. part /boot/efi —-fstype="efi" —-ondisk=sda —-size=122 —-fsoptions="umask=0077,shortname=winnt" —-label=boot-efi
  60. part /boot —-fstype="xfs" —-ondisk=sda —-size=488 —-label=boot
  61. volgroup hadoop-datan —-pesize=4096 pv.1125
  62. logvol /usr  —-fstype="xfs" —-size=7629 —-label="usr" —-name=usr —-vgname=hadoop-datan
  63. logvol /tmp  —-fstype="xfs" —-size=488 —-label="tmp" —-name=tmp —-vgname=hadoop-datan
  64. logvol swap  —-fstype="swap" —-size=3814 —-name=swap —-vgname=hadoop-datan
  65. logvol /  —-fstype="xfs" —-size=2861 —-label="root" —-name=root —-vgname=hadoop-datan
  66. logvol /var  —-fstype="xfs" —-size=15016 —-label="var" —-name=var —-vgname=hadoop-datan
  67.  
  68. %packages
  69. @^minimal
  70. @core
  71.  
  72. %end
  73.  
  74. %addon com_redhat_kdump —-disable —-reserve-mb='auto'
  75.  
  76. %end

Put this file on your web server, let’s call it kickstart-dn.cfg.

Now, boot the new server using CentOS installation media and when the initial screen appears, select Install CentOS 7 and press the e key to edit.

Keep the first and the third lines unchanged and modify the second one to:

  1. vmlinuz initrd=initrd.cfg ks=http://10.9.15.10/kickstart-dn.cfg ksdevice=eno1

Note that I explicitly specified ksdevice=eno1. This is a network card attached to the DHCP aware network and is used solely for the initial installation. Once the installation is completed I’ll disconnect the cable from eno1 and will use ens4f0 (which is in a different VLAN with no DHCP).

Press Ctrl-X to continue the installation. You should notice that if everything is fine, kickstart-dn.cfg will be downloaded, processed and the installation continues without any prompts.

Have fun!

Tags: , , , , , ,

Leave a Reply