cloudbase / cloudbase-init

Cross-platform instance initialization
http://openstack.org
Apache License 2.0
430 stars 153 forks source link

Unable to create azure VM for cloudbase sysprepped image. #161

Open PrashantRaj18198 opened 2 weeks ago

PrashantRaj18198 commented 2 weeks ago

Hi,

I made an image including cloudbase init. And sysprepped the VM using the cloud init provided unattend.xml file Here's how I'm doing the sysprep

# Use the unattend.xml provided by cloudbase-init
$unattendedXml = Join-Path $env:ProgramFiles "Cloudbase Solutions\Cloudbase-Init\conf\Unattend.xml"
& $env:SystemRoot\System32\Sysprep\Sysprep.exe /oobe /generalize /mode:vm /quit /quiet /unattend:$unattendedXml
if ($LASTEXITCODE) {
    Throw "Failed to run Sysprep.exe"
}

... # wait for image state to reach IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE

This is using packer btw.

The image made is able to bootup most of the time (this is different different instances, by bootup I mean new instance allocation). But some times it fails with the error

OS Provisioning for VM 'wb-wrkcsr44qg5t' did not finish in the allotted time. However, the VM guest agent was detected running. This suggests the guest OS has not been properly prepared to be used as a VM image (with CreateOption=FromImage). To resolve this issue, either use the VHD as is with CreateOption=Attach or prepare it properly for use as an image:
Instructions for Windows: https://azure.microsoft.com/documentation/articles/virtual-machines-windows-upload-image/
Instructions for Linux: https://azure.microsoft.com/documentation/articles/virtual-machines-linux-capture-image/
Deleting and recreating the virtual machine may resolve the issue

The machine however is okay when I restart it and it works. This flow is part of an automated process where I can't do a manual intervention to start up the VMs.

Let me know if I can provide any additional details on this.

ader1990 commented 2 days ago

Hello,

With packer is a little bit more different, but this might be useful: https://github.com/cloudbase/windows-imaging-tools/blob/master/UnattendResources/Logon.ps1#L720

I suggest creating images with this tool: https://github.com/cloudbase/windows-imaging-tools or maybe trying to reproduce the steps when creating such an image.

You have an example of working cloudbase-init configuration and steps here: https://github.com/cloudbase/windows-imaging-tools/tree/master/Examples/config/azure

Thanks.