HowTo – Deploy ESXi Images and Configuration via PXE Part2

In part two of this blog post I want to cover the configuration of ESXi hosts using kickstart files and some ways to implement it in a Linux PXE server. If yo have not read part one and you don’t have a PXE server yet, take a look at “HowTo – Deploy ESXi Images and Configuration via PXE Part1” first.

Requirements

  • A running PXE server (like in part one of this post), which offers an ESXi installation
  • An idea how you want to configure your ESXi hosts
  • (optional) the MAC addresses of you hosts to give them an individual configuration

Prepare the PXE server

In addition to part one of this blog post we need to install the Apache Web Server. The ESXi hosts can only access the config files using HTTP, FTP or NFS (USB drives and CDROMs would work too). So if you have NFS datastores, you could also use them.

  1. Install Apache Web Server on CentOS:
  2. Start and enable (autostart) the httpd service
  3. Enable HTTP in the firewall (normally it should be enabled by default)
  4. Using a web browser and enter the IP of your server, you’d now see the Apache test site:
  5. Now you need to decide where you want to store your kickstart files. The web server is offering files from “/var/www/html/” but I want to store them together with my ESXi files in “/var/lib/tftpboot/”. So I created a folder called “kickstart” there and linked it to /var/www/html/”:

  6.  If you open a web browser and enter “http://your-ip/kickstart” you should now see the empty kickstart folder. If you see “no permission” (or something similar) something went wrong. You Should fix the permissions first.

Now you are ready to to to create the kickstart file.

 

Create the kickstart file

Base installation kickstart file

Building a kickstart file is relatively easy. It consists of four parts, setup, pre install, first boot and post install. To be honest I prefer to create a very simple kickstart files, just enough for automatic base installation and some settings to be applied and do the rest later with powershell or host profiles. But you can be creative, if you want and I think it’s possible to do nearly everything. Go to William Lam’s blog to see some examples of kickstart files

For only installing ESXi on the disk we need the following commands:

vmaccepteula – to accept the license agreement
install – to install ESXi on a specific disk

  • “–firstdisk=[local|remote|usb]” to use the first disk
  • “–disk= “DISKNAME” to use a specific disk or LUN
  • “–ignoressd” to not install on SSDs
  • “–overwritevmfs” to delete existing VMFS (be careful with that)

rootpw – to set a root password (add –iscrypted for encrypted password)
keyboard – to set keyboard layout (see available layouts here)
reboot – to reboot automatically after installation (add –noeject for not ejecting the cdrom)

optional:

clearpart – to clear partitions on a specific disk before installing (similar parameters like for ‘install’)
dryrun – to just do a dryrun and no real install (similar parameters like for ‘install’)
network – to configure management network (“–bootproto=[dhcp|static]”, “–device=DEVNAME”,…)
vmserialnum – to add a license key with –esx=<license-key>
upgrade – upgrade instead of installation (similar parameters like for ‘install’)
partition – to create additional VMFS partitions (datastores) (similar parameters like for ‘install’)

To see all the command with all options go to Installation and Upgrade Script Commands.

Here is an example how the kickstart file could look just for automated installation:

 

Now you just need to tell you ESXi host where the location of the kickstart file is. This is different for UEFI or legacy boot (see Part 1).

For UEFI replace set “ks=http://192.168.216.234/kickstart/ks.cfg” to kernelopt:

 

For legacy BIOS add “ks=http://192.168.216.234/kickstart/ks.cfg” at the and of the append -c line:

In addition to part 1 (I added it there too) post, I edited the following lines in “/etc/dhcp/dhcpd.conf” to give the hosts their hostname via DHCP (restart DHCP service after editing the file: “sudo systemctl restart dhcpd”). The option host-name “NAME” is responsible for that:

After booting with this settings and waiting the installation to complete, we get this screen without doing anything, so it works:

 

Base installation with configuration kickstart file

After doing so, why not just add a bit of ESXi configuration in the kickstart file. You can add any command you could run on ESXi shell (esxcli, vim-cmd, etc.). The configuration will happen at the first boot so we’ll add “%firstboot –interpreter=busybox” to the kickstart file, type down the needed commands and to make sure do a reboot (this is just an example how it may look like):

The only thing you need to change now are the VMkernel IP addresses. Setting static IP addresses via PXE would only work if you use one kickstart file per host. You’d also insert bash scripts into the kickstart file (i.e. to get the MAC address, DHCP hostname, etc. and set a specific address).

IP configuration Bash Script

Here is one example how you can set different IP addresses with a single kickstart file. The script is looking if a specific MAC address appears in “esxcli network nic list”. If so it runs  IP configuration commands for the specific MAC address. If not it will use DHCP:

The full kickstart file could look like this:

An now all the configuration got set by the script:

Simple static IP configuration

Here is another example how to configure the DHCP IP address and hostname as static.  The script just gets all the IP address and hostname and sets it static. Of course, this only works, if the DHCP provides the Information needed for production. Make sure to run the esxcli command before deleting vmkernel ports.

 

It is also possible to configure the PXE server to offer different kickstart files per MAC address, but I have not implemented it yet. If you have any Information, just post it in the comments.