Scripted install of ESX 3.0
16 December, 2007Automated install of ESX 3.0
For the customer I work, I’ve written an automatic installation script to deploy ESX hosts within minutes.The UDA is an appliance that I use for pxe boot and choosing which script to run. You can find the UDA here: http://www.vmware.com/appliances/directory/232. When booting a new server (or one that needs to be reinstalled), you press F12 and the UDA will offer a PXE boot environment. The server is presented a menu from which the installation can be chosen. After selecting the installation desired, almost everything is done automatically. During the first run, all necessary files are installed and the server is rebooted. After this reboot some extra configurations are made using a second script I call after boot time. The only thing left after this is, connecting the server to virtual center, activating the licenses and enabling the (already configured) vmotion interfac. I’m aware that enabling the vmotion interface can be done using the vmish command but I was too lazy at this point to add it in
One should always leave room for improvement
(Not tested on 3.5 yet !!!)
Detailed layout
You can skip this section and go to the code section if you just want to use the script. I’ll first explain how the script has evolved and how the different sections follow each other. The first script I had functioned quite well, but the downside of it was that when adding a new server, you’d have to edit the IP address and host name manually in the script. Because this is quite error prone, I searched for a way to make as few changes as possible when adding a new host. I started using variables, but it turned out that they get lost between the various sections in the kickstart script. There is a %PRE, %POST and an install section. I needed to find a way to past these vars from one section to another. I used a dummy file to save the vars to disk, but (ofcourse) during install the disk is repartitioned and reformatted which made me lose the dummy file. Thanks to the help of the kickstart mailing list I learned about the special –nochroot section you can use during %POST. At that point there are two filesystems available, the temp file system that is used during install and the new file system not yet mounted at the proper location. It enables me to copy my dummy file from the temp system to the new file system and then continue. In the %POST section the new file system is then mounted and my dummy file is ready for use.
The next image shows which sections are used and which scripts are called.

When the server is booted and F12 is pressed, the PXE boot is started on the nic. The UDA will assign an ip-address and then display the installation menu. Here you chose which installation to start.The installation menu in my case is a list of host names. Each menu item has a boot command line like this : append ip=dhcp ksdevice=eth0 load_ramdisk=1 initrd=initrd.esx301 network ks=http://x.x.x.249/kickstart/es031.cfg ESXIP=31. For a detailed explanation of this command line, please refer to the UDA manual.
Important is the extra piece I’ve added: “ESXIP=31″ to the command line. In my situation all hosts are in the same subnet and only the last digit of the IP will change. In this case the IP will end with 31. Also all host names are like this: vmesx001, vmesx002, in this case vmesx031. ( I admit there will be a problem in the hostname when we reach IP=100 because of the leading zero, but that is for later concern). After choosing the installation, the UDA will load the kickstart script from http://x.x.x.249/kickstart/es031.cfg. (249 is the IP of the UDA).The kickstart script has 4 sections, %PRE, command-section, %POST –nochroot and %POSTsection. Not sure if command-section is the correct name, but this contains the normal installation options.
%PRE
The %PRE section I use to read the boot command line and search for the ESXIP= variable. Most scripting tricks I explain in the code itself. This is just to show you how to go with the flow
So, after I find the ESXIP var, I know the IP address the host should get and write this to a temp file: /tmp/networkconfig. This will also contain gateway address, name servers and hostname. In the command section, this file is read and included again. Because I need the vars later on for other things, I write them to call-script.sh. The call-script.sh will only contain a call to another script called /tmp/esx-post-script.sh and the IP address and VMotion IP address are passed. (I use the x.x.26.x subnet of esx hosts and the x.x.28.x subnet for vmotion).
Command-Section
Now the installation starts and standard things like regional settings, disk layout, etc are loaded. The network section is included through this command: %include /tmp/networkconfig. Nothing special here
After this the %POST –nochroot section is started.
%POST –nochroot
Very short section, only used to copy the “call-script.sh” script from the temporary file system to the new file system. This enables me to use it later on again.
%POST
The post section will download the esx-post-script .sh which contains extra configuration settings. After download call-script.sh is started which then calls the esx-post-script.sh and pastes the IP and VMotion IP.
When the esx-post-script is ran, the host is still running the installation and the vmkernel is not yet loaded. But a number of configurations have to be done with a loaded VMkernel. The work around is to again create a script file, which then can be run after VMkernel is loaded. Looking at the esx-post-script you’ll see that most of it is pasted to /tmp/esxcfg.sh. The last piece is to make /tmp/esxcfg.sh executable and edit rc.local to run /tmp/esxcfg.sh after reboot.
I think that the comments I put inside the scripts are helpful enough to figure out what is done by each command. Should you have more questions, feel free to mail me. The scripts don’t display very well on this blog so I offer them as download here: Scripting ESX 3.0
-
gogotop
-
admin
-
Anne
-
Sanyok
-
admin
-
Linkun
-
TallyESX35U2
-
gman66
-
Babsy98
-
newbie
