Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 2. Installing and Configuring ES... > Perform a Scripted Installation Usin...

2.4. Perform a Scripted Installation Using a USB Device

Scripted installations are an exciting way to build hosts in a fast and meaningful process. There are times when a fast build is necessary—think disaster recovery. Additionally, scripted installations ensure all builds are exactly the same. And most important, why spend unnecessary time doing something that can be accomplished while you relax and watch the process do what it is designed to do? A friend of mine says he does his best work while getting coffee (he scripts everything). The best approach is to create a master script, and then make copies of it for each ESX host in your inventory, customized with the IP address, hostname, and any other pertinent information needed. An added benefit of this strategy is increased knowledge of the moving parts encompassing an ESX host. An installation script is nothing more than a text file called ks.cfg; essentially it is an answer file.

A Sample ks.cfg Script

The following code is an example of a ks.cfg file. This file is used to perform a scripted installation; it is the answer key. This is only an example—you can add to or subtract from it—but it is a good starting point for a scripted installation.

accepteula
keyboard us
auth  --enablemd5 --enableshadow
# Canonical drive names:
clearpart --drives=mpx.vmhba0:C0:T0:L0
# Uncomment to use first detected disk:
#clearpart --firstdisk
install cdrom
rootpw --iscrypted $1$RZG65IhM$gey0IiHJyKqeGqvioM8g.0
timezone --utc 'US/Eastern'
network --addvmportgroup=true --device=vmnic0
--bootproto=static --ip=192.168.1.31
--netmask=255.255.255.0 --gateway=192.168.1.251
--nameserver=192.168.1.15,192.168.1.1
--hostname=vsphere02.phoenix.com
part '/boot'  --fstype=ext3 --size=250
--ondisk=mpx.vmhba0:C0:T0:L0
# Uncomment to use first detected disk:
#part '/boot'  --fstype=ext3 --size=250  --onfirstdisk
part 'none'  --fstype=vmkcore --size=110
--ondisk=mpx.vmhba0:C0:T0:L0
# Uncomment to use first detected disk:
#part 'none'  --fstype=vmkcore --size=110  --onfirstdisk
part 'Storage1'  --fstype=vmfs3 --size=8604
--grow  --ondisk=mpx.vmhba0:C0:T0:L0
# Uncomment to use first detected disk:
#part 'Storage1'  --fstype=vmfs3 --size=8604
--grow  --onfirstdisk
virtualdisk 'esxconsole' --size=7604 --onvmfs='Storage1'
part 'swap'  --fstype=swap --size=600
--onvirtualdisk='esxconsole'
part '/var/log'  --fstype=ext3 --size=2000
--onvirtualdisk='esxconsole'
part '/'  --fstype=ext3 --size=5000 --grow
--onvirtualdisk='esxconsole'
%post --interpreter=bash

					  


When working with scripts, you should use a text editor that won't add any additional markups to the files. If you use WordPad, Notepad, or Microsoft Word to edit files, the script may no longer work and you'll spend time trying to hunt down a problem or failure that will be almost impossible to find. Everything will look exactly as it should to human eyes, but not from a file system perspective. What is odd is that these programs don't add errors every time; once in a while they work just fine. Find a program (on the internet, via a search engine of your choice) called Win32pad, install it, and use it. (When opening this application, be sure to change the format to Unix by selecting File Format Unix. Otherwise, Win32pad will default to DOS/Windows and files may stop working.) Another option is to modify all files via a session in Linux.

Where can you find an install script? There are two ways to acquire a script. First, a running ESX host has a copy of its configuration, called anacondo-ks.cfg, in the directory /root. A second option is to take a copy of what is in the anacondo-ks.cfg file, use a program similar to Win32pad, save the file as a Unix format, and then edit as necessary. A benefit of using a working copy of a ks.cfg file is that the root password will be encrypted.

2.4.1. Identify the USB Device

Unfortunately, there is no easy way to identify the USB device. Each piece of hardware has the potential to do this in a slightly different way. However, if you have several hosts that are all the same, identifying the USB device on the first one should tell you what it will be on subsequent hardware of the same make and model. In the following steps we will identify our USB device.

  1. On an ESX host that is already installed, open a console session.

  2. Without the USB device plugged in, issue this command:

    fdisk -l (L as in lima)

  3. Note the devices that are present. A screen shot may be helpful for the before-and-after comparison.

  4. Plug in the USB key (in some cases the host may need to be rebooted) and reissue the following command:

    fdisk -l

    USB devices often take the form of /dev/sda or /dev/sdb. Figure 2.28 shows a USB device before formatting.

    Figure 2.28. Identifying the USB device

2.4.2. Format the USB Key

Our next step will format the entire space on the USB key and then copy the ks.cfg file to the root of the partition. This assumes the ks.cfg file is already customized for the build it is to be used for. If that's not the case, open the file with Win32pad, make the necessary changes, and proceed.

  1. From a console window under root, assuming the USB device is /dev/sdd1, enter the following commands (as shown in Figure 2.29):

    mkfs.ext3 /dev/sdd1
    cd /mnt/

    Figure 2.29. Formatting the USB device

  2. Enter the following commands to create a directory where one didn't exist before:

    mkdir usbdisk
    cd /root

  3. Enter the following commands to copy the file to the USB drive:

    cp ks.cfg /mnt/usbdisk
    unmount /mnt/usbdisk

    The USB device is now formatted, has a copy of ks.cfg on it, and has been modified (prior to our copy) by an administrator to contain ESX host–specific information.

  4. Insert the installation media and power on the host; the installation will boot from the CD/DVD and draw answers from the USB device.

  5. On the splash screen, choose the option ESX Scripted Install Using USB ks.cfg and press Enter.

The process should take off; when complete, a prompt appears asking you to reboot.

  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint