top of page

PowerCLI+NAS: Your on-demand Nested ESXi PXE server!!

In this blog post, we will take a look at how to use your NAS as a Pxe server for deploying on demand Nested ESXi. Naturally, this is only applicable for homelab environments, since nested ESXis are not supported by VMware in production environments. We can use William Lam's nested ESXis for the same purpose, this is just another method for deploying nested ESXis in the homelab.

Setup up PXE server and ftp server in your NAS. Incase you have a synology nas, you can refer to my blog posts: ESXi PXE boot off Synlogy NAS! [Part 1] ( and ESXi PXE boot off Synology NAS! [Part 2] ( . You can use these posts as reference for setting up PXE and ftp on other NASes as well, just that the UI options would vary slightly.

In this post we will be looking at the boot.cfg file, ks.cfg file and the PowerCLI function that enable us to automatically deploy NestedESXis in our homelabs.

In this example, we will be injecting the ESXi installation answer file i.e ks.cfg file via FTP server running on my NAS server. The same can be achieved by NFS/HTTPS file servers. In order to inject the answer file into the installation; we need to edit the 6th line of the boot.cfg file, as highlighted below. In this example, I have named my answer file as nested.cfg file:

kernelopt=ks=ftp://<user>:<Password>@<NAS IP>/ks/nested.cfg
modules=/jumpstrt.gz --- /useropts.gz --- /features.gz --- /k.b00 --- .... 

Next, let us look at the sample ks.cfg file, in this example, I have named it as nested.cfg file. You can refer to the standard ks.cfg file from Vmware's url: "About the Default ks.cfg Installation Script (". In this example, I have made some minor changes to the default ks.cfg file:

# Sample Nested ESXi KS file

# Accept the VMware End User License Agreement

# Set the root password for the DCUI and Tech Support Mode
rootpw <Your root password here>

# Install on the first local disk available on machine
install --firstdisk --overwritevmfs

# Set the network to DHCP on the first network adapter
network --bootproto=dhcp

Next we take a look at the key ingredient of this solution, the PowerCLI function. The function "Deploy-PxeBootNestedEsxi" connects to the target host, creates a new VM with guest os selected as ESXi7.x, enables hardware virtualization and sets the network adapter to VMXNET3. The function then powers up the VM, which begins the PXE boot sequence from the NAS on the network.

The following parameters need to be provided to the function:

- Server: Target virtualization server where you deploy the nested esxi

- serveruser: Target server root user

- serverpass: Target server root password

- NestedESXiName: Nested ESXi VM name

- datastore: datastore where you would create the nested esxi vm

- NestedDiskSpaceGB: Nested ESXi disk size in GBs

- NestedCPU: Nested ESxi CPUs

- NestedMemGB: Nested ESXi memory in GBs

- NestedEsxiNW: Nested ESxi network connection

#Deploy Nested ESXi using PXE server
#Written by

function Deploy-PxeBootNestedESXi{
    #Define all parameters required
    Param (

                #Connect to target Server
                Connect-VIServer -Server $server -User $serveruser -Password $serverpass |Out-Null

                #Create the VM
                New-VM -VMHost $vmhost -Name $NestedEsxiName -Datastore $datastore -DiskGB $NestedDiskSpaceGB -NumCpu $NestedCpu `
                -MemoryGB $NestedMemGB -NetworkName $NestedEsxiNW -GuestId "vmkernel7Guest" | Out-Null
                #Re-configure to allow for NestedEsxi
                $vmview= Get-VM -Name $NestedEsxiName |Get-View

                #Enable Hardware Virtualization
                $config = New-Object VMware.Vim.VirtualMachineConfigSpec
                $config.NestedHVEnabled = $true
                $vmview.ReconfigVM_Task($config) |Out-Null

                #Set boot to uefi
                $config = New-Object VMware.Vim.VirtualMachineConfigSpec
                $config.Firmware = 'efi'
                $vmview.ReconfigVM_Task($config) |Out-Null

                #Change Network Adapter to VMXNET3
                Get-VM -Name $NestedEsxiName| Get-NetworkAdapter| Set-NetworkAdapter -Type Vmxnet3 -StartConnected: $true -Confirm: $false|Out-Null

                Start-Sleep -Seconds 10

                #PowerUp the VM,PXE boot will start automatically, provided you have already configured your NAS to support PXE
                Get-VM -Name $NestedEsxiName|Start-VM |Out-Null

                #Inform User:
                Write-Host "NestedHost has been created, PXE ESXi installation will begin shortly. Please switch to the console view" `
                -BackgroundColor Cyan -ForegroundColor Black
                #Disconnect the server
                Disconnect-VIServer -Server * -Confirm:$false |Out-Null


Deploy-PxeBootnestedEsxi in action!!:

25 views0 comments
bottom of page