How to stop Windows10 VM on OpenStack from automatically restarting!

Updated on April 13, 2022

I’m experiencing a Windows10 VM on OpenStack that automatically restarts on successful autologon. Struggling with this for a while and hours spent in search of this topic on google went in vain. Followed the below step-by-step procedure to find the root cause and stop Windows10 VM on OpenStack from automatically restarting!

Wondered why Windows restarts automatically? Thankfully, Windows tracks the events and records in the system log. With the built-in Windows Event Viewer, you can monitor the activities that occur on your computer before, during, and after it shuts down or restarts. This article helped me to view the system logs in Windows10 that triggered the automatic restart.

View Shutdown and Restart log from Event Viewer

Open Event Viewer app

Event Viewer App in Windows10

Navigate to Windows Logs -> System on the left pane. Wait until all the logs are loaded. Click on Filter Current Log on the right pane. Type 41, 1074, 6006, 6008 into the textbox under includes/Excludes Event IDs and then click OK to filter the event logs.

Windows10 Filter System logs based on Event IDs

From the filtered logs, found a suspicious log stating Cloudbase-Init has initiated the restart of the computer as below:

Windows10 System logs

This provided a hint to research further and found a bug reported in launchpad related to cloudbase-init. Below is my understanding of why the automatic restart was happening:

From our cloudbase-init unattend.xml file (C:\Program Files\Cloudbase Solutions\Cloudbase-Init\conf\unattend.xml) you can notice that cloudbase-init tries to set the hostname in the specialize settings. This causes a SetComputerName function to run during the specialize step, which changes the computer name to DESKTOP-<random string>. A known issue in Windows10 is that a change to the computer name requires a restart.

Cloudbase-init unattend.xml file

How to stop Windows10 VM on OpenStack from automatically restarting!

Thanks to Curt Moore for his quick solution. The same I have tried to explain in detail below:

Step 1: Install Cloudbase-init using the MSI as normal, except DO NOT have it perform an automatic sysprep during the autoinstallation.

Step 2: After the Cloudbse-init installation is complete, run the following command from the command prompt (Run as administrator) to disable the automatic startup of the Windows service version of cloudbase-init.

sc config cloudbase-init start= disabled

set-config command to disable cloudbase-init

Step 3: Edit the unattend.xml file and add another RunSynchronousCommand node to re-enable the automatic start of the cloudbase-init Windows service. This command _must_ be set as <Order>1</Order> and the existing unattended cloudbase-init node set to <Order>2</Order> so that the re-enable command runs prior to the unattended instance of cloudbase-init, which requires a reboot. The idea is that if we re-enable the cloudbase-init service (but do not restart it at this time) upon the reboot required by the unattended cloudbase-init, the Windows service instance will start as desired and will not be in contention with the unattended instance since it will have already executed. Below is the modified unattend.xml file:

Modified Unattend.xml file for re-enable autostart of cloudbase-init

Step 4: After editing the unattend.xml file, manually run sysprep command from the command prompt (Run as administrator) and reference the modified XML.

C:\Windows\system32>"%SYSTEMROOT%\system32\sysprep\sysprep.exe" /generalize /oobe /quit /unattend:C:\Program Files\Cloudbase Solutions\Cloudbase-Init\conf\unattend.xml

Refer the unattend.xml

Refer the unattend.xml file path correctly with respect to your installation.

Step 5: Release the Windows IP configuration after the sysprep and then immediately shutdown the VM.

Why to release IP

This will avoid to re-DISCOVER the same IP address the VM had prior to being sysprepped. This is troublesome when booting a VM in OpenStack as the network segments are totally different and it takes Windows ~10-20 seconds to stop trying to re-DISCOVER the old address and just issue a new DHCP REQUEST.

ipconfig /release
shutdown /s /f /t 1

Release IP and Shutdown from command line in Windows10

Now upload the Windows VM to OpenStack and boot an instance. Voila! the Windows10 VM autologged in and didn’t restart!

Was this article helpful?

Related Articles

Leave a Comment