Proxmox debian cloud-init disk name unstable

Dec 13, 2021
24
5
8
Hi I have the following script
Bash:
qm create "$VMID" --name "debian-docker" --memory 10240 --sockets 1 --core 4 --net0 virtio="46:4A:5E:3C:8A:55",bridge=vmbr0 --description "Debian bullseye cloud image" --agent enabled=1
qm set "$VMID" --ide2 "$STORAGE:cloudinit"
qm set "$VMID" --serial0 socket --vga serial0
qm importdisk "$VMID" "/tmp/$IMAGE" "$STORAGE"
qm set "$VMID" --scsihw virtio-scsi-pci --scsi0 "$STORAGE:vm-$VMID-disk-0,backup=0"
# Move cloud init file to snipet folder
qm set "$VMID" --cicustom "user=snippets:snippets/$VMID-$SNIPPETNAME"
qm set "$VMID" --boot c --bootdisk scsi0
qm set "$VMID" --scsi1 "$STORAGE:128"
qm start "$VMID"
This does the following:
  1. creates a new VM
  2. adds a debian no cloud as boot disk
  3. sets vga via serial
  4. adds cloud init
  5. adds a secondary data disk
Then in my cloud init file I have the following:
YAML:
disk_setup:
  /dev/sda:
    table_type: 'gpt'
    layout:
      - 95
      - 5

fs_setup:
  - label: persistent_app
    filesystem: 'ext4'
    device: /dev/sda1
    partition: 'auto'
  - label: persistent_user
    filesystem: 'ext4'
    device: /dev/sda2
    partition: 'auto'

The problem is that it seems a bit random if the data disk is mounted under /dev/sda or /dev/sdb is there some way to force them to always be in the same order?
 
Maybe use /dev/disk/by-path/...? Those paths depend on the SCSI/IDE controller and the SCSI/IDE number of the drive (which you control in the VM configuration).
 
Maybe use /dev/disk/by-path/...? Those paths depend on the SCSI/IDE controller and the SCSI/IDE number of the drive (which you control in the VM configuration).
Thanks that makes more sense, so for my current disk the path is then /dev/disk/by-path/pci-0000:00:05.0-scsi-0:0:0:1.
I'm running debian cloud image as stated and it uses cloud-init 20.4.1 but it seems the following doesn't work
Code:
disk_aliases: #Found a bug saying the name should be disk not device so tried both just to be sure
  'data0': '/dev/disk/by-path/pci-0000:00:05.0-scsi-0:0:0:1'

device_aliases:
  'data0': '/dev/disk/by-path/pci-0000:00:05.0-scsi-0:0:0:1'

disk_setup:
  data0:
    table_type: 'gpt'
    layout:
      - 95
      - 5

fs_setup:
  - label: persistent_app
    filesystem: 'ext4'
    device: data0.1
    partition: 'auto'
  - label: persistent_user
    filesystem: 'ext4'
    device: data0.2
    partition: 'auto'
When I inspect the disk using parted it just says Partition Table: unknown so I'm guessing device_aliases isn't supported even when its in the documentation? https://cloudinit.readthedocs.io/en/20.4.1/topics/modules.html?highlight=fs_setup#disk-setup

Sadly I'm having a hard time finding the log line where the disk_setup fails so I'm not 100% sure.

So then I tried the following:
Code:
disk_setup:
  '/dev/disk/by-path/pci-0000:00:05.0-scsi-0:0:0:1':
    table_type: 'gpt'
    layout:
      - 95
      - 5

fs_setup:
  - label: persistent_app
    filesystem: 'ext4'
    device: '/dev/disk/by-path/pci-0000:00:05.0-scsi-0:0:0:1'
    partition: 1
    partition: 'auto'
  - label: persistent_user
    filesystem: 'ext4'
    device: '/dev/disk/by-path/pci-0000:00:05.0-scsi-0:0:0:1'
    partition: 2
    partition: 'auto'
Now it formats the disk correctly with 2 partitions, but the partitions aren't formatted..

The problem seems to be that the partitions are listed under /dev/disk/by-path/ with -part1/2 instead of .1/2 so I have no way of specifying the path to fs_setup as it just looks for the last . in the path and everything behind that is counted as the partition, but in this case the device name contains a dot. I even tried with pci-0000:00:05.0-scsi-0:0:0:1.-part1 but the dot is kept when it looks for the device and causes it to fail.
 
Sorry but I have no experience with cloudinit. I only know that the paths under /dev/disk/by-... are much more stable than /dev/sd*.
- label: persistent_app
filesystem: 'ext4'
device: '/dev/disk/by-path/pci-0000:00:05.0-scsi-0:0:0:1'
partition: 1
partition: 'auto'
I would not expect partition twice. I guess you already tried something like this?
Code:
      - label: persistent_app
        filesystem: 'ext4'
        device: '/dev/disk/by-path/pci-0000:00:05.0-scsi-0:0:0:1-part1'
 

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!