You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# 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.
12
12
---
@@ -15,11 +15,11 @@ ms.author: rogarana
15
15
16
16
**Applies to:**:heavy_check_mark: Linux VMs :heavy_check_mark: Flexible scale sets
17
17
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.
19
19
20
20
## Attach a new disk to a VM
21
21
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:
23
23
24
24
```azurecli
25
25
az vm disk attach \
@@ -32,7 +32,7 @@ az vm disk attach \
32
32
33
33
### Lower latency
34
34
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 highscale 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.
@@ -46,164 +46,110 @@ diskId=$(az disk show -g myResourceGroup -n myDataDisk --query 'id' -o tsv)
46
46
az vm disk attach -g myResourceGroup --vm-name myVM --name $diskId
47
47
```
48
48
49
-
## Format and mount the disk
49
+
## Identifying disks
50
50
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
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
-
```
64
55
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).
66
57
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
76
59
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:
78
61
79
62
```bash
80
-
ls -l /dev/disk/azure/scsi1
81
-
```
82
-
83
-
The output should be similar to the following example:
> Before identifying specific disks, determine whether your VM uses SCSI, NVMe, or a combination of both interfaces.
89
68
90
-
### Format the disk
69
+
### [Azure-VM-Utils](#tab/azure-vm-utils)
91
70
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.
93
72
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:
97
74
75
+
```bash
76
+
# List all disks
77
+
sudo azure-disk-list
98
78
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.
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)
108
91
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.
109
93
110
-
###Mount the disk
94
+
#### SCSI disks
111
95
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:
113
97
114
98
```bash
115
-
sudo mkdir /datadrive
99
+
lsblk -o NAME,HCTL,SIZE,MOUNTPOINT | grep -i "sd"
116
100
```
117
101
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
122
111
```
123
112
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.
125
114
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:
127
116
128
117
```bash
129
-
sudo blkid
118
+
ls -l /dev/disk/azure/scsi1
130
119
```
131
120
132
-
The output looks similar to the following example:
> 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:
> 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:
- 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:
185
135
```
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
192
142
```
193
143
194
-
# [SLES](#tab/suse)
144
+
For more detailed information about NVMe devices, use the `nvme` command:
* 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