Friday, 16 March 2012

Force Bios Setup from PowerCLI

I was trying to troubleshoot a Linux VM yesterday and the VM Console from vCenter would be too slow after a reset, so that I could not modify the kernel boot parameters, because by the time it displayed anything, there was already a kernel panic message and I had an unresponsive VM.

So I ticked the Force BIOS Setup option, to force the VM to go on to the BIOS screen on booting up. I removed quiet from the kernel entry in GRUB but all I got was a message saying that I should disable SElinux and after I went through the whole thing again and managed to boot up again without making any changes to the kernel entry, I thought I had better look for a PowerCLI solution, so here it is:
  1. Fire up VMware vSphere PowerCLi.
  2. Connect to vCenter (Connect-VIServer vcenterserver)
  3. Import-Module -Name .\VMware.Vim.dll
  4. $ida = get-vm -name ida
  5. $idaVMBO = New-Object VMware.Vim.VirtualMachineBootOptions
  6. $idaVMBO.EnterBIOSSetup=$true
  7. $idaVMCS = New-Object VMware.Vim.VirtualMachineConfigSpec
  8. $idaVMCS.BootOptions = $idaVMBO
  9. $idaView = Get-View -VIObject $ida
  10. $idaView.ReconfigVM($idaVMCS)
  11. restart-vm $ida
To repeat the process after step 11, just do:
  1. $idaView.ReconfigVM($idaVMCS)
  2. restart-vm $ida -confirm:$false
I think this is a good candidate for a script.

2 comments:

  1. function Set-VMBootToBIOS
    {
    param (
    $VMs,
    [bool]$BootToBIOS = $true
    )

    $vmbo = New-Object VMware.Vim.VirtualMachineBootOptions
    $vmbo.EnterBIOSSetup = $BootToBIOS
    $vmcs = New-Object VMware.Vim.VirtualMachineConfigSpec
    $vmcs.BootOptions = $vmbo

    foreach ($VM in $VMs)
    {
    if ($VM.typename -eq "VMware.VimAutomation.ViCore.Impl.V1.VM.UniversalVirtualMachineImpl")
    {
    $VM = $VM.name
    }

    $view = Get-View -VIObject $VM
    $view.ReconfigVM($vmcs)
    }

    }

    ReplyDelete
    Replies
    1. Set-VMBootToBIOS $(get-vm KIL*10VW-*) -BootToBIOS $true

      Delete