Windows VM and VMID Awareness

Waywatcher

Member
Jul 2, 2019
11
2
23
39
Good day all,

Apologies if this has been asked before but multiple web searches have not provided an answer. I have a need to be able to quickly spawn a linked clone with a specific VMID. When the clone boots into windows for the first time I want a powershell script to query its VMID and then use the VMID # as an append to a template.

E.G
Linked clone VMID 1020 Hostname: clone0000.contoso.com
Start
Load into Windows
Powershell: VMID 1020 -> Rename host: clone1020.contoso.com -> join AD.

I have had no luck being able to make it VMID aware which I think is for security reasons. QEMU Guest Agent?

My next idea was to statically assign a MAC address on the linked clone when spawned. That MAC will correlate with a DNS name that CAN be queried. But that adds something else I have not had luck figuring out. Reserve a range of MAC in proxmox so it never assigns them to other NIC.

I appreciate any advice, or guidance you can offer. I would be happy with links even. I may not need a full explanation but can possibly live with at least an example to work from.

Thank you so much,

Scott
 
Additionally, if the above is not best. Can I set any queried value when spawning the clone that Windows can then see?
 
A very unusual use case. I see a few options you could potentially try to tell the VMID to your guest:

1) Add a serial port to your VM and use a script on the Proxmox host to communicate the VMID this way.

You can use 'qm terminal <vmid>' to access a serial console from the host (check 'man qm').

2) Allow the VM network access to the host and query the API via a service user.

Security implications are yours to consider (depends on your environment), but you can at least restrict access to read-only on your VMs (check our docs, e.g. create a role that has only VM.Audit rights and assign it to your service user on just the cloned VM).

3) You can set the 'hv_vendor_id' CPU flag on your cloned VM to a value containing your VMID. However, I don't know how to access this value from the Windows guest, or if this is even possible in a script - theoretically it should be.

Reserve a range of MAC in proxmox so it never assigns them to other NIC.
That's currently not possible, although you can manually set MAC addresses when you create VMs.
 
A very unusual use case. I see a few options you could potentially try to tell the VMID to your guest:

1) Add a serial port to your VM and use a script on the Proxmox host to communicate the VMID this way.

You can use 'qm terminal <vmid>' to access a serial console from the host (check 'man qm').

2) Allow the VM network access to the host and query the API via a service user.

Security implications are yours to consider (depends on your environment), but you can at least restrict access to read-only on your VMs (check our docs, e.g. create a role that has only VM.Audit rights and assign it to your service user on just the cloned VM).

3) You can set the 'hv_vendor_id' CPU flag on your cloned VM to a value containing your VMID. However, I don't know how to access this value from the Windows guest, or if this is even possible in a script - theoretically it should be.


That's currently not possible, although you can manually set MAC addresses when you create VMs.

Thank you for these suggestions. We moved to look at the BIOS option for the resolution. I still need to look into how to call this from qm create but the WebUI method is as follows:
  1. Shutdown VM -> Options
  2. SMBIOS Settings -> Add VMID to Serial line.
  3. Start VM
CMD: wmic bios get serialnumber

Powershell: gwmi win32_bios | Select-Object -ExpandProperty SerialNumber

To solve my needs I can then assign this as a variable:

$uuid = gwmi win32_bios | Select-Object -ExpandProperty SerialNumber
$ComputerName = "clone$uuid"
Write-Host "The next available builder name is $ComputerName"

Thinking for command line (Linked Clone): Assuming I dont need to specify storage etc since I am doing a linked clone.

qm clone <vmid> <newID> --description <> --name <> --target <node> --smbios1 [serial=<vmid>]

Again thank you for your suggestions.

-Scott Connary
 

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!