diff --git a/src/platform/backends/qemu/qemu_vm_process_spec.cpp b/src/platform/backends/qemu/qemu_vm_process_spec.cpp index e18634de26..624daf0c99 100644 --- a/src/platform/backends/qemu/qemu_vm_process_spec.cpp +++ b/src/platform/backends/qemu/qemu_vm_process_spec.cpp @@ -38,7 +38,6 @@ mp::QemuVMProcessSpec::QemuVMProcessSpec(const mp::VirtualMachineDescription& de QStringList mp::QemuVMProcessSpec::arguments() const { QStringList args; - if (resume_data) { args = resume_data->arguments; @@ -63,10 +62,12 @@ QStringList mp::QemuVMProcessSpec::arguments() const } else { + // The UUID needs to be unique per VM and must be consistent across boots. + const auto vm_uuid = utils::make_uuid(desc.vm_name); auto mem_size = QString::number(desc.mem_size.in_megabytes()) + 'M'; /* flooring here; format documented in `man qemu-system`, under `-m` option; including suffix to avoid relying on default unit */ - + // clang-format off args << platform_args; // The VM image itself args << "-device" @@ -97,6 +98,9 @@ in `man qemu-system`, under `-m` option; including suffix to avoid relying on de << "-nographic"; // Cloud-init disk args << "-cdrom" << desc.cloud_init_iso; + // To make `/sys/class/dmi/id/product_uuid` present + args << "-uuid" << vm_uuid; + // clang-format on } for (const auto& [_, mount_data] : mount_args) diff --git a/tests/unit/qemu/test_qemu_vm_process_spec.cpp b/tests/unit/qemu/test_qemu_vm_process_spec.cpp index 167317a7e8..df8db70224 100644 --- a/tests/unit/qemu/test_qemu_vm_process_spec.cpp +++ b/tests/unit/qemu/test_qemu_vm_process_spec.cpp @@ -65,7 +65,7 @@ TEST_F(TestQemuVMProcessSpec, defaultArgumentsCorrect) #else const auto storage_interface = "virtio-scsi-pci"; #endif - + const auto expected_uuid = multipass::utils::make_uuid(desc.vm_name); EXPECT_EQ(spec.arguments(), QStringList({"--enable-kvm", "-nic", @@ -89,6 +89,8 @@ TEST_F(TestQemuVMProcessSpec, defaultArgumentsCorrect) "-nographic", "-cdrom", "/path/to/cloud_init.iso", + "-uuid", + expected_uuid, "-virtfs", "local,security_model=passthrough,uid_map=1000:1000,gid_map=1000:1000," "path=path/to/target,mount_tag=m810e457178f448d9afffc9d950d726"}));