I agree -- not many examples of this common scenario. I think part of the problem you're facing above is that you're referencing a partition instead of a disk in disk_setup.
With Azure, the first data disk attached to the VM will usually be identified as /dev/sdc
, the second will be /dev/sdd
, and so on. This isn't guaranteed, however. The documentation here indicates that there are circumstances which can result in a different drive letter being assigned. As a result, we'll reference the disks using a build-in alias. This alias is guarantee to always be mapped using the LUN assigned in the ARM template (or disk definition). These aliases follow the form /dev/disk/azure/scsi1/lun#
(with partitions aliased as /dev/disk/azure/scsi1/lun#-part#
).
If you're using ARM, the template will include a reference in the VM definition to the drive. As part of that definition, you will specify the LUN value. You can reference that assigned value in your cloud-init. For example, the following ARM snippet will create /dev/disk/azure/scsi1/lun0
:
"dataDisks": [
{
"lun": 0,
"name": "[concat(variables('vmName'),'-datadisk0')]",
"createOption": "Attach",
"managedDisk":
{
"id": "[resourceId('Microsoft.Compute/disks/',
concat(variables('vmName'),'-datadisk0'))]"
}
},
Knowing this, we can construct the contents for a cloud-config. First, we define the data disk. I suggest using GPT as the table type for to enable support for disks and partitions that are > 2TiB.
disk_setup:
/dev/disk/azure/scsi1/lun0:
table_type: gpt
layout: True
overwrite: True
Next, we specify the file system setup for the disks. We reference each partition and declare the file system to be used.
fs_setup:
- device: /dev/disk/azure/scsi1/lun0
partition: 1
filesystem: ext4
Finally, we mount the partitions. The process used by cloud-init will create the folders and mount the specified partitions. I'm using the recommended nofail
(ensures the VM can boot in the event of issues or a detached drive) along with noexec
(which prevents executing binaries on that partition). Since we've placed the file system on the first partition of lun0, we need to mount lun0-part1
.
mounts:
- ["/dev/disk/azure/scsi1/lun0-part1", "/datadisk", auto, "defaults,noexec,nofail"]