How to create custom ESXi image
Sergey Sypalo Sypalo.com
2020-10-10
In this article, I will show you how to create a custom esxi image with PowerShell
You will need 30 minutes to follow these steps:
-
Go to VMWare downloads and download your vendor-specific image -
Swtich to Drivers tab and download required/additional/updated drivers if needed -
Go to VMWare patches and download latest ESXi build -
Go to your server's vendor drivers download page, in my case Cisco drivers and download latest drivers for your ESXi version -
Go to your vCenter AutoDeploy menu section, click the Import link on the top right, locate a vendor-customized image and provide a name -
Repeat the previous step and import the latest ESXi build and drivers -
Add custom depot -
Click on the link "New image profile" and provide name and details.
I usually use the following naming convention: ESXi-[major_version].[minor_version]-[build]-[standard/no-tools]. The last part depends on whenever I include VMTools or no. -
Select only the latest packages as by default wizard shows you a list with all available vibs from all depots -
Custom ESXi image has been created and now you can use it in AutoDeploy or export to zip or ISO by clicking the Export button
Or you can use the following PowerShell script to do this for you
$vcenter = Read-Host "Provide vCenter name"
$esxi_build = Read-Host "Provide ESXi build number you want to download"
$handle = Connect-VIServer $vcenter
$version = $handle.Version.Substring(0,3)
# Import downloaded ESXi Cisco Custom image, latest ESXi image, Cisco enic drivers and NetApp VAAI driver from the folder below
Get-EsxSoftwareDepot | Remove-EsxSoftwareDepot
Add-EsxSoftwareDepot (Get-ChildItem "c:\packages\$version" *.zip).FullName
$profilename = "ESXi-$version-$esxi_build"
Write-Host "Checking if already downloaded build matches target one"
if ((Get-EsxSoftwarePackage -Newest | ? name -eq esx-base).Version.Split('.')[-1] -ne $esxi_build) {
Get-EsxSoftwareDepot | Remove-EsxSoftwareDepot
Write-Host "New build $profilename wasn't found locally, adding online depot to download it"
Add-EsxSoftwareDepot "https://hostupdate.vmware.com/software/VUM/PRODUCTION/main/vmw-depot-index.xml"
Write-Host "Looking for a build to download"
$ver = "ESXi-" + $handle.Version + "-202"
Get-EsxImageProfile | ? Name -like *$ver*standard* | sort Name -Descending | % {
if (($_.VibList | ? name -eq esx-base).Version.Split('.')[-1] -eq $esxi_build) {
$profilename = $_.Name
Write-Host "Found correct build in profile $profilename, downloading it"
Export-EsxImageProfile $profilename -ExportToBundle c:\packages\$version\$profilename.zip
break
}
}
}
else {
Write-Host "Correct build is already downloaded"
$profilename = "ESXi-$version-$esxi_build"
}
# Import downloaded ESXi Cisco Custom image, latest ESXi image, Cisco enic drivers and NetApp VAAI driver from the folder below
Get-EsxSoftwareDepot | Remove-EsxSoftwareDepot
Add-EsxSoftwareDepot (Get-ChildItem "c:\packages\$version" *.zip).FullName
Write-Host "Creating custom stateless ESXi image without tools"
if (!(Test-Path c:\packages\$profilename-no-tools.zip)) {
New-EsxImageProfile -NewProfile -Name $profilename-no-tools -SoftwarePackage (Get-EsxSoftwarePackage -Newest | ? name -ne tools-light) -Vendor DevOps -AcceptanceLevel PartnerSupported
Export-EsxImageProfile $profilename-no-tools -ExportToBundle c:\packages\$profilename-no-tools.zip
}
Write-Host "Creating custom stateful ESXi image with tools"
if (!(Test-Path c:\packages\$profilename-standard.zip)) {
New-EsxImageProfile -NewProfile -Name $profilename-standard -SoftwarePackage (Get-EsxSoftwarePackage -Newest) -Vendor DevOps -AcceptanceLevel PartnerSupported
Export-EsxImageProfile $profilename-standard -ExportToBundle c:\packages\$profilename-standard.zip
}
That's all, we built an ESXi image we need with specified drivers