You've successfully subscribed to Nuvotex Blog
Great! Next, complete checkout for full access to Nuvotex Blog
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Billing info update failed.

Change BIOSGUID in Hyper-V machines

Using templated virtual machines on hyper-v comes with some issues if you need to ensure that each VM has a unique identity. This guide will show how you'll assign a unique identity for linux VMs.

Daniel Nachtrub
Daniel Nachtrub

A thing most people don't know is that when importing virtual machines hyper-v also imports base configuration like BIOSGUID - which is somehow expected, as you won't want to change anything on your system if you export and import again. In case you're exporting and importing for deployment purpose you might want to change this identifier. This is especially relevant if you are running virtual machines on larger scale and you're using templated virtual machines that are deployed several times.

Why change BIOSGUID?

Operating systems often rely on some hardware fingerprint to generate a unique id of the host. Linux for example generates product_uuid based on the BIOSGUID (accessible via /sys/class/dmi/id/product_uuid). If you're running workloads like kubernetes that require unique identifiers of each host, you might avoid using templated VMs or just reset the identifier for a particular VM.

How to change the BIOSGUID?

Modifying these kind of settings can be done at any stage of the virtual machine (no need to reinstall, redeploy, etc.) - the VM has just to be turned off, so you'll need to plan some brief downtime for the adjusment.

The following script will use WMI to adjust the virtualmachine settings and apply just a new, randomly assigned GUID.

$VMName = '<NameOfVirtualMachine>'
$MSVM = gwmi -Namespace root\virtualization\v2 -Class msvm_computersystem -Filter "ElementName = '$VMName'"
# get current settings object
$MSVMSystemSettings = $null
foreach($SettingsObject in $MSVM.GetRelated('msvm_virtualsystemsettingdata'))
    $MSVMSystemSettings = [System.Management.ManagementObject]$SettingsObject
# assign a new id
$MSVMSystemSettings['BIOSGUID'] = "{$(([System.Guid]::NewGuid()).Guid.ToUpper())}"
$VMMS = gwmi -Namespace root\virtualization\v2 -Class msvm_virtualsystemmanagementservice
# prepare and assign parameters
$ModifySystemSettingsParameters = $VMMS.GetMethodParameters('ModifySystemSettings')
$ModifySystemSettingsParameters['SystemSettings'] = $MSVMSystemSettings.GetText([System.Management.TextFormat]::CimDtd20)
# invoke modification
$VMMS.InvokeMethod('ModifySystemSettings', $ModifySystemSettingsParameters, $null)
assign a new bios guid

That's all you need to do - starting the VM will show a new BIOSGUID, so that you can keep using your images without having issues on duplicate identifiers!


Daniel Nachtrub

Kind of likes computers. Linux foundation certified: LFCS / CKA / CKAD / CKS. Microsoft certified: Cybersecurity Architect Expert & Azure Solutions Architect Expert.