[SOLVED] Packer, Windows, Cloudbase-Init - OS not "seeing" cloudconfig drive.

ravioli3

New Member
Jan 5, 2025
2
0
1
I am trying to create a template using Packer and Cloudbase-Init but have been running into problems with Cloudbase-Init.

Unless I'm misunderstanding something the primary issue is that the cloudconfig drive isn't appearing in Windows after I clone my template that was created by Packer. To confirm, Windows does not see a CDROM drive with the metadata from cloudconfig. Post clone I've even removed the cloudconfig drive that packer created, recreated it (both gui and cmdline) but its still not there. The Cloudbase logs just show it looking for a drive then eventaully moving on to the http server, then failure.

I have created a Windows Server 2022 VM by hand, installed cloudbase-init, created a cloudconfig drive, started VM and was able to see the cloudconfig drive and eventually the settings were applied (besides the password).I'm not sure why my template made with Packer cannot "see" the cloudconfig drive. Maybe Windows doesn't need to see the drive but since I have successfully used cloudconfig when it does I assume it should.

packervm.conf
Code:
agent: 1
bios: ovmf
boot: order=scsi0;net0;ide0
cipassword: SuperSecretPass
cores: 8
cpu: host
efidisk0: SONETB_2:2222/base-2222-disk-0.raw/101/vm-101-disk-0.qcow2,efitype=4m,pre-enrolled-keys=1,size=528K
ide0: local:iso/virtio-win-0.1.266.iso,media=cdrom,size=707456K
ide2: SONETB_2:101/vm-101-cloudinit.qcow2,media=cdrom
ipconfig0: ip=192.168.1.91/24,gw=192.168.1.1
kvm: 1
machine: pc-i440fx-9.0
memory: 8192
meta: creation-qemu=9.0.2,ctime=1736685959
name: testetstttt
net0: virtio=BC:24:11:99:CC:C8,bridge=vmbr0
numa: 0
onboot: 0
ostype: win11
scsi0: SONETB_2:2222/base-2222-disk-1.qcow2/101/vm-101-disk-1.qcow2,cache=none,replicate=0,size=60G
scsihw: virtio-scsi-pci
smbios1: uuid=0ff69ecf-32a5-4fce-b337-ff123baf0529
sockets: 1
vmgenid: c047196c-f3ca-4ae7-b676-f5edcdcf9b72

manualvm.conf
Code:
bios: ovmf
boot: order=scsi0;ide0;ide2;net0
cipassword: testing123
cores: 4
cpu: x86-64-v2-AES
efidisk0: SONETB_2:105/vm-105-disk-0.qcow2,efitype=4m,pre-enrolled-keys=1,size=528K
ide0: local:iso/virtio-win-0.1.266.iso,media=cdrom,size=707456K
ide1: SONETB_2:105/vm-105-cloudinit.qcow2,media=cdrom
ide2: local:iso/en-us_windows_server_2022_updated_nov_2024_x64_dvd_4e34897c.iso,media=cdrom,size=5844826K
ipconfig0: ip=192.168.1.81/24,gw=192.168.1.1
machine: pc-i440fx-9.0
memory: 8192
meta: creation-qemu=9.0.2,ctime=1736685449
name: srv2022-42
net0: virtio=BC:24:11:39:6B:B6,bridge=vmbr0,firewall=1
numa: 0
ostype: win11
parent: initial_setup
scsi0: SONETB:105/vm-105-disk-0.qcow2,size=60G
scsihw: virtio-scsi-pci
smbios1: uuid=26619948-0984-4958-9858-d8e1a7a6c137
sockets: 1
vmgenid: 914d3345-4fef-47ce-9e1a-e3612700483d

Packer Template
Code:
packer {
  required_plugins {
    windows-update = {
      version = "0.16.8"
      source = "github.com/rgl/windows-update"
    }
    proxmox = {
      version = "~> 1"
      source  = "github.com/hashicorp/proxmox"
    }
  }
}

variable "proxmox_node" {
  type = string
}

variable "proxmox_api_token_id" {
  type = string
  sensitive = true
}

variable "proxmox_api_token" {
  type = string
  sensitive = true
}

variable "proxmox_url" {
  type = string
}


variable "template" {
  type = string
  default = "std-core"
  description = "Template type, can be desktop or core"
  validation {
    condition = (var.template == "std-core") || (var.template == "std-desktop" || var.template == "data-core") || (var.template == "data-desktop")
    error_message = "Should be std_core, std_desktop, data_core or data_desktop."
  }
}

variable "image_index" {
  type = map(string)
}


variable "windows_iso" {
  type = string
  description = "Location of ISO file in the Proxmox environment"
}

variable "iso_storage" {
  type = string
  description = "Proxmox storage location for additional iso files"
}

