Skip to content
Advertisement

Reliably targeting correct Azure Managed Disk on a Linux VM using an Ansible playbook

How do I reliably partition and mount the file system of an Azure Managed Disk on a Linux VM using Ansible playbooks?

I can create an Azure Managed Disk with azure_rm_manageddisk and assign it to a VM instance. My issue starts when I’m trying to take the disk into use. I just don’t know how to reliably target the correct managed disk anymore for partitioning and file system mounting.

Neither azure_rm_manageddisk nor azure_rm_manageddisk_info seems to return a reliable, unambigious id for the disk that could be referred from the OS side.

I don’t think the disk even shows up on blkid before it has been partitioned.

Microsoft has documented that

By default when you create a VM, Azure provides you with an OS disk (/dev/sda) and a temporary disk (/dev/sdb). All additional disks you add show up as /dev/sdc, /dev/sdd, /dev/sde and so on.

(source: https://learn.microsoft.com/en-us/azure/virtual-machines/linux/optimization)

but this doesn’t seem reliable. I think I saw my VM have a setup different from this right after creation and this is definitely going to change after reboot. So no trusting /dev/sdc in my opinion. A rerun of a playbook could cause all kinds of havoc, if the block device files aren’t stable. I actually managed already to make my root partition visible at /media/my_data_disk_mount.

Is this just something I will have to handle manually? Seems odd. It’s such a common thing to do.

There’s also /dev/disk/azure/resource for example, but that seemed to lead to messy results also.

(source: https://learn.microsoft.com/en-us/azure/virtual-machines/troubleshooting/troubleshoot-device-names-problems)

Maybe something with the LUN numbers?

Advertisement

Answer

According to the messages, you want to find the correct disk and get the UUID to mount. What you think is right. You can use the LUN of the disk to judge which one is you want. You can use the command tree /dev/disk/azure and it shows as below:

enter image description here

You can see the disk /dev/sdc use the lun1. And you can also find which disk is using the lun1in the Azure portal. And then you can use the command sudo blkid to get the UUID after you init the disk:

enter image description here

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement