- Lab
- A Cloud Guru
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.
Path Info
Table of Contents
-
Challenge
Create the Managed Disk.
-
Log in to the Azure Portal.
-
Click + Add and add search for/select Managed Disks. Select Create.
-
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
, selectStandard SSD
. Select512 GiB
.
- Review and create the disk. After a short time, your disk will be created.
-
-
Challenge
Attach the Disk to the VM.
-
Return to the resource group main page by clicking Home, then the resource group.
-
Click the Virtual machine resource called lab-VM.
-
Select Disks from the menu.
-
Click + Add data disk.
-
Click the Name dropdown and select
inventory-processing-output
. -
Click Save.
After a few moments, the disk will be attached to the VM.
-
-
Challenge
Mount the Disk to the VM file system.
-
Log in to the VM in a terminal.
-
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
.- Format the new disk:
sudo fdisk /dev/sdc
- 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.
- 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
- Create the output directory:
sudo mkdir /output
- Get the Disk's UUID. Copy the UUID value from the output:
sudo -i blkid | grep sdc1
- Add the new disk to
fstab
so that it will be automatically mounted whenever the VM restarts:
sudo vi /etc/fstab
- Add a new line to the file. Be sure to replace
<your disk UUID>
with the Disk UUID that was printed by theblkid
command earlier:
UUID=<your disk UUID> /output ext4 defaults,nofail 1 2
- Mount the new Disk immediately by reloading
fstab
:
sudo mount -a
- Write some data to the disk to verify that it is working:
echo "Hello, world!" | sudo tee -a /output/test.txt
- Read the data back from the disk:
cat /output/test.txt
-
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.