Introduction
Virtual Machines (VMs) in Azure provide flexible computing resources, but sometimes the default storage isn't enough for your needs. Whether you're storing application data, logs, or databases, adding a data disk allows you to expand storage capacity while keeping your OS disk separate. This improves performance, security, and manageability.
In this guide, we will focus on attaching a data disk to an Azure VM using the Azure Portal. By the end of this exercise, you will have a new data disk added to your VM and ready for use.
What is a Data Disk in Relation to a VM?
A data disk in Azure is an additional storage disk that you can attach to a VM. Unlike the OS disk, which contains the operating system and system files, a data disk is used for:
- Storing application data such as databases, logs, or media files.
- Separating critical data from the OS disk for better security and performance.
Expanding storage capacity without modifying the existing VM configuration.
Data disks are persistent, meaning they retain data even if the VM is restarted or deallocated. They can also be detached and reattached to other VMs as needed.Requirements to Perform This Exercise
Before you begin, make sure you have the following:An Active Azure Subscription – You must have access to the Azure Portal.
Proper Permissions – You need Contributor or Owner access to create and manage resources.
Available Storage Quota – Ensure your subscription allows the creation of VMs and additional disks.
With these in place, let’s start by creating a Linux Virtual Machine in Azure and then attach a data disk to expand its storage.
Creating the VM
- Log into the Azure portal and search for Virtual Machines
Select or create resource group
Select an appropriate Region
Select appropriate availability zone options as needed
Select a VM size, we are using Standard_B1s for this example
Click create. Download the ssh key to your machine by following the prompt
Attaching data disk
Formatting the disk:
In the Azure portal, navigate to your newly created VM. Copy and note the Public IP address.
Open terminal and navigate to where you downloaded the ssh key for the VM. Enter:
ssh -i /path/to/private-key.pem <username>@<VM_Public_IP>
If this does not work, enter
chmod 600 </path/to/private-key.pem>
Then try the former command again
- Example:
Run the following command to identify the newly attached disk:
lsblk
You should see a new disk (e.g., /dev/sdb) that is not yet mounted.
Use fdisk to create a partition:
sudo fdisk /dev/sdb1
Press n (new partition) → p (primary partition) → Enter (default values) → Enter (default values) → w (write changes).
- Format the partition. Ex:
sudo mkfs.ext4 /dev/sdb1
- Create a Mount Directory:
sudo mkdir /mnt/datadisk
- Mount the Disk:
sudo mount /dev/sdb1 /mnt/datadisk
- Make the Mount Permanent (Optional): To ensure the disk mounts automatically on reboot, add it to /etc/fstab:
echo "/dev/sdb1 /mnt/datadisk ext4 defaults,nofail 0 2" | sudo tee -a /etc/fstab
- Your data disk is now attached, formatted, and ready to use!
Top comments (0)