Add a data disk
In this task you'll add a data disk to a VM.
Every VM has an operating system disk. For your own files, databases or logs, add a data disk: a separate managed disk you can resize, back up, or move to another VM.
A new data disk arrives empty and unformatted. Azure attaches it, and then you prepare it inside the operating system.
Example. Larkfield Group keeps its reporting database on a separate data disk, so it can rebuild the VM from a fresh image without touching the data.
Before you start
You need: Virtual Machine Contributor or Contributor. Time: 10 minutes.
Where to look
- Virtual machines
- vm-practice
- Disks
- + Create and attach a new disk
Steps
- Open vm-practice and select Disks in the left menu.
- Under Data disks, select + Create and attach a new disk.On a narrower screen it hides under the ... menu above the data disks list.
- Name it vm-practice-data1, choose Premium SSD and a size of 64 GiB.On a free account, free services include a limited number of 64 GiB Premium SSD disks for 12 months.
- Select Apply (or Save) at the top of the page and wait for the notification.
- Connect with SSH and run lsblk. The new disk appears without partitions, as sdb or sdc depending on the VM size.Formatting and mounting it is a Linux job: partition it, create a file system, then add it to /etc/fstab.
- To detach it, go back to Disks, select the detach icon next to the data disk and Save.A detached disk still exists, and still costs money, until you delete it.
Commands
# Create and attach a new 64 GiB Premium SSD data disk
az vm disk attach --resource-group rg-portal-practice --vm-name vm-practice \
--name vm-practice-data1 --new --size-gb 64 --sku Premium_LRS
# Detach it, then delete it
az vm disk detach --resource-group rg-portal-practice --vm-name vm-practice --name vm-practice-data1
az disk delete --resource-group rg-portal-practice --name vm-practice-data1 --yes
Watch out for
- Cost
- Disks are billed for their full size whether they're full or empty, and whether the VM is running or not. Detaching doesn't stop the charge; deleting does.
- Security
- Managed disks are encrypted at rest by default. Anyone with access to the disk resource can copy or download it, so give access carefully.
- Common mistakes
- Choosing a big size 'just in case': you pay for every GiB. Forgetting about detached disks, which keep costing money. Expecting the disk to be ready to use without formatting it.
Clean up
- Resource groups
- rg-portal-practice
- Delete resource group
You've finished the VM section: delete the whole resource group. It removes the VM and every disk, including detached ones, as long as they're in that group.
Words to know
- Managed disk
- A disk that Azure stores and looks after for you, billed by size and type.
- Premium SSD, Standard SSD, Standard HDD
- Disk types from fastest and dearest to slowest and cheapest.
- LUN
- The slot number a data disk is attached to on the VM.
Tick off each step and track your progress in the guide.
Open this task in Azure Portal, Hands On