The following is an excerpt from my book Mastering VMware vSphere 5.5, which you can read more on this blog over the coming weeks. To read the full text you can get a copy here. To test out this procedure, download AutoLab.
ESXi Installation Scripts
ESXi supports the use of an installation script (often referred to as a kickstart, or KS, script) that automates the installation routine. By using an installation script, users can create unattended installation routines that make it easy to quickly deploy multiple instances of ESXi.
ESXi comes with a default installation script on the installation media. Listing 2.1 shows the default installation script.
Listing 2.1: ESXi provides a default installation script
# # Sample scripted installation file # # Accept the VMware End User License Agreement vmaccepteula # Set the root password for the DCUI and Tech Support Mode rootpw mypassword # Install on the first local disk available on machine install --firstdisk --overwritevmfs # Set the network to DHCP on the first network adapter network --bootproto=dhcp --device=vmnic0 # A sample post-install script %post --interpreter=python --ignorefailure=true import time stampFile = open('/finished.stamp', mode='w') stampFile.write( time.asctime() )
If you want to use this default install script to install ESXi, you can specify it when booting the VMware ESXi installer by adding the ks=file://etc/vmware/weasel/ks.cfg boot option. We’ll show you how to specify that boot option shortly.
Of course, the default installation script is useful only if the settings work for your environment. Otherwise, you’ll need to create a custom installation script. The installation script commands are much the same as those supported in previous versions of vSphere. Here’s a breakdown of some of the commands supported in the ESXi installation script:
accepteula or vmaccepteula
These commands accept the ESXi license agreement.
The install command specifies that this is a fresh installation of ESXi, not an upgrade. You must also specify the following parameters:
–firstdisk Specifies the disk on which ESXi should be installed. By default, the ESXi installer chooses local disks first, then remote disks, and then USB disks. You can change the order by appending a comma-separated list to the –firstdisk command, like this:
–firstdisk=remote,local This would install to the first available remote disk and then to the first available local disk. Be careful here—you don’t want to inadvertently overwrite something (see the next set of commands).
–overwritevmfs or –preservevmfs These commands specify how the installer will handle existing VMFS datastores. The commands are pretty self explanatory.
This command specifies the keyboard type. It’s an optional component in the installation script.
This command provides the network configuration for the ESXi host being installed. It is optional but generally recommended. Depending on your configuration, some of the additional parameters are required:
–bootproto This parameter is set to dhcp for assigning a network address via DHCP or to static for manual assignment of an IP address.
–ip This sets the IP address and is required with –bootproto=static. The IP address should be specified in standard dotted-decimal format.
–gateway This command specifies the IP address of the default gateway in standard dotted-decimal format. It’s required if you specified –bootproto=static.
–netmask The network mask, in standard dotted-decimal format, is specified with this command. If you specify –bootproto=static, you must include this value.
–hostname Specifies the hostname for the installed system.
–vlanid If you need the system to use a VLAN ID, specify it with this command. Without a VLAN ID specified, the system will respond only to untagged traffic.
–addvmportgroup This parameter is set to either 0 or 1 and controls whether a default VM Network port group is created. 0 does not create the port group; 1 does create the port group.
This command is optional and, if specified, will automatically reboot the system at the end of installation. If you add the –noeject parameter, the CD is not ejected.
This is a required parameter and sets the root password for the system. If you don’t want the root password displayed in the clear, generate an encrypted password and use the –iscrypted parameter.
This specifies an upgrade to ESXi 5.5. The upgrade command uses many of the same parameters as install and also supports a parameter for deleting the ESX Service Console VMDK for upgrades from ESX to ESXi. This parameter is the –deletecosvmdk parameter.
This is by no means a comprehensive list of all the commands available in the ESXi installation script, but it does cover the majority of the commands you’ll see in use.
Looking back at Listing 2.1, you’ll see that the default installation script incorporates a %post section, where additional scripting can be added using either the Python interpreter or the BusyBox interpreter. What you don’t see in Listing 2.1 is the %firstboot section, which also allows you to add Python or BusyBox commands for customizing the ESXi installation. This section comes after the installation script commands but before the %post section. Any command supported in the ESXi shell can be executed in the %firstboot section, so commands such as vim-cmd, esxcfg-vswitch, esxcfg-vmknic, and others can be combined in the %firstboot section of the installation script.
A number of commands that were supported in previous versions of vSphere (by ESX or ESXi) are no longer supported in installation scripts for ESXi 5.5, such as these:
- autopart (replaced by install, upgrade, or installorupgrade)
- auth or authconfig
- serialnum or vmserialnum
- The –level option of %firstboot
Once you have created the installation script you will use, you need to specify that script as part of the installation routine.
Specifying the location of the installation script as a boot option is not only how you would tell the installer to use the default script but also how you tell the installer to use a custom installation script that you’ve created. This installation script can be located on a USB flash drive or in a network location accessible via NFS, HTTP, HTTPS, or FTP. Table 2.1 summarizes some of the supported boot options for use with an unattended installation of ESXi.
Table 2.1: Boot options for an unattended ESXi installation
|Boot Option||Brief Description|
|ks=cdrom:/path||Uses the installation script found at path on the CD-ROM. The installer checks all CD-ROM drives until the file matching the specified path is found.|
|ks=usb||Uses the installation script named ks.cfg found in the root directory of an attached USB device. All USB devices are searched as long as they have a FAT16 or FAT32 file system.|
|ks=usb:/path||Uses the installation script at the specified path on an attached USB device. This allows you to use a different filename or location for the installation script.|
|ks=protocol:/serverpath||Uses the installation script found at the specified network location. The protocol can be NFS; HTTP; HTTPS or FTP.|
|ip=XX.XX.XX.XX||Specifies a static IP address for downloading the installation script and the installation media.|
|nameserver=XX.XX.XX.XX||Provides the IP address of a Domain Name System (DNS) server to use for name resolution when downloading the installation script or the installation media.|
|gateway=XX.XX.XX.XX||Provides the network gateway to be used as the default gateway for downloading the installation script and the installation media.|
|netmask=XX.XXXX.XX||Specifies the network mask for the network interface used to download the installation script or the installation media.|
|vlanid=XX||Configures the network interface to be on the specified VLAN when downloading the installation script or the installation media.|
Not a Comprehensive List of Boot Options
The list found in Table 2.1 includes only some of the more commonly used boot options for performing a scripted installation of ESXi. For the complete list of supported boot options, refer to the vSphere Installation and Setup Guide, available from www.vmware.com/go/support-pubs-vsphere.
To use one or more of these boot options during the installation, you’ll need to specify them at the boot screen for the ESXi installer. The bottom of the installer boot screen states that you can press Shift+O to edit the boot options.
The following code line is an example that could be used to retrieve the installation script from an HTTP URL; this would be entered at the prompt at the bottom of the installer boot screen:
<ENTER: Apply options and boot> <ESC: Cancel>
> runweasel ks=http://192.168.1.1/scripts/ks.cfg ip=192.168.1.200
Using an installation script to install ESXi not only speeds up the installation process but also helps to ensure the consistent configuration of all your ESXi hosts.