Mastering PowerCLI
上QQ阅读APP看书,第一时间看更新

Image Builder with PowerCLI

The vSphere Image Builder CLI is a process or tool used to build custom ESXi images or software bundles, which can later be installed using the update manager. It is actually a collection of PowerCLI cmdlets that gives you the power to do the earlier mentioned tasks. In most cases, VMware partners use it extensively so that they can build their own images. For example, let's assume that particular server hardware requires a few special drivers for the ESXi server to run properly on that platform. So, we have two options: either we need to install these special drivers after the installation of the ESXi server or we can preinclude them in the ESXi image itself so that we don't need to install any drivers later on. In most cases, the second approach is preferred by most hardware vendors, so you will get vanilla ESXi images from the VMware site, but if you download the ESXi image available from a server vendor site, it includes the added drivers required for the proper functioning of the ESXi server.

We can use the same methods to include some other VIBs (vSphere installation bundles) in the ESXi image and create a new ISO; or we can create a software bundle for later use.

We can use Image Builder to manage a software depot, image profile, and VIBs. Note that VIBs are software packages and image profiles are a set of such packages. So, when we apply an image profile, it actually installs a set of VIBs on that server.

The following figure is the architecture of a VMware Image Builder:

Image Builder with PowerCLI

The main use cases and reasons why you need to use Image Builder are as follows:

  • We can create image profiles that can be used later by Auto Deploy.
  • Add third-party drivers to existing image profiles to make a new custom ISO or software bundle.
  • To perform upgrades on the existing environment.
  • We can create custom images with a reduced footprint. We can take the default ESXi image and then remove VIBs and create a custom reduced image.

The Image Builder cmdlets take the image profiles and VIBs kept in the software depot as the input and produce either a custom ISO image or offline depot ZIP file. The ZIP file can be used later by the update manager or ESXCLI cmdlets for installation at a later stage.

Before we go ahead and discuss this further, let's take a closer look at few of the common terms that we have used so far:

  • VIB: A vSphere installation bundle is an ESXi software package.
  • Image profile: An image profile defines an ESXi image and consists of VIBs. They always have a base VIB and can have more VIBs in them.
  • Software depot: A software depot is a collection of VIBs and image profiles. It is actually a collection of files and folders. Depending on their nature of availability, they can be an online depot (an HTTP URL access) and offline depot (ZIP file).

Next, let's take a look at the cmdlets that are available in Image Builder. The cmdlets can be grouped into different categories as follows:

  • Tasks that can be performed on a software depot:
    • Add-EsxSoftwareDepot
    • Remove-EsxSoftwareDepot
    • Get-EsxSoftwareDepot
  • Cmdlets that can manage image profiles:
    • Get-EsxImageProfile
    • New-EsxImageProfile
    • Set-EsxImageProfile
    • Export-EsxImageProfile
    • Compare-EsxImageProfile
    • Remove-EsxImageProfile
  • Cmdlets that can work on software packages:
    • Add-EsxSoftwarePackage
    • Remove-EsxSoftwarePackage

To get detailed information on these cmdlets, use their Get-Help cmdlets.

So, let's start with creating a depot. We can add an offline bundle file as a depot and then add it on top of it, or add an online depot. In this example, I have taken an existing online depot provided and maintained by Hewlett Packard (https://vibsdepot.hp.com).

Image Builder with PowerCLI

We can download an offline bundle and add it as a software depot as well.

Image Builder with PowerCLI

So, now you can check that I have two different software depots:

Image Builder with PowerCLI

Since we have added the software depot, let's check the contents. Note that the offline bundle that I downloaded from VMware already has two image profiles: one standard and one without any VMware tools.

Image Builder with PowerCLI

We can get a list of available software packages in the depot using the Get-EsxSoftwarePackage cmdlet.

Image Builder with PowerCLI

Now, let's create a new image profile using the available software packages. In this example, we will add packages available from the Hewlett Packard site to the existing VMware profile. As mentioned earlier, since I added the online depot as an existing depot to my environment, I can get a list of available software packages in the HP site. From the list of available packages, I will add the hpbootcfg package to our existing image. This is purely an example; I am trying to show you how to add packages to an existing image. You need to add packages in line with your requirements.

First, I have cloned the existing image profile as Custom-Profile; note that I have mentioned Vendor as Custom and AcceptanceLevel as CommunitySupported:

PS C:\> New-EsxImageProfile -CloneProfile ESXi600-201504001-standard "Custom-Profile" -Vendor Custom -AcceptanceLevel CommunitySupported
Image Builder with PowerCLI

Now, let's add a software package, hpbootcfg, to this new ImageProfile:

PS C:\> Add-EsxSoftwarePackage –ImageProfile "Custom-Profile" –SoftwarePackage hpbootcfg
Image Builder with PowerCLI

Now, let's write the new ImageProfile to an ISO file:

PS C:\> Export-EsxImageProfile –ImageProfile "Custom-Profile" –ExportToIso C:\Custom-ESXI6.0.iso
Image Builder with PowerCLI

So, we have successfully created a new image profile. Similarly, we can create a new bundle with the –ExportToBundle switch. For further details and other supported tasks, you can check individual cmdlets with the Get-Help support.