Attaching a Custom Disk to an Existing VM in Microsoft Azure

Hands-On Lab

 

Photo of Gary McLeary

Gary McLeary

Azure Training Architect I in Content

Length

00:30:00

Difficulty

Intermediate

In this lab, we are going to walk through the steps for uploading a VHD data disk with both PowerShell and the Azure Portal. This lab will simulate a scenario in which we have an on-premises environment with a data file that needs to be uploaded and then attached to an existing Virtual Machine that is located in the Azure Cloud. These are very important procedures. In the role of an Azure Administrator, we may need to migrate data or virtual machines from an on-premises environment into the Azure Cloud. We will accomplish these tasks primarily within the Azure portal using the GUI and PowerShell. Learning outcomes include the following: Gaining an understanding of the PowerShell command and the parameters required for uploading a VHD file into the Azure Storage Account Understanding of the different components within the Azure Storage account, and how they relate to the blob storage service and the VHD file

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Attach a Custom Disk to an Existing VM in Microsoft Azure

Introduction

In this lab, we are going to walk through the steps for uploading a VHD data disk with both PowerShell and the Azure Portal. This lab will simulate a scenario in which we have an on-premises environment with a data file that needs to be uploaded and then attached to an existing Virtual Machine that is located in the Azure Cloud.

The VHD required for this learning activity can be found here:
https://github.com/GaryMcLeary/70-533-Files/blob/master/file1.zip

Please remember to download and uncompress this file prior to trying to use the file in this Hands-On Lab.

Solution

  1. Log in to the Azure Portal using the credentials provided on the lab instructions page.

  2. Click on All resources on the left-hand menu.

  3. Click on lab-VM.

  4. Copy the Public IP address.

  5. Use the IP address to open a RDP session. Log in using the username "AZUREuser" and password "LA!2018!Lab" without the quotes.

Add the VHD to the Storage Account Using Cloud Shell

  1. In the Azure Portal, click on Storage accounts in the left-hand menu.

  2. Click on the provided storage account.

  3. Under Blob service, click Blobs.

  4. Click + Container.

  5. Enter a Name vhd.

  6. Click OK.

  7. Click on the >_ icon at the top of the page.

  8. Under Storage account, select Create new and enter "powershellDATE" in the box provided.

  9. Under File share, select Create new and enter "powershellDATE" in the box provided.

  10. Click Create storage.

  11. Click the transfer files icon in the Cloud Shell title bar and select Upload.

  12. Select the unzipped vhd file you downloaded from GitHub. This file should have been downloaded as part of the introduction.

  13. Navigate to the directory where the file was uploaded:

    cd homeUSERNAME
  14. Verify the presence of the file:

    ls -la

Add the VHD to Blob Storage Using Cloud Shell

  1. In the Azure Portal, click the blob link at the top.

  2. Click the ellipsis at the end of the vhd row to pull up the context menu and select Container properties.

  3. Copy the URL and save it for later.

  4. Click Resource groups in the left-hand menu.

  5. Click on the provided resource group.

  6. Copy the resource group name at the top of the page and save it for later.

  7. Return to the Cloud Shell window and enter the command.

    add-azurermvhd -ResourceGroupName RESOURCE_GROUP_NAME -destination "CONTAINER_URL/file-1.vhd" -LocalFilePath file1.vhd
  8. In the Azure Port, click Storage accounts from the left-hand menu.

  9. Click the storage account where you sent the file.

  10. Under Blob service, click Blobs.

  11. Click vdh and verify the existence of the file.

Attempt to Set Up the Virtual Machine

  1. Close Cloud Shell.

  2. In the Azure Portal, click Virtual machines from the left-hand menu.

  3. Click lab-VM.

  4. Under Settings, click Disks.

  5. Click + Add data disk.

  6. From the pull-down menu, select Create disk.

  7. In the Name field, enter additionaldatadisk.

  8. Under Source type, select Storage blob.

  9. Click Browse.

  10. Navigate to the vhd file and select it.

  11. Under Size (GB), enter 1.

  12. Click Create.

  13. After getting the error message, close and discard the changes.

  14. Click X Discard at the top.

Upload the VHD File Using the Azure Portal

  1. Click the storage account where you sent the file.

  2. Under Blob service, click Blobs.

  3. Click vhd.

  4. Select the file and click Delete at the top.

  5. Select the Also delete blob snapshots box and click OK.

  6. Click Upload at the top.

  7. Under Files, click the folder button and select the file1.vhd file.

  8. Click Open.

  9. Click Advanced to open the accordion.

  10. Under Blob type, select Page blob.

  11. Click Upload.

Attempt to Set Up the Virtual Machine

  1. Click Virtual machines from the left-hand menu.

  2. Click lab-VM.

  3. Under Settings, click Disks.

  4. Click + Add data disk.

  5. From the pull-down menu, select Create disk.

  6. In the Name field, enter "additionaldatadisk".

  7. Under Source type, select Storage blob.

  8. Under Source blob, paste the complete path for the vhd file: "CONTAINER_URL/file1.vhd"

  9. Under Size (GB), enter "1".

  10. Click Create.

  11. Click Save.

  12. Switch over the virtual machine and open File Explorer.

  13. Verify the existence of the new drive with content.

Conclusion

Congratulations — you've completed this hands-on lab!