hashicorp / packer

Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.

Home Page:http://www.packer.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RDP into VM not working on self-created images.

Ujkugri opened this issue Β· comments

Community Note

  • Please vote on this issue by adding a πŸ‘ reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Overview of the Issue

I have to create my own VM-Images for windows11. I do this via an AzureDevOps-Pipeline, that uses Packer to create my images. The specific image it uses to build on is

  # Image Source for packer to know what image it should use as a base.
  os_type                           = "Windows"
  image_publisher                   = "MicrosoftWindowsDesktop"
  image_offer                       = "office-365"
  image_sku                         = "win11-23h2-avd-m365"

Now I run some scripts. I can, throughout all of the time my scripts run, connect to the VM packer created via RDP.
However, the sysprep part is where everything goes south. At the moment, I am only running this, yes no other commands or scripts are runing:

  provisioner "powershell" {
    inline = [
      "echo '>>> Waiting for GA to start ...'",
      "while ((Get-Service RdAgent).Status -ne 'Running') { Start-Sleep -s 5 }",
      "while ((Get-Service WindowsAzureGuestAgent).Status -ne 'Running') { Start-Sleep -s 5 }",

      "echo '>>> Sysprepping VM ...'",
      "if( Test-Path $Env:SystemRoot\\windows\\system32\\Sysprep\\unattend.xml ){ rm $Env:SystemRoot\\windows\\system32\\Sysprep\\unattend.xml -Force}",
      "& $Env:SystemRoot\\System32\\Sysprep\\Sysprep.exe /oobe /generalize /quiet /quit /mode:vm",
      "while($true) { $imageState = Get-ItemProperty HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\State | Select ImageState; if($imageState.ImageState -ne 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { Write-Output $imageState.ImageState; Start-Sleep -s 5  } else {  Write-Output $imageState.ImageState; break } }",
      "while($true) { $fileExists = Test-Path -Path 'C:\\Windows\\System32\\sysprep\\Sysprep_succeeded.tag'; if(!$fileExists) { Write-Output 'Sysprep still in progress!'; Start-Sleep -s 5 } else { Write-Output 'Sysprep Succeeded!'; break } }"
    ]
    skip_clean = true
  }

for sysprep. The file Sysprep_succeeded.tag and the state is IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE according to my logs in the pipe. I also tried other versions and adding restarts before and after sysprep. Did not help. I tried for example this here:

https://github.com/hashicorp/packer/issues/9261

But nothing there helped. I am baffled at this point. Everytime I create a VM it just automatically goes to internal error 0x4 with 0x0 as further errorcode. I run all the scripts in the "Run command"-Section of the VM. Did not help. Restarted it. Did not help. Run again the scripts after restart did also not help. And yes, I changed the nsg to allow access to my new rdp-port. I have checked. RdAgent, WindowsAzureGuestAgent and TeamService are running on the vm. Boot Diagnostics show me a pic of the Start screen.

Also, I can run the base image with no problems in the same subscription, same rg, with the same nsg and have no problems connecting to the image that is not prepared by packer.

Packer version

Newest Version as of 17.04.2024

Operating system and Environment details

In Azure I use this as a base Image.

  # Image Source for packer to know what image it should use as a base.
  os_type                           = "Windows"
  image_publisher                   = "MicrosoftWindowsDesktop"
  image_offer                       = "office-365"
  image_sku                         = "win11-23h2-avd-m365"

Log Fragments and crash.log files

Packer itself does not show any problems, even with increased verbosity, but the azure vm has this, maybe this helps?

cat C:\WindowsAzure\Logs\WaAppAgent.log
 

