Created
November 14, 2022 15:04
-
-
Save peteraritchie/68b50ff6d310b6f2be240bc2251fab0c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
az configure --defaults location=eastus | |
az configure --defaults group="resourceGroup" | |
# Create VM in default resource group and default location | |
az vm create \ | |
--name support-web-vm01 \ | |
--image Canonical:UbuntuServer:16.04-LTS:latest \ | |
--size Standard_DS1_v2 \ | |
--admin-username azureuser \ | |
--generate-ssh-keys | |
# add new empty disk to VM | |
az vm disk attach \ | |
--vm-name support-web-vm01 \ | |
--name uploadDataDisk1 \ | |
--size-gb 64 \ | |
--sku Premium_LRS \ | |
--new | |
# get ip address of VM | |
ipaddress=$(az vm show \ | |
--name support-web-vm01 \ | |
--show-details \ | |
--query [publicIps] \ | |
--output tsv) | |
# ssh to VM w/IP and run `lsblk` to initialize the disk | |
ssh azureuser@$ipaddress lsblk | |
# further initialization | |
az vm extension set \ | |
--vm-name support-web-vm01 \ | |
--name customScript \ | |
--publisher Microsoft.Azure.Extensions \ | |
--settings '{"fileUris":["https://raw.githubusercontent.com/MicrosoftDocs/mslearn-add-and-size-disks-in-azure-virtual-machines/master/add-data-disk.sh"]}' \ | |
--protected-settings '{"commandToExecute": "./add-data-disk.sh"}' | |
# resize a disk | |
az vm deallocate --name support-web-vm01 | |
az disk update --name uploadDataDisk1 --size-gb 128 | |
az vm start --name support-web-vm01 | |
# expand partition after resize | |
ipaddress=$(az vm show --name support-web-vm01 -d --query [publicIps] -o tsv) | |
## ssh azureuser@$ipaddress lsblk | |
az vm extension set \ | |
--vm-name support-web-vm01 \ | |
--name customScript \ | |
--publisher Microsoft.Azure.Extensions \ | |
--settings '{"fileUris":["https://raw.githubusercontent.com/MicrosoftDocs/mslearn-add-and-size-disks-in-azure-virtual-machines/master/resize-data-disk.sh"]}' \ | |
--protected-settings '{"commandToExecute": "./resize-data-disk.sh"}' | |
## ssh azureuser@$ipaddress lsblk | |
ssh azureuser@$ipaddress df -h |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment