Lately I’ve been using Hashicorp Packer to automate my golden master #Citrix images. A few years back, I was mostly using the normal BIOS setting for the virtual machine configuration. Fast forward to now, it is best practice to configure the firmware as EFI.
In essence, UEFI is the preferred choice for modern computers because it offers a faster, more secure, and more user-friendly experience compared to the older BIOS standard
When using “C:\Program Files\Citrix\Provisioning Services\ImagingWizard.exe” with BIOS, you specifically tell what volume to convert to VHDX. Notice the “C:” in the following code.
start-process -Wait "C:\Program Files\Citrix\Provisioning Services\ImagingWizard.exe" -ArgumentList "p2vhdx $newname ""\\Server\share$"" C: /QuitWhenDone"
When using the new UEFI firmware format, you can’t specify a volume. This is denoted in the documentation when running “imagingwizard.exe /?”. The correct format would look something like this.
start-process -Wait "C:\Program Files\Citrix\Provisioning Services\ImagingWizard.exe" -ArgumentList "p2vhdx $newname ""\\Server\share$"" /QuitWhenDone"
Notice the format does NOT include the “C:” volume. Where you might run into an issue is when using Packer for automated builds. Majority of the build examples I see use the “floppy_files” parameter to include the autounattend.xml file to automate the Windows OS installation, as well as copy certain scripts and files that are needed, such as installing VMware Tools, setting WinRM/SSH connection settings, enabling RDP, etc… The problem with using the Floppy technique and using UEFI format is that imagingwizard.exe does not like the floppy drive. Just opening the imagingwizard.exe you’ll get the following error: “Failed to open disk \\.\PhsicalDrive4294967295. The system cannot find the file specified” This can also be found in the imagingwizard.exe log location in “C:\programdata\Citrix\imagingwzard”.
You have a couple different options here. The easiest is to disable the floppy drive from the Windows OS perspective.
Get-PnpDevice -Class "FloppyDisk" | Disable-PnpDevice -Confirm:$False
This disables the floppy drive and imagingwizard.exe no longer presents the previous error. Note, if you still need to reference any files that you stored on the floppy drive, you can simply run the code above, but use the Enable-PnPdevice.
Another method would be to use the cd_files parameter. Instead of using a floppy drive, this will create another CD Drive. An example of that would look something like this:
cd_files = [
"${path.root}/setup/*"
]
cd_content = {
"autounattend.xml" = templatefile("${abspath(path.root)}/setup/autounattend.pkrtpl.hcl", {
PACKER_BuildMachine = var.PACKER_BuildMachine
PACKER_LocalAdminUser = var.PACKER_LocalAdminUser
PACKER_LocalAdminPass = var.PACKER_LocalAdminPass
vm_inst_os_eval = var.vm_inst_os_eval
vm_inst_os_language = var.vm_inst_os_language
vm_inst_os_keyboard = var.vm_inst_os_keyboard
vm_inst_os_image = var.vm_inst_os_image_standard_desktop
vm_inst_os_key_standard = var.vm_inst_os_key_standard
vm_inst_os_timezone = var.vm_inst_os_timezone
vm_inst_os_org = var.vm_inst_os_org
})
}
I really like this new’ish Packer technique, as it allows you to insert variables into the autounattend.xml. This way you don’t have to have your passwords in plaintext and also allows you to use 1 autounattend.xml for multiple builds, but use different Operating Systems, timezones, and any other settings you’d like to configure.
Note: the cd_files approach does require that you have ocsdimg, which is documented here: https://developer.hashicorp.com/packer/integrations/hashicorp/vmware/latest/components/builder/iso
This basically takes the file path in cd_files and uses oscdimg to create a new ISO to mount to the virtual machine. If you don’t have oscdimg then you will see an error like this “could not find a supported CD ISO creation command (the supported commands are: xorriso, mkisofs, hdiutil, oscdimg)”. You’ll need to install oscdimg, which can be done by installing the Microsoft ADK and choosing the ‘deployment tools’ option.
Hope this saves some of you time in troubleshooting the imagingwizard.exe with Packer.
Happy Automating!