Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Azure icon
Labs

Attaching an Azure Managed Disk to a Linux VM

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.

Azure icon
Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 30m
Published
Clock icon Feb 14, 2020

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    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.
    1. Review and create the disk. After a short time, your disk will be created.
  2. Challenge

    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.

  3. Challenge

    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
    

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

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.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans