Set fixed UUID for all disks in a VM

Hell,
I installed a K8s (Kubernetes) with several QEMU disks in an Ubuntu VM.
The challenge is that after a restart of the VM, the disks are no longer the same UUID as during installation.
This results in K8s not starting anymore.
In the config (/etc/pve/qemu-server/<VMID>.conf) I can set a single UUID. If I have understood correctly, this UUID is only set for the boot disk (ubuntu).
Is there a way to set the UUID's for all disks?
Perhaps there is a parameter that ensures that all disks are assigned the UUID they were given the first time you started them.
I am open to any solutions.
 
AFAIK, you cannot influence the disk UUID in your VM from PVE. The UUID you can set is the system UUID, not the filesystem UUID.
 
Ok, first thanks for your response
That I have understood correctly, this means that there is no option to set the scsi disks 1 to 9 (see screenshot) to always have the same UUID when booting.
It would be enough for me if the UUID would not change when booting.
In the /etc/pve/qemu-server/<VMID>.conf I can set a UUID for the boot disk (scsi0) and this is also retained when booting.

Then I will submit it as a change request.
Can someone tell me how and where I can do this?

1721979005311.png
 
That I have understood correctly, this means that there is no option to set the scsi disks 1 to 9 (see screenshot) to always have the same UUID when booting.
It would be enough for me if the UUID would not change when booting.
I don't understand what a UUID for a disk should be. Do you mean the WWN?
Could you try to explain/show what you mean that changes inside of your guest?

You can however give the disk a serial, that may be used to generate an UUID inside of the guest? You can just add it as ,serial=1234
(source)


Can someone tell me how and where I can do this?
Feature requests go to the bug tracker.
 
FYI, the WWN can be set via CLI, but is not exposed in the UI, e.g.
Code:
qm set 118 --scsi1 lvmthin:vm-118-disk-0,wwn=0x5566777799999999
 
You can also set serial=<max-20-characters> accoring to the Documentation (in the same Way as @fiona explained), but it will require a custom UDEV Rule in your VM ;) .