indows\1.1.18\enable.cmd and params: 
[00000004] 2024-04-17T07:19:26.812Z [INFO]  Beginning enable of plugin Microsoft.CPlat.Core.RunCommandWindows.
[00000004] 2024-04-17T07:19:26.812Z [INFO]  CreateJobObject: Creating job object with a name of Microsoft.CPlat.Core.RunCommandWindows
[00000004] 2024-04-17T07:19:26.812Z [INFO]  Microsoft.CPlat.Core.RunCommandWindows: Creating job object with a name of Microsoft.CPlat.Core.RunCommandWindows
[00000004] 2024-04-17T07:19:26.812Z [TRACE] Microsoft.CPlat.Core.RunCommandWindows: A job object was already existing with this thread will associate process to the same job objects
[00000004] 2024-04-17T07:19:26.812Z [INFO]  Microsoft.CPlat.Core.RunCommandWindows: isAtLeast2012 = True
[00000004] 2024-04-17T07:19:26.812Z [ERROR] Microsoft.CPlat.Core.RunCommandWindows: Error SetCPUNotification: 87
[00000004] 2024-04-17T07:19:26.812Z [INFO]  Microsoft.CPlat.Core.RunCommandWindows: Checking to see if internal default values should be used
[00000004] 2024-04-17T07:19:26.812Z [INFO]  Microsoft.CPlat.Core.RunCommandWindows: Extension CpuQuota is not set
[00000004] 2024-04-17T07:19:26.812Z [INFO]  Microsoft.CPlat.Core.RunCommandWindows: Extension RamQuota is not set
[00000004] 2024-04-17T07:19:26.812Z [INFO]  Microsoft.CPlat.Core.RunCommandWindows: isAtLeast2012 = True
[00000004] 2024-04-17T07:19:26.812Z [WARN]  Microsoft.CPlat.Core.RunCommandWindows: No CpuLimit set for Microsoft.CPlat.Core.RunCommandWindows
[00000004] 2024-04-17T07:19:26.812Z [WARN]  Microsoft.CPlat.Core.RunCommandWindows: Setting MaxMemory to 0
[00000004] 2024-04-17T07:19:26.812Z [ERROR] Microsoft.CPlat.Core.RunCommandWindows: Error SetCommonLimits: 87
[00000004] 2024-04-17T07:19:29.876Z [INFO]  Microsoft.CPlat.Core.RunCommandWindows: Stopped completion port thread.
[00000004] 2024-04-17T07:19:29.876Z [INFO]  Microsoft.CPlat.Core.RunCommandWindows: Closed completion port handle.
[00000004] 2024-04-17T07:19:29.876Z [INFO]  Microsoft.CPlat.Core.RunCommandWindows: Closed job object handle.
[00000004] 2024-04-17T07:19:29.876Z [INFO]  StartProcessWithRetryForPluginArtifact: Running process as S-1-5-18 (NT AUTHORITY\SYSTEM). Process start information: FileName = C:\Packages\Plugins\Microsoft.CPlat.Core.RunCommandWindows\1.1.18\enable.cmd; Arguments = .
[00000004] 2024-04-17T07:19:29.892Z [WARN]  Started a process with the launch command C:\Packages\Plugins\Microsoft.CPlat.Core.RunCommandWindows\1.1.18\enable.cmd, params: .
[00000004] 2024-04-17T07:19:29.892Z [INFO]  Microsoft.CPlat.Core.RunCommandWindows: Function AssignProcessToJobObject success, jobObjectHandle: 1120, jobName: Microsoft.CPlat.Core.RunCommandWindows
[00000004] 2024-04-17T07:19:29.892Z [INFO]  Waiting for command C:\Packages\Plugins\Microsoft.CPlat.Core.RunCommandWindows\1.1.18\enable.cmd of plugin (name Microsoft.CPlat.Core.RunCommandWindows version 1.1.18) to finish...
[00000004] 2024-04-17T07:19:32.939Z [INFO]  Command C:\Packages\Plugins\Microsoft.CPlat.Core.RunCommandWindows\1.1.18\enable.cmd of Microsoft.CPlat.Core.RunCommandWindows has exited with Exit code: 0
[00000004] 2024-04-17T07:19:32.939Z [INFO]  Successfully enabled plugin Microsoft.CPlat.Core.RunCommandWindows.
[00000004] 2024-04-17T07:19:32.939Z [WARN]  Setting the install state of the handler Microsoft.CPlat.Core.RunCommandWindows_1.1.18 to Enabled
[00000004] 2024-04-17T07:19:32.939Z [WARN]  Plugin enabled (handler name: Microsoft.CPlat.Core.RunCommandWindows, extension name: , version: 1.1.18)., Code: 0
[00000016] 2024-04-17T07:19:32.939Z [INFO]  Starting polling for the terminal status of extension 'HandlerName: 'Microsoft.CPlat.Core.RunCommandWindows', ExtensionName: '''
[00000016] 2024-04-17T07:19:33.974Z [WARN]  Handler status file C:\Packages\Plugins\Microsoft.CPlat.Core.RunCommandWindows\1.1.18\Status\0.status deserialization has failed with exception The process cannot access the file 'C:\Packages\Plugins\Microsoft.CPlat.Core.RunCommandWindows\1.1.18\Status\0.status' because it is being used by another process.. Handler Microsoft.CPlat.Core.RunCommandWindows:1.1.18 Will retry 4 more times

This issue has been migrated to hashicorp/packer-plugin-azure#412 due to the Packer Plugin split.

Please follow the new issue for updates.