0

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?

xtrom0rt
  • 183
  • 1
  • 11
  • Did you try to gather facts on the vm and look at `ansible_devices`? Quick oneliner example to have a look at the var structure on your localhost: `ansible localhost -m setup -a filter=ansible_devices`. You should have what you're looking for in there on your remote target. – Zeitounator Dec 03 '20 at 09:53
  • If you do not trust the things such as `/dev/sdc`, you can use the UUID as the advice the troubleshooting provide. And what else do you expect? – Charles Xu Dec 04 '20 at 08:30
  • As I see it, both of these suggestions are valid, but there's a missing link somewhere. How am I supposed to know which disk is the one that I want? I've already sort of lost the handle. Basically I could try to infer which disk to target based on disk size, but that smells bad. There are three or more disks to choose from. I have to pick one before I can get get the correct UUID, for example. How do I go about that step in a reliable manner? I don't know the UUID at this stage and must find out which disk to read the UUID from. There's probably something really simple I'm missing... – xtrom0rt Dec 04 '20 at 09:02
  • Any more updates on this question? Does it solve your problem? – Charles Xu Dec 11 '20 at 06:19

1 Answers1

1

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

Charles Xu
  • 29,862
  • 2
  • 22
  • 39