I played a bit around with the different Bus Types (SATA, IDE, SCSI, VIRTIO, USB) and I think this covers most Cases (although I didn't test it *that* much):
Code:
# ********************************************************************************************************************************
# **IMPORTANT**:  Support for REMOVING Symlinks was introduced in Systemd PR #26081 (merged on 2023-01-17)                    ****
#                 On Systems featuring older Packages (e.g. Debian Stable) the corresponding Lines might need to be disabled   ***
# ********************************************************************************************************************************

# Add Symlink Rule for SCSI Devices
SUBSYSTEM=="block", ENV{ID_BUS}=="scsi", ENV{DEVTYPE}=="disk", ENV{ID_SCSI_SERIAL}=="?*", SYMLINK+="/dev/disk/by-id/scsi-$env{ID_VENDOR}_$env{ID_MODEL}_$env{ID_SCSI_SERIAL}"

SUBSYSTEM=="block", ENV{ID_BUS}=="scsi", ENV{DEVTYPE}=="partition", ENV{ID_SCSI_SERIAL}=="?*", ENV{ID_PART_ENTRY_NUMBER}=="?*", SYMLINK+="/dev/disk/by-id/scsi-$env{ID_VENDOR}_$env{ID_MODEL}_$env{ID_SCSI_SERIAL}-part$env{ID_PART_ENTRY_NUMBER}"

# Remove Symlink Rule for SCSI Devices
SUBSYSTEM=="block", ENV{ID_BUS}=="scsi", ENV{DEVTYPE}=="disk", ENV{ID_SERIAL}=="?*", SYMLINK-="/dev/disk/by-id/scsi-$env{ID_SERIAL}"

SUBSYSTEM=="block", ENV{ID_BUS}=="scsi", ENV{DEVTYPE}=="partition", ENV{ID_SERIAL}=="?*", SYMLINK-="/dev/disk/by-id/scsi-$env{ID_SERIAL}-part$env{ID_PART_ENTRY_NUMBER}"




# Add Symlink Rule for USB Devices
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ENV{DEVTYPE}=="disk", ENV{ID_USB_SERIAL_SHORT}=="?*", SYMLINK+="/dev/disk/by-id/usb-$env{ID_VENDOR}_$env{ID_MODEL}_$env{ID_USB_SERIAL_SHORT}"

SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ENV{DEVTYPE}=="partition", ENV{ID_USB_SERIAL_SHORT}=="?*", ENV{ID_PART_ENTRY_NUMBER}=="?*", SYMLINK+="/dev/disk/by-id/usb-$env{ID_VENDOR}_$env{ID_MODEL}_$env{ID_USB_SERIAL_SHORT}-part$env{ID_PART_ENTRY_NUMBER}"



# Add Symlink Rule for IDE/ATA Devices
SUBSYSTEM=="block", ENV{ID_BUS}=="ata", ENV{DEVTYPE}=="disk", ENV{ID_SERIAL_SHORT}=="?*", SYMLINK+="/dev/disk/by-id/ata-$env{ID_MODEL}_$env{ID_SERIAL_SHORT}"

SUBSYSTEM=="block", ENV{ID_BUS}=="ata", ENV{DEVTYPE}=="partition", ENV{ID_SERIAL_SHORT}=="?*", ENV{ID_PART_ENTRY_NUMBER}=="?*", SYMLINK+="/dev/disk/by-id/ata-$env{ID_MODEL}_$env{ID_SERIAL_SHORT}-part$env{ID_PART_ENTRY_NUMBER}"




# Add Symlink Rule for SATA Devices
SUBSYSTEM=="block", ENV{ID_BUS}=="ata", ENV{ID_ATA_SATA}=="1", ENV{DEVTYPE}=="disk", ENV{ID_SERIAL_SHORT}=="?*", SYMLINK+="/dev/disk/by-id/ata-$env{ID_MODEL}_$env{ID_SERIAL_SHORT}"

SUBSYSTEM=="block", ENV{ID_BUS}=="ata", ENV{ID_ATA_SATA}=="1", ENV{DEVTYPE}=="partition", ENV{ID_SERIAL_SHORT}=="?*", ENV{ID_PART_ENTRY_NUMBER}=="?*", SYMLINK+="/dev/disk/by-id/ata-$env{ID_MODEL}_$env{ID_SERIAL_SHORT}-part$env{ID_PART_ENTRY_NUMBER}"




# Add Symlink Rule for Virtio Devices
SUBSYSTEM=="block", ENV{DEVNAME}=="/dev/vd?*", ENV{DEVTYPE}=="disk", ENV{ID_SERIAL}=="?*", SYMLINK+="/dev/disk/by-id/virtio-$env{ID_SERIAL}"

SUBSYSTEM=="block", ENV{DEVNAME}=="/dev/vd?*", ENV{DEVTYPE}=="partition", ENV{ID_SERIAL}=="?*", ENV{ID_PART_ENTRY_NUMBER}=="?*", SYMLINK+="/dev/disk/by-id/virtio-$env{ID_SERIAL}-part$env{ID_PART_ENTRY_NUMBER}"

I didn't feel like I needed to remove other Stuff than the "wrong" SCSI Serial which does NOT match what you can set from the CLI.
But of course you can tweak it further if you run into some other "special" Case.

Some Relevant Notes:
Code:
# Prefixes for udevadm Information
# https://docs.oracle.com/en/operating-systems/oracle-linux/8/udev/udev-QueryingUdevandSysfs_prefixes_for_udevadm_information.html

# Monitor Rules Loading (trigger reloading from another Shell)
# udevadm monitor --subsystem-match="scsi"

# Get Device Properties
# udevadm info -p 'block/sdb' --query all --tree

# Or even more Information
# udevadm info -p 'block/sdb' --query all --tree --root --attribute-walk

# For use in Scripts
# udevadm info -p 'block/sdb' --query all --tree --root --attribute-walk --no-pager

# Simulate Rules
# udevadm test /dev/sdb

EDIT 1:
this of course requires that you set the serial (and Potentially the wwn as well) from the CLI though, e.g.:
Code:
qm set <vmid> --scsiX local-zfs:vm-<vmid>-disk-<diskid>,serial=<max-20-characters>,wwn=<16-hex-digits>

Where you can generate the 2 Parameters with:
Code:
# Generate random Serial Number
serial_number=$(uuidgen | sed -E "s|-||g" | cut -c 1-20)

And:
Code:
# Generate random WWN Number
wwn_number=$(uuidgen --hex | sed -E "s|-||g" | cut -c 1-16)

EDIT 2: updated Script to also create Symlinks for Partitions

EDIT 3: updated Script to check that Partition is set before attempting to create Partition Symlink
 
Last edited: