Skip to content

Latest commit

 

History

History
58 lines (40 loc) · 2.37 KB

create-vm-from-managed-os-disks.md

File metadata and controls

58 lines (40 loc) · 2.37 KB
title description services author manager editor ms.service ms.devlang ms.topic ms.tgt_pltfrm ms.date ms.author ms.custom
Create a VM by attaching a managed disk as OS disk - CLI Sample
Azure CLI Script Sample - Create a VM by attaching a managed disk as OS disk
virtual-machines-linux
ramankumarlive
kavithag
ramankum
azure-disk-storage
azurecli
sample
vm-linux
02/23/2022
ramankum
mvc, devx-track-azurecli

Create a virtual machine using an existing managed OS disk with CLI

This script creates a virtual machine by attaching an existing managed disk as OS disk. Use this script in preceding scenarios:

  • Create a VM from an existing managed OS disk that was copied from a managed disk in different subscription
  • Create a VM from an existing managed disk that was created from a specialized VHD file
  • Create a VM from an existing managed OS disk that was created from a snapshot

[!INCLUDE quickstarts-free-trial-note]

[!INCLUDE azure-cli-prepare-your-environment.md]

Sample script

[!INCLUDE cli-launch-cloud-shell-sign-in.md]

Run the script

:::code language="azurecli" source="~/azure_cli_scripts/virtual-machine/create-vm-attach-existing-managed-os-disk/create-vm-attach-existing-managed-os-disk.sh" id="FullScript":::

Clean up resources

Run the following command to remove the resource group, VM, and all related resources.

az group delete --name myResourceGroupName

Sample reference

This script uses the following commands to get managed disk properties, attach a managed disk to a new VM and create a VM. Each item in the table links to command specific documentation.

Command Notes
az disk show Gets managed disk properties using disk name and resource group name. Id property is used to attach a managed disk to a new VM
az vm create Creates a VM using a managed OS disk

Next steps

For more information on the Azure CLI, see Azure CLI documentation.

Additional virtual machine CLI script samples can be found in the Azure Linux VM documentation.