variable "efi_storage" {
  type = string
  description = "Location of EFI storage on proxmox host"
}

variable "cloud_init_storage" {
  type = string
  description = "Loaction of cloud-init files/iso/yaml config"
}

variable "memory" {
  type = number
  description = "VM memory in MB"
}

variable "cores" {
  type = number
  description = "Amount of CPU cores"
}

variable "socket" {
  type = number
  description = "Amount of CPU sockets"
}

# variable "vlan" {
#   type = number
#   description = "Network VLAN Tag"
# }

variable "bridge" {
  type = string
  description = "Network bridge name"
}

variable "disk_storage" {
  type = string
  description = "Disk storage location"
}

variable "disk_size_gb" {
  type = string
  description = " Disk size including GB so <size>GB"
}

variable "winrm_user" {
  type = string
  description = "WinRM user"
}

variable "winrm_password" {
  type = string
  sensitive = true
  description = "WinRM password"
}

variable "cdrom_drive" {
  type = string
  description = "CD-ROM Driveletter for extra iso"
  default = "E:"
}

variable "vm_id" {
  type = number
  default = "1050"
}

source "proxmox-iso" "windows2022" {
 
  # Proxmox Host Conection
  node                 = var.proxmox_node
  username             = var.proxmox_api_token_id
  token                = var.proxmox_api_token
  proxmox_url          = var.proxmox_url
  insecure_skip_tls_verify =  true

  # BIOS - UEFI
  bios = "ovmf"

  # Machine type
  # Q35 less resource overhead and newer chipset
  machine = "pc"

  efi_config {
    efi_storage_pool = var.efi_storage
    pre_enrolled_keys = true
    efi_type = "4m"
  }

  # Windows Server ISO File
  boot_iso {
    type                    = "ide"
    iso_file                = var.windows_iso
    unmount                 = true
   # iso_checksum            = var.rocky_template_iso_checksum
  }

  additional_iso_files {
    cd_files = ["./config/drivers/*","./config/scripts/ConfigureRemotingForAnsible.ps1"]
    cd_content = {
      "autounattend.xml" = templatefile("./config/templates/autounattend.pkrtpl", {password = var.winrm_password, cdrom_drive = var.cdrom_drive, index = lookup(var.image_index, var.template, "2")})
    }
    cd_label = "Unattend"
    iso_storage_pool = var.iso_storage
    unmount = true
    type = "sata"
  }
 

  template_name = "templ-win2022-${var.template}"
  template_description = "Windows ${var.template} Created on: ${timestamp()}"
  memory = var.memory
  cores = var.cores
  sockets = var.socket
  cpu_type = "host"
  os = "win11"
  scsi_controller = "virtio-scsi-pci"
  cloud_init = true
  cloud_init_storage_pool = var.cloud_init_storage
  vm_id           = var.vm_id
 
  # Network
  network_adapters {
    model = "virtio"
    bridge = var.bridge
  }

  # Storage
  disks  {
    storage_pool = var.disk_storage
    type = "scsi"
    disk_size = var.disk_size_gb
    format = "qcow2"
  }

  # WinRM
  communicator          = "winrm"
  winrm_username        = var.winrm_user
  winrm_password        = var.winrm_password
  winrm_timeout         = "12h"
  winrm_port            = "5986"
  winrm_use_ssl         = true
  winrm_insecure        = true

  # Boot
  boot_wait = "7s"
  boot_command = [
    "<enter>"
  ]

}

build {
  name = "Proxmox Build"
  sources = ["source.proxmox-iso.windows2022"]

  provisioner "windows-restart" {
  }

  # provisioner "windows-update" {
  #   search_criteria = "IsInstalled=0"
  #   filters = [
  #     "exclude:$_.Title -like '*Preview*'",
  #     "include:$true",
  #   ]
  #   update_limit = 25
  # }

  provisioner "powershell" {
    script = "../common/windows/scripts/InstallCloudBase.ps1"
    pause_before = "1m"
  }

  provisioner "file" {
    source = "./config/cloudinit"
    destination = "C://Program Files//Cloudbase Solutions//Cloudbase-Init//conf"
  }

  provisioner "powershell" {
    inline = [
      "Set-Service cloudbase-init -StartupType Manual",
      "Stop-Service cloudbase-init -Force -Confirm:$false"
      ]
  }

  provisioner "powershell" {   
    inline = [
      "Set-Location -Path \"C:\\Program Files\\Cloudbase Solutions\\Cloudbase-Init\\conf\"",
      "C:\\Windows\\System32\\Sysprep\\Sysprep.exe /oobe /generalize /unattend:unattend.xml"
     ]
  }

}
 
This appears to be an issues with the machine and cpu type.

I switched it to q35/x86-64-v2-AES and the clouddrive is visible.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!