简体   繁体   中英

Unable to add custom data with AZ CLI az create vm command

I am running the below command to create a VM on my resource group, however when I login, I don't see the file /root/hello.txt .

az vm create --name "my_vm" --resource-group "my_rg" --image "centos" --admin-username "centos" --os-disk-size-gb "100" --vnet-name "my_vnet" --subnet "public-4" --ssh-key-values "ssh-rsa ..." --size "Standard_DS1_v2" --nsg "my_nsg" --custom-data '#!/bin/bash
        touch /root/hello.txt
        ' --data-disk-sizes-gb "10"

Granted, there are newlines that didn't paste nicely, but it shouldn't matter. Also, I don't want to pass a file path. I need to pass the text, just like I do for AWS.

The ultimate goal is to run below bash script to increase the partition of the OS disk, which is far too small.

#!/bin/sh
fdisk /dev/sda <<EOF
u
p
d
2
n
p
2


w
EOF
touch fdisk.log
reboot
xfs_growfs -d /dev/sda2
touch xfs.log

First of all, the Custom Data is a script or other metadata that can be injected into a Microsoft Azure virtual machine at provision time . Currently, there are cloud-init preinstalled and configured images in Azure. It can act on the custom data sent during provisioning using a cloud-init configuration file or simply a shell script (as long as it starts with #! , then cloud-init will execute it).

On Linux, this data is passed to the VM via the ovf-env.xml file, which is copied to the /var/lib/waagent directory during provisioning. Newer versions of the Microsoft Azure Linux Agent will also copy the base64-encoded data to /var/lib/waagent/CustomData as well for convenience.

Read Custom Data and Cloud-Init on Microsoft Azure for more details.

Generally, Custom data is sent to the VM along with the other provisioning configuration information such as the new hostname, username, password, certificates and keys, etc. In this case, I don't think you can resize the partition of the OS disk using custom data at the provision time. It seems that it's impossible to do a reboot and interactive processing scripts in the custom data.

For more references, you can read

Resizing a Linux VM system disk in Microsoft Azure

Expand virtual hard disks on a Linux VM with the Azure CLI

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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