Skip to content

Commit 3359f98

Browse files
Merge pull request #2295 from MicrosoftDocs/main
Auto Publish – main to live - 2025-09-18 22:00 UTC
2 parents afa61b1 + 7acd731 commit 3359f98

File tree

5 files changed

+566
-117
lines changed

5 files changed

+566
-117
lines changed

articles/virtual-machines/TOC.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,14 @@
18251825
href: ./windows/attach-managed-disk-portal.yml
18261826
- name: Change temp disk drive letter
18271827
href: ./windows/change-drive-letter.md
1828+
- name: Format and mount a disk
1829+
items:
1830+
- name: Linux
1831+
items:
1832+
- name: Managed disks
1833+
href: ./linux/disks-format-mount-data-disks-linux.md
1834+
- name: Temporary disks
1835+
href: ./linux/disks-format-mount-temp-disks-linux.md
18281836
- name: Detach a disk
18291837
items:
18301838
- name: Linux
@@ -1862,6 +1870,8 @@
18621870
href: ./linux/azure-to-guest-disk-mapping.md
18631871
- name: Map managed disk to guest disk - Windows
18641872
href: ./windows/azure-to-guest-disk-mapping.md
1873+
- name: Azure VM utilities - Linux
1874+
href: ./linux/azure-virtual-machine-utilities.md
18651875
- name: File storage
18661876
items:
18671877
- name: Copy files to a VM

articles/virtual-machines/linux/add-disk.md

Lines changed: 63 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ms.service: azure-disk-storage
66
ms.custom: devx-track-azurecli, linux-related-content
77
ms.collection: linux
88
ms.topic: how-to
9-
ms.date: 12/09/2024
9+
ms.date: 09/03/2025
1010
ms.author: rogarana
1111
# Customer intent: As a system administrator managing Linux VMs, I want to attach and configure a persistent data disk using the command line, so that I can ensure data retention and improve performance for my applications.
1212
---
@@ -15,11 +15,11 @@ ms.author: rogarana
1515

1616
**Applies to:** :heavy_check_mark: Linux VMs :heavy_check_mark: Flexible scale sets
1717

18-
This article shows you how to attach a persistent disk to your VM so that you can preserve your data - even if your VM is reprovisioned due to maintenance or resizing.
18+
This article shows you how to attach a persistent disk to your virtual machine (VM) to preserve your data, even if your VM is reprovisioned due to maintenance or resizing.
1919

2020
## Attach a new disk to a VM
2121

22-
If you want to add a new, empty data disk on your VM, use the [az vm disk attach](/cli/azure/vm/disk) command with the `--new` parameter. If your VM is in an Availability Zone, the disk is automatically created in the same zone as the VM. For more information, see [Overview of Availability Zones](/azure/reliability/availability-zones-overview). The following example creates a disk named *myDataDisk* that is 50 Gb in size:
22+
If you want to add a new, empty data disk to your VM, use the [az vm disk attach](/cli/azure/vm/disk) command with the `--new` parameter. If your VM is in an Availability Zone, the disk is automatically created in the same zone as the VM. For more information, see [Overview of Availability Zones](/azure/reliability/availability-zones-overview). The following example creates a disk named *myDataDisk* that is 50 GB in size:
2323

2424
```azurecli
2525
az vm disk attach \
@@ -32,7 +32,7 @@ az vm disk attach \
3232

3333
### Lower latency
3434

35-
In select regions, the disk attach latency has been reduced, so you'll see an improvement of up to 15%. This is useful if you have planned/unplanned failovers between VMs, you're scaling your workload, or are running a high scale stateful workload such as Azure Kubernetes Service. However, this improvement is limited to the explicit disk attach command, `az vm disk attach`. You won't see the performance improvement if you call a command that may implicitly perform an attach, like `az vm update`. You don't need to take any action other than calling the explicit attach command to see this improvement.
35+
In select regions, disk attach latency is reduced. In those regions, there's an improvement of up to 15%. This improvement is useful if you have planned or unplanned failovers between VMs, you're scaling your workload, or you're running a high-scale stateful workload such as Azure Kubernetes Service. However, this improvement is limited to the explicit disk attach command, `az vm disk attach`. You won't see the performance improvement if you call a command that might implicitly perform an attach, like `az vm update`. You don't need to take any action other than calling the explicit attach command to see this improvement.
3636

3737
[!INCLUDE [virtual-machines-disks-fast-attach-detach-regions](../includes/virtual-machines-disks-fast-attach-detach-regions.md)]
3838

@@ -46,164 +46,110 @@ diskId=$(az disk show -g myResourceGroup -n myDataDisk --query 'id' -o tsv)
4646
az vm disk attach -g myResourceGroup --vm-name myVM --name $diskId
4747
```
4848

49-
## Format and mount the disk
49+
## Identifying disks
5050

51-
To partition, format, and mount your new disk so your Linux VM can use it, SSH into your VM. For more information, see [How to use SSH with Linux on Azure](mac-create-ssh-keys.md). The following example connects to a VM with the public IP address of *10.123.123.25* with the username *azureuser*:
51+
Azure Linux VMs use different disk interfaces depending on the VM size and generation:
52+
- VM sizes v6 and newer: Use NVMe interface for improved performance
53+
- VM sizes v5 and older: Use SCSI interface for disk management
5254

53-
```bash
54-
55-
```
56-
57-
### Find the disk
58-
59-
Once you connect to your VM, find the disk. In this example, we're using `lsblk` to list the disks.
60-
61-
```bash
62-
lsblk -o NAME,HCTL,SIZE,MOUNTPOINT | grep -i "sd"
63-
```
6455

65-
The output is similar to the following example:
56+
For details about SCSI vs NVMe differences, see [SCSI to NVMe conversion](/azure/virtual-machines/nvme-linux#scsi-vs-nvme).
6657

67-
```output
68-
sda 0:0:0:0 30G
69-
├─sda1 29.9G /
70-
├─sda14 4M
71-
└─sda15 106M /boot/efi
72-
sdb 1:0:1:0 14G
73-
└─sdb1 14G /mnt
74-
sdc 3:0:0:0 50G
75-
```
58+
### Connect to the virtual machine
7659

77-
Here, `sdc` is the disk that we want, because it's 50G. If you add multiple disks, and aren't sure which disk it's based on size alone, you can go to the VM page in the portal, select **Disks**, and check the LUN number for the disk under **Data disks**. Compare the LUN number from the portal to the last number of the **HTCL** portion of the output, which is the LUN. Another option is to list the contents of the `/dev/disk/azure/scsi1` directory:
60+
To identify disks associated with your Linux VM, connect to the VM by using SSH. For details, see [How to use SSH with Linux on Azure](/azure/virtual-machines/linux/mac-create-ssh-keys). The following example connects to a VM with the public IP address of 10.123.123.25 with the username azureuser:
7861

7962
```bash
80-
ls -l /dev/disk/azure/scsi1
81-
```
82-
83-
The output should be similar to the following example:
84-
85-
```output
86-
lrwxrwxrwx 1 root root 12 Mar 28 19:41 lun0 -> ../../../sdc
63+
8764
```
8865

66+
> [!NOTE]
67+
> Before identifying specific disks, determine whether your VM uses SCSI, NVMe, or a combination of both interfaces.
8968
90-
### Format the disk
69+
### [Azure-VM-Utils](#tab/azure-vm-utils)
9170

92-
Format the disk with `parted`, if the disk size is two tebibytes (TiB) or larger then you must use GPT partitioning, if it is under 2TiB, then you can use either MBR or GPT partitioning.
71+
The [azure-vm-utils](azure-virtual-machine-utilities.md) package provides utilities to optimize the Linux experience on Azure VMs, making disk identification more reliable across different VM configurations.
9372

94-
> [!NOTE]
95-
> It is recommended that you use the latest version `parted` that is available for your distro.
96-
> If the disk size is 2 tebibytes (TiB) or larger, you must use GPT partitioning. If disk size is under 2 TiB, then you can use either MBR or GPT partitioning.
73+
Use the following commands to list disks on the VM:
9774

75+
```bash
76+
# List all disks
77+
sudo azure-disk-list
9878

99-
The following example uses `parted` on `/dev/sdc`, which is where the first data disk will typically be on most VMs. Replace `sdc` with the correct option for your disk. We're also formatting it using the [XFS](https://xfs.wiki.kernel.org/) filesystem.
79+
# List NVMe disks with detailed information
80+
sudo azure-nvme-id
81+
```
10082

101-
```bash
102-
sudo parted /dev/sdc --script mklabel gpt mkpart xfspart xfs 0% 100%
103-
sudo partprobe /dev/sdc
104-
sudo mkfs.xfs /dev/sdc1
83+
The output from `azure-nvme-id` is similar to:
84+
```
85+
/dev/nvme0n1: type=os
86+
/dev/nvme0n2: type=data, lun=0
87+
/dev/nvme1n1: type=local, index=1, name=nvme-50G-1
10588
```
10689

107-
Use the [`partprobe`](https://linux.die.net/man/8/partprobe) utility to make sure the kernel is aware of the new partition and filesystem. Failure to use `partprobe` can cause the blkid or lsblk commands to not return the UUID for the new filesystem immediately.
90+
### [lsblk](#tab/lsblk)
10891

92+
The `lsblk` command is a standard Linux utility that can identify both SCSI and NVMe disks. The command options differ slightly based on the disk controller type.
10993

110-
### Mount the disk
94+
#### SCSI disks
11195

112-
Now, create a directory to mount the file system using `mkdir`. The following example creates a directory at `/datadrive`:
96+
For VMs with SCSI controllers, use the following command:
11397

11498
```bash
115-
sudo mkdir /datadrive
99+
lsblk -o NAME,HCTL,SIZE,MOUNTPOINT | grep -i "sd"
116100
```
117101

118-
Use `mount` to then mount the filesystem. The following example mounts the `/dev/sdc1` partition to the `/datadrive` mount point:
119-
120-
```bash
121-
sudo mount /dev/sdc1 /datadrive
102+
The output is similar to:
103+
```
104+
sda 0:0:0:0 30G
105+
├─sda1 29.9G /
106+
├─sda14 4M
107+
└─sda15 106M /boot/efi
108+
sdb 1:0:1:0 14G
109+
└─sdb1 14G /mnt
110+
sdc 3:0:0:0 50G
122111
```
123112

124-
### Persist the mount
113+
Here, `sdc` is the data disk we added. The last number in the HCTL field (for example, 3:0:0:**0**) is the LUN number that corresponds to what you see in the Azure portal.
125114

126-
To ensure that the drive is remounted automatically after a reboot, it must be added to the `/etc/fstab` file. It's also highly recommended that the UUID (Universally Unique Identifier) is used in `/etc/fstab` to refer to the drive rather than just the device name (such as, */dev/sdc1*). If the OS detects a disk error during boot, using the UUID avoids the incorrect disk being mounted to a given location. Remaining data disks would then be assigned those same device IDs. To find the UUID of the new drive, use the `blkid` utility:
115+
You can also check the Azure disk symlinks:
127116

128117
```bash
129-
sudo blkid
118+
ls -l /dev/disk/azure/scsi1
130119
```
131120

132-
The output looks similar to the following example:
133-
134-
```output
135-
/dev/sda1: LABEL="cloudimg-rootfs" UUID="11111111-1b1b-1c1c-1d1d-1e1e1e1e1e1e" TYPE="ext4" PARTUUID="1a1b1c1d-11aa-1234-1a1a1a1a1a1a"
136-
/dev/sda15: LABEL="UEFI" UUID="BCD7-96A6" TYPE="vfat" PARTUUID="1e1g1cg1h-11aa-1234-1u1u1a1a1u1u"
137-
/dev/sdb1: UUID="22222222-2b2b-2c2c-2d2d-2e2e2e2e2e2e" TYPE="ext4" TYPE="ext4" PARTUUID="1a2b3c4d-01"
138-
/dev/sda14: PARTUUID="2e2g2cg2h-11aa-1234-1u1u1a1a1u1u"
139-
/dev/sdc1: UUID="33333333-3b3b-3c3c-3d3d-3e3e3e3e3e3e" TYPE="xfs" PARTLABEL="xfspart" PARTUUID="c1c2c3c4-1234-cdef-asdf3456ghjk"
121+
Output:
140122
```
141-
142-
> [!NOTE]
143-
> Improperly editing the `/etc/fstab` file could result in an unbootable system. If unsure, refer to the distribution's documentation for information on how to properly edit this file. It is also recommended that a backup of the `/etc/fstab` file is created before editing.
144-
145-
Next, open the `/etc/fstab` file in a text editor. Add a line to the end of the file, using the UUID value for the `/dev/sdc1` device that was created in the previous steps, and the mountpoint of `/datadrive`. Using the example from this article, the new line would look like the following:
146-
147-
```output
148-
UUID=33333333-3b3b-3c3c-3d3d-3e3e3e3e3e3e /datadrive xfs defaults,nofail 1 2
123+
lrwxrwxrwx 1 root root 12 Mar 28 19:41 lun0 -> ../../../sdc
149124
```
150125

151-
When you're done editing the file, save and close the editor.
126+
#### NVMe disks
152127

153-
Alternatively, you can run the following command to add the disk to the `/etc/fstab` file:
128+
For VMs with NVMe controllers, use the following command:
154129

155130
```bash
156-
echo "UUID=33333333-3b3b-3c3c-3d3d-3e3e3e3e3e3e /datadrive xfs defaults,nofail 1 2" >> /etc/fstab
131+
lsblk -o NAME,TYPE,SIZE,MOUNTPOINT | grep nvme
157132
```
158133

159-
> [!NOTE]
160-
> Later removing a data disk without editing fstab could cause the VM to fail to boot. Most distributions provide either the *nofail* and/or *nobootwait* fstab options. These options allow a system to boot even if the disk fails to mount at boot time. Consult your distribution's documentation for more information on these parameters.
161-
>
162-
> The *nofail* option ensures that the VM starts even if the filesystem is corrupt or the disk does not exist at boot time. Without this option, you may encounter behavior as described in [Cannot SSH to Linux VM due to FSTAB errors](/troubleshoot/azure/virtual-machines/linux-virtual-machine-cannot-start-fstab-errors)
163-
>
164-
> The Azure VM Serial Console can be used for console access to your VM if modifying fstab has resulted in a boot failure. More details are available in the [Serial Console documentation](/troubleshoot/azure/virtual-machines/serial-console-linux).
165-
166-
### TRIM/UNMAP support for Linux in Azure
167-
168-
Some Linux kernels support TRIM/UNMAP operations to discard unused blocks on the disk. This feature is primarily useful to inform Azure that deleted pages are no longer valid and can be discarded. This feature can save money on disks that are billed based on the amount of consumed storage, such as unmanaged standard disks and disk snapshots.
169-
170-
There are two ways to enable TRIM support in your Linux VM. As usual, consult your distribution for the recommended approach:
171-
172-
- Use the `discard` mount option in `/etc/fstab`, for example:
173-
174-
```output
175-
UUID=33333333-3b3b-3c3c-3d3d-3e3e3e3e3e3e /datadrive xfs defaults,discard 1 2
176-
```
177-
178-
- In some cases, the `discard` option may have performance implications. Alternatively, you can run the `fstrim` command manually from the command line, or add it to your crontab to run regularly:
179-
180-
# [Ubuntu](#tab/ubuntu)
181-
182-
```bash
183-
sudo apt install util-linux
184-
sudo fstrim /datadrive
134+
The output is similar to:
185135
```
186-
187-
# [RHEL](#tab/rhel)
188-
189-
```bash
190-
sudo yum install util-linux
191-
sudo fstrim /datadrive
136+
nvme0n1 disk 30G
137+
├─nvme0n1p1 part 29.9G /
138+
├─nvme0n1p14 part 4M
139+
└─nvme0n1p15 part 106M /boot/efi
140+
nvme1n1 disk 50G
141+
nvme0n2 disk 50G
192142
```
193143

194-
# [SLES](#tab/suse)
144+
For more detailed information about NVMe devices, use the `nvme` command:
195145

196146
```bash
197-
sudo zypper in util-linux
198-
sudo fstrim /datadrive
147+
sudo nvme list
199148
```
200-
---
201-
202-
## Troubleshooting
203149

204-
[!INCLUDE [virtual-machines-linux-lunzero](../includes/virtual-machines-linux-lunzero.md)]
150+
---
205151

206-
## Next steps
152+
## Next Steps
207153

208-
* To ensure your Linux VM is configured correctly, review the [Optimize your Linux machine performance](/previous-versions/azure/virtual-machines/linux/optimization) recommendations.
209-
* Expand your storage capacity by adding more disks and [configure RAID](/previous-versions/azure/virtual-machines/linux/configure-raid) for extra performance.
154+
- Format and mount the disks based on your requirements and use case. Review instructions for formatting and mounting [managed disks](disks-format-mount-data-disks-linux.md) and [temporary disks](disks-format-mount-temp-disks-linux.md).
155+
- [Learn about Azure-VM-Utils](azure-virtual-machine-utilities.md).

0 commit comments

Comments
 (0)