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.

No comments:

Post a Comment