Thursday, September 3, 2015

VMware: ESXi Unattended Scripted Installation

ESXi installation is an easy job for one or two hosts, but imagine to repeat such installation for 40/50 hosts: it would take all day. To prevent such time-consuming situation VMware allow administrators to perform unattended ESXi installation.

Unattended installation is performed using a kickstart script that will be provided during boot. Kickstart script contains all parameters needed by ESXi to automatically complete installation process without further human intervention.

At first I suggest you to have a look at official documentation regarding ESXi 5.5 scripted installation:

Deploying ESXi 5.x using the Scripted Install feature (2004582) 
About Installation and Upgrade Scripts

Here's my kickstart file. I named it ks.cfg. You can use it as a base template and edit it according to your requirements.

 #  
 # Sample scripted installation file  
 #  
 # Accept EULA  
 vmaccepteula  
 # Set root password  
 rootpw mypassword  
 #Install on local disk overwriting any existing VMFS datastore  
 install --firstdisk --overwritevmfs  
 # Network configuration  
 network --bootproto=static --device=vmnic0 --ip=192.168.116.228 --netmask=255.255.255.0 --gateway=192.168.116.2 --nameserver=192.168.116.2 --hostname=esx1.testdomain.local --vlanid=100 --addvmportgroup=1  
 #Reboot after installation completed  
 reboot  

As you can see the code is already commented but let me spend a few words on:

install --firstdisk --overwritevmfs

This is used to install ESXi on first available local disk overwriting any existent VMFS partition.

While:

network --bootproto=static --device=vmnic0 --ip=192.168.116.228 --netmask=255.255.255.0 --gateway=192.168.116.2 --nameserver=192.168.116.2 --hostname=esx1.testdomain.local --vlanid=100 --addvmportgroup=1

Specifies that vmnic0 will be used for management and assigns to it IP address, netmask, gateway and vlan id.

--addvmportgroup=1 creates the VM Network portgroup to which virtual machines will be connected by default.

Let me now explain how to use this kickstart file during installation.

Boot your host with ESXi installation media attached (I use CDROM). During boot press SHIFT + O toEdit boot options. Weasel prompt will appear.

> runweasel

Basic command to use a network accessible (HTTP, HTTPS, NFS, FTP) kickstart file is:

> runweasel ks=<kickstart_file_location> ip=<ip_address_to_use_to_retrieve_ks> netmask=<netmask_to_use_to_retrieve_ks> gateway=<gateway_to_use_to_retrieve_ks> vlanid=<vlan_to_use_to_retrieve_ks>

kickstart script s location can be not just an HTTP(S) server. Even FTP, NFS, cdrom or usb are accepted in the form of:

ks=protocol://<serverpath>
ks=cdrom:/<path\>
ks=file://<path>
ks=usb:</path> 


In this example I retrieve kickstart file from a webserver (an HTTP location) and assign192.168.116.222 as IP address for host during installation process. 

> runweasel ks=http://192.168.116.1:8080/ks.cfg ip=192.168.116.222 netmask=255.255.255.0 gateway=192.168.116.2




Unattended installation will begin by parsing kickstart file.



When installation is completed host will reboot and ESXi will be ready to be used.



That's all!!
==================================================================

Unattended ESXi Installation from an USB Flash Drive

  1. Create a bootable ESXi Installer USB Flash Drive with Rufus (Howto)
  2. Navigate to the Flash Drive and open boot.cfg with an editor. Make sure to use an editor that can handle UNIX encoding (PSPad for example)
    edit-boot.cfg
  3. Replace kernelopt=runweasel with kernelopt=ks=usb:/ks.cfg
    boot-cfg-replace-kernelopts
  4. Create ks.cfg in the root directory of your Flash Drive
    create-esxi-kickstart-file
  5. Open ks.cfg with an editor. Creating complex kickstart is out of scope of this post. The only option you need to know is install. The firstdisk flag will install ESXi to the first device, with the following priority:
    1 – locally attached storage (local)
    2 – network storage (remote)
    3 – usb disks (usb)
    Be careful to not destory any data! Remove Shared LUNs and do not use this with Servers that contain data.Copy this to your ks.cfg file. This will install ESXi to the first local disk:
    vmaccepteula
    rootpw vmware
    install --firstdisk --overwritevmfs
    network --bootproto=dhcp --device=vmnic0
    reboot
    ks-cfg-content
  6. Save and Close
That’s it. You can plug in the USB Flash Drive to a Server, power it on and it will be installed automatically. The password for the root user is set to “vmware”.
Do you want to install plenty hosts to SD Cards or USB Flash Drives?Create the required amount of USB Flash Drives or SD Cards but replace the ks.cfg file with:
vmaccepteula
rootpw vmware
install --firstdisk=usb-storage --overwritevmfs
network --bootproto=dhcp --device=vmnic0
reboot
Plug it in and power the server on. It will boot from the media and do an unattended installation to the installation media. (It uses the first USB device – might be an issue when you have more than one USB storages connected.)
Of course, you can also write an own ks.cfg file to deploy servers with your own customized configuration.

No comments:

Post a Comment