Attaching an Azure Managed Disk to a Linux VM

30 minutes
  • 3 Learning Objectives

About this Hands-on Lab

Azure Managed Disks provide a way to manage disk-based data storage and access the data in your VMs. Azure Disks provide the main operating system storage for virtual machines, but additional disks can be attached to VMs to provide storage as well. This allows you to use storage that is optimized for the needs of different parts of your infrastructure. In this lab, you will be able to work with Azure Data Disks hands-on. You will create a disk, attach it to a Linux VM, and mount it from within the VM so that it is ready for use.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create the Managed Disk.
  1. Log in to the Azure Portal.

  2. Click + Add and add search for/select Managed Disks. Select Create.

  3. Configure the Disk:

    • Ensure that Resource Group is set to your resource group (not empty).
    • Enter inventory-processing-output for the Disk name.
    • Select West US for the Region.
    • Click Change size. For Account type, select Standard SSD. Select 512 GiB.
  4. Review and create the disk. After a short time, your disk will be created.

Attach the Disk to the VM.
  1. Return to the resource group main page by clicking Home, then the resource group.

  2. Click the Virtual machine resource called lab-VM.

  3. Select Disks from the menu.

  4. Click + Add data disk.

  5. Click the Name dropdown and select inventory-processing-output.

  6. Click Save.

After a few moments, the disk will be attached to the VM.

Mount the Disk to the VM file system.
  1. Log in to the VM in a terminal.

  2. Verify that the disk has been attached to the VM.

dmesg | grep SCSI

You should see a line that reads:

[sdc] Attached SCSI disk

This means the managed disk is called sdc.

  1. Format the new disk:
sudo fdisk /dev/sdc
  1. Respond to the prompts like so:
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-1073741823, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-1073741823, default 1073741823):

Created a new partition 1 of type 'Linux' and of size 512 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
  1. Create a file system on the new partition. Note that it will take a few moments to finish building the file system:
sudo mkfs -t ext4 /dev/sdc1
  1. Create the output directory:
sudo mkdir /output
  1. Get the Disk’s UUID. Copy the UUID value from the output:
sudo -i blkid | grep sdc1
  1. Add the new disk to fstab so that it will be automatically mounted whenever the VM restarts:
sudo vi /etc/fstab
  1. Add a new line to the file. Be sure to replace <your disk UUID> with the Disk UUID that was printed by the blkid command earlier:
UUID=<your disk UUID>   /output   ext4   defaults,nofail   1   2
  1. Mount the new Disk immediately by reloading fstab:
sudo mount -a
  1. Write some data to the disk to verify that it is working:
echo "Hello, world!" | sudo tee -a /output/test.txt
  1. Read the data back from the disk:
cat /output/test.txt

Additional Resources

Your company, Store All the Things!, has a virtual machine running some software that generates a lot of data. While the virtual machine itself is fairly disposable and can be easily replaced, the output data has some additional performance and reliability requirements.

Your engineers want to be able to manage this important data separately from the main OS disk used by the VM, so you have been asked to create and mount an additional data disk to the VM where the software can write the output data. Create the disk, attach it to the VM, and mount it to the file system within the VM.

Additional details:

  • The virtual machine is called lab-VM
  • The VM is located in the West US region. The Disk will need to be located in that region as well
  • The Disk should be named inventory-processing-output
  • The Disk should be a 512 GiB Standard SSD
  • Mount the Disk to the VM filesystem at the location /output

If you get stuck, feel free to check out the solution video, or the detailed instructions under each objective. Good luck!

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!