简体   繁体   English

使用 Ansible 剧本在 Linux VM 上可靠地定位正确的 Azure 托管磁盘

[英]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?如何使用 Ansible 剧本在 Linux VM 上可靠地分区和挂载 Azure 托管磁盘的文件系统?

I can create an Azure Managed Disk with azure_rm_manageddisk and assign it to a VM instance.我可以使用azure_rm_manageddisk创建一个 Azure 托管磁盘并将其分配给 VM 实例。 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. azure_rm_manageddiskazure_rm_manageddisk_info似乎都没有为可以从操作系统端引用的磁盘返回可靠、明确的 ID。

I don't think the disk even shows up on blkid before it has been partitioned.我不认为磁盘在分区之前甚至不会出现在blkid上。

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).默认情况下,当您创建 VM 时,Azure 会为您提供一个操作系统磁盘 (/dev/sda) 和一个临时磁盘 (/dev/sdb)。 All additional disks you add show up as /dev/sdc, /dev/sdd, /dev/sde and so on.您添加的所有其他磁盘显示为 /dev/sdc、/dev/sdd、/dev/sde 等。

(source: https://learn.microsoft.com/en-us/azure/virtual-machines/linux/optimization ) (来源: 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.我想我看到我的 VM 在创建后立即具有与此不同的设置,并且这肯定会在重新启动后发生变化。 So no trusting /dev/sdc in my opinion.所以我认为不要信任/dev/sdc A rerun of a playbook could cause all kinds of havoc, if the block device files aren't stable.如果块设备文件不稳定,重新运行 playbook 可能会造成各种破坏。 I actually managed already to make my root partition visible at /media/my_data_disk_mount .我实际上已经设法让我的根分区在/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.例如,还有/dev/disk/azure/resource ,但这似乎也会导致混乱的结果。

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

Maybe something with the LUN numbers?也许有 LUN 编号?

According to the messages, you want to find the correct disk and get the UUID to mount.根据消息,您想找到正确的磁盘并获取要挂载的 UUID。 What you think is right.你认为是对的。 You can use the LUN of the disk to judge which one is you want.你可以通过磁盘的LUN来判断你要的是哪个。 You can use the command tree /dev/disk/azure and it shows as below:您可以使用命令tree /dev/disk/azure ,它显示如下:

在此处输入图像描述

You can see the disk /dev/sdc use the lun1.可以看到磁盘/dev/sdc使用的是 lun1。 And you can also find which disk is using the lun1in the Azure portal.您还可以在 Azure 门户中找到哪个磁盘正在使用 lun1。 And then you can use the command sudo blkid to get the UUID after you init the disk:然后您可以在初始化磁盘后使用命令sudo blkid获取 UUID:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM