Technical

Proxmox Read VMID From Inside Guest: SMBIOS vs Cloud-Init vs Guest Agent

Proxmox Read VMID From Inside Guest: SMBIOS vs Cloud-Init vs Guest Agent

Proxmox read VMID from inside guest is one of those things that should be easy but isn’t obvious. Three ways actually work: SMBIOS serial via dmidecode, cloud-init instance-id, and the guest agent. Here’s what each gives you.

Power lines and a tree under a clear blue sky in Lang Son, Vietnam.

SMBIOS serial with dmidecode

This is the most reliable method on a normal VM. Proxmox sets the SMBIOS serial to the VMID by default. Just run:

sudo dmidecode -s system-serial-number

You’ll get something like 100 or whatever your VMID is. It’s stable across reboots and doesn’t need any extra packages. If you see Not Specified, the VM config probably has a custom serial set or SMBIOS is disabled.

Cloud-init instance-id

If you use cloud-init images, the instance-id is stored in /var/lib/cloud/data/instance-id. That’s not the VMID though. It’s a UUID generated by cloud-init, usually something like iid-dhcp-12345. You can map it back to the VMID on the host with qm cloudinit dump <vmid>, but that’s clunky. The instance-id is stable per VM, but it’s not human-readable and it’s not the VMID.

Detailed image of a server rack with glowing lights in a modern data center.

Guest agent

If the guest agent is installed and running, the host knows the VMID, but the guest doesn’t directly. You can query the agent from the host with qm agent <vmid> network-get-interfaces, but that’s backwards. Inside the guest, there’s no simple command to get the VMID from the agent. The agent is useful for the host to identify the guest, not the other way around.

Which one to use

For most cases, dmidecode -s system-serial-number is the answer. It’s simple, it’s the actual VMID, and it works on any Linux guest. Cloud-init instance-id is only useful if you’re already using cloud-init and need a stable identifier for automation. The guest agent doesn’t help you read the VMID from inside the guest at all.

If you’re dealing with LXC containers instead of VMs, the situation is different. You can read the container ID from /etc/hostname if you set it, or check /proc/1/environ for container=lxc, but there’s no direct VMID equivalent. For VMs, stick with SMBIOS.

Related: Proxmox LXC USB Passthrough Device Name Colon covers another identity quirk with containers.

Leave a comment

Comments are reviewed before they appear. Your email is never published.