Tag Archives: schedule vm power cycle

How to schedule VM power cycle when the guest OS reboots?

Couple of weeks back vSphere 6.7 U3 released vCenter release notes & ESXi release notes and once again an update release has got great content. Apart from several other changes gone into vSphere 6.7 U3, one of the utilities I found really useful. i.e. Ability to schedule the VM power cycle when the guest OS reboots. This post is focused on the same. Before we dig into, below is what ESXi release note says about it.

PR 2394247: You cannot set virtual machines to power cycle when the guest OS reboots

After a microcode update, sometimes it is necessary to re-enumerate the CPUID for virtual machines on an ESXi server. By using the configuration parameter vmx.reboot.powerCycle = TRUE you can schedule virtual machines for power-cycle when necessary.

This issue is resolved in this release.

Based on above description, it is clear that one of the motivations behind this cool utility is the recent meltdown/spectre patches. After applying each of these patches, it was required to do cold power cycle of the VMs in order to re-enumerate the CPUID(s) introduced by that particular patch. Performing cold power cycle (power off and power on) is always tricky to plan and painful activity. This utility enables an user to schedule power cycle as part of guest OS reboots itself. How cool is that!

In order to simulate a scenario where we should see CPUIDs are re-enumerated on a VM, I created a cluster with 2 hosts, where both hosts Max EVC mode supported was “Broadwell” but I enabled EVC on “ivy-bridge” EVC mode. Then I created a GOS VM, powered on it and used below powerCLI script to add ” vmx.reboot.powerCycle = TRUE ” into vmx file.

[powershell] 
 #PowerCLI script to add vmx entry "vmx.reboot.powerCycle"
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
Connect-VIServer -Server 10.1.1.1 -User Administrator@vsphere.local -Password VMware@123 #replace your server (VC or ESXi) name

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.extraConfig += New-Object VMware.Vim.OptionValue
$spec.extraConfig[0].key = "vmx.reboot.powerCycle"
$spec.extraConfig[0].value = "TRUE"

(get-view (Get-VM -Name VMW).ID).ReconfigVM_Task($spec)  #replace your vm name

Disconnect-VIServer -Server 10.1.1.1 -Confirm:$false #replace your server (VC or ESXi) name 
 [/powershell] 

You can run above script against either vCenter or ESXi as endpoint. User also can add above vmx entry using ESXi host client as shown below.

Add parameter into vmx file

After running above script against my VM, I see that vmx file has got ” vmx.reboot.powerCycle = TRUE ” entry . Before I restart the GOS, I checked (from MOB) CPUIDs available on this VM at ivy-bridge EVC mode and below is how it looks.

CPUIDs at ivy-bridge EVC mode
VM cpuids at ivy-bridge EVC mode

In continuation to simulate the scenario, I disabled EVC on the cluster,where max EVC mode supported is “Broadwell” i.e. ideally VMs should be running on Broadwell cpu set but since we had created our VM when EVC was enabled on “ivy-bridge”, it will continue to use “ivy-bridge” cpu set/features even though underlying host is “Broadwell”. Before 6.7 U3, we had to do cold power cycle (power off, power on) to have VM on “Broadwell” cpu set. Since we added vmx entry already, we need not to do power cycle but guest reboot in-turn will do power cycle as well and CPUIDs will be re-enumerated. Below are the CPUIDs I see on VM when I restarted the Guest OS as it is now using broadwell cpu instruction set.

VM cpuids re-enumerated to broadwell

Key observations.
1. I see vmx entry works only when it is added on the Powered ON VM.
2. When I added vmx entry onto PowerOff VM, it got added but as soon as I powered on, it got removed. It will persist during suspend and resume.
3. I observed that this setting is one time i.e. when user restarts the Guest OS, I do not see vmx entry i.e. vmx.reboot.powerCycle = TRUE any more. Hence next time you want to have similar functionality, you need to set it once again on powered ON VM.
4. This utility is just not only for cpuid re-enumeration. cpuid re-enumeration is one of the use-cases. I think it is great idea to schedule the power Cycle when you upgrade VM hardware version or upgrade vmware tools.

I hope enjoyed the post. Let me know if you have any comment.