Skip to content

Commit 4e9184e

Browse files
committed
Fix attach disk
1 parent 23a8800 commit 4e9184e

File tree

1 file changed

+6
-136
lines changed

1 file changed

+6
-136
lines changed

scenarios/AttachDataDiskLinuxVM/attach-data-disk-linux-vm.md

Lines changed: 6 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -132,82 +132,21 @@ az vm extension set \
132132
--name AADSSHLoginForLinux \
133133
--resource-group $MY_RESOURCE_GROUP_NAME \
134134
--vm-name $MY_VM_NAME -o JSON
135-
```
136-
137-
Results:
138-
139-
<!-- expected_similarity=0.3 -->
140-
```JSON
141-
{
142-
"autoUpgradeMinorVersion": true,
143-
"enableAutomaticUpgrade": null,
144-
"forceUpdateTag": null,
145-
"id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/LinuxRG-a36f5d/providers/Microsoft.Compute/virtualMachines/myVMa36f5d/extensions/AADSSHLoginForLinux",
146-
"instanceView": null,
147-
"location": "australiaeast",
148-
"name": "AADSSHLoginForLinux",
149-
"protectedSettings": null,
150-
"protectedSettingsFromKeyVault": null,
151-
"provisionAfterExtensions": null,
152-
"provisioningState": "Succeeded",
153-
"publisher": "Microsoft.Azure.ActiveDirectory",
154-
"resourceGroup": "LinuxRG-a36f5d",
155-
"settings": null,
156-
"suppressFailures": null,
157-
"tags": null,
158-
"type": "Microsoft.Compute/virtualMachines/extensions",
159-
"typeHandlerVersion": "1.0",
160-
"typePropertiesType": "AADSSHLoginForLinux"
161-
}
162-
```
163135

164-
In this scenario the LUN0 our first data disk is going to be formatted and mounted using the command below:
136+
# In this scenario the LUN0 our first data disk is going to be formatted and mounted using the command below:
165137

166-
```bash
167138
export FQDN="${MY_DNS_LABEL}.${REGION}.cloudapp.azure.com"
168139
ssh -o StrictHostKeyChecking=no $MY_VM_USERNAME@$FQDN -- "sudo parted -s -a optimal -- /dev/disk/azure/scsi1/lun0 mklabel gpt mkpart primary xfs 0% 100%"
169140
ssh -o StrictHostKeyChecking=no $MY_VM_USERNAME@$FQDN -- "sudo partprobe -s /dev/disk/azure/scsi1/lun0"
170141
ssh -o StrictHostKeyChecking=no $MY_VM_USERNAME@$FQDN -- "sudo mkfs.xfs /dev/disk/azure/scsi1/lun0-part1"
171142
ssh -o StrictHostKeyChecking=no $MY_VM_USERNAME@$FQDN -- "sudo mkdir -v /datadisk01"
172143
ssh -o StrictHostKeyChecking=no $MY_VM_USERNAME@$FQDN -- "sudo mount -v /dev/disk/azure/scsi1/lun0-part1 /datadisk01"
173-
```
174-
175-
Results:
176-
177-
<!-- expected_similarity=0.3 -->
178-
```text
179-
/dev/sdc: gpt partitions 1
180-
mke2fs 1.47.0 (5-Feb-2023)
181-
Discarding device blocks: done
182-
Creating filesystem with 33553920 4k blocks and 8388608 inodes
183-
Filesystem UUID: 1095e29c-07db-47ec-8b19-1ffcaf4f5628
184-
Superblock backups stored on blocks:
185-
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
186-
4096000, 7962624, 11239424, 20480000, 23887872
187-
188-
Allocating group tables: done
189-
Writing inode tables: done
190-
Creating journal (131072 blocks): done
191-
Writing superblocks and filesystem accounting information: done
192-
193-
mkdir: created directory '/datadisk01'
194-
mount: /dev/sdc1 mounted on /datadisk01.
195-
```
196-
197-
In oder to update the /etc/fstab file, you can use the following command, and mount the LUN1 using it's unique identifier (UUID) together with the discard mount option:
198144

199-
```bash
145+
# In oder to update the /etc/fstab file, you can use the following command, and mount the LUN1 using it's unique identifier (UUID) together with the discard mount option:
200146
ssh $MY_VM_USERNAME@$FQDN -- \
201147
'echo UUID=$(sudo blkid -s UUID -o value /dev/disk/azure/scsi1/lun0-part1) /datadisk01 xfs defaults,discard 0 0 | sudo tee -a /etc/fstab'
202148
```
203149

204-
Results:
205-
206-
<!-- expected_similarity=0.3 -->
207-
```text
208-
UUID=1095e29c-07db-47ec-8b19-1ffcaf4f5628 /datadisk01 xfs defaults,discard 0 0
209-
```
210-
211150
## Attach a new disk to a VM
212151

213152
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](../../availability-zones/az-overview.md). The following example creates a disk named *$LUN2_NAME* that is 50 Gb in size:
@@ -223,54 +162,21 @@ az vm disk attach \
223162
--caching None \
224163
--lun 1 \
225164
--size-gb 50
226-
```
227165

228-
In this second possible scenario the LUN1 is going to be our data disk, the following example shows how to format and mount the data disk.
166+
# In this second possible scenario the LUN1 is going to be our data disk, the following example shows how to format and mount the data disk.
229167

230-
```bash
231168
ssh -o StrictHostKeyChecking=no $MY_VM_USERNAME@$FQDN -- "sudo parted -s -a optimal -- /dev/disk/azure/scsi1/lun1 mklabel gpt mkpart primary xfs 0% 100%"
232169
ssh -o StrictHostKeyChecking=no $MY_VM_USERNAME@$FQDN -- "sudo partprobe -s /dev/disk/azure/scsi1/lun1"
233170
ssh -o StrictHostKeyChecking=no $MY_VM_USERNAME@$FQDN -- "sudo mkfs.xfs /dev/disk/azure/scsi1/lun1-part1"
234171
ssh -o StrictHostKeyChecking=no $MY_VM_USERNAME@$FQDN -- "sudo mkdir -v /datadisk02"
235172
ssh -o StrictHostKeyChecking=no $MY_VM_USERNAME@$FQDN -- "sudo mount -v /dev/disk/azure/scsi1/lun1-part1 /datadisk02"
236-
```
237-
238-
Results:
239-
240-
<!-- expected_similarity=0.3 -->
241-
```text
242-
/dev/sdd: gpt partitions 1
243-
mke2fs 1.47.0 (5-Feb-2023)
244-
Discarding device blocks: done
245-
Creating filesystem with 13106688 4k blocks and 3276800 inodes
246-
Filesystem UUID: 6e8ad233-5664-4f75-8ec6-3aa34f228868
247-
Superblock backups stored on blocks:
248-
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
249-
4096000, 7962624, 11239424
250-
251-
Allocating group tables: done
252-
Writing inode tables: done
253-
Creating journal (65536 blocks): done
254-
Writing superblocks and filesystem accounting information: done
255173

256-
mkdir: created directory '/datadisk02'
257-
mount: /dev/sdd1 mounted on /datadisk02.
258-
```
259-
260-
In oder to update the /etc/fstab file, you can use the following command, and mount the LUN1 using it's unique identifier (UUID) together with the discard mount option:
174+
# In oder to update the /etc/fstab file, you can use the following command, and mount the LUN1 using it's unique identifier (UUID) together with the discard mount option:
261175

262-
```bash
263176
ssh $MY_VM_USERNAME@$FQDN -- \
264177
'echo "UUID=$(sudo blkid -s UUID -o value /dev/disk/azure/scsi1/lun1-part1) /datadisk02 xfs defaults,discard 0 0" | sudo tee -a /etc/fstab'
265178
```
266179

267-
Results:
268-
269-
<!-- expected_similarity=0.3 -->
270-
```text
271-
UUID=0b1629d5-0cd5-41fd-9050-b2ed7e3f1028 /datadisk02 xfs defaults,discard 0 0
272-
```
273-
274180
## Attach an existing data disk to a VM
275181

276182
Lastly the third scenario is to attach an existing disk to a VM. You can use the [az vm disk attach](/cli/azure/vm/disk) command with the `--disk` parameter to attach an existing disk to a VM. The following example attaches an existing disk named *myDataDisk* to a VM named *myVM*:
@@ -290,43 +196,9 @@ az disk create \
290196
--zone $ZONE \
291197
--performance-plus false \
292198
--public-network-access Disabled -o JSON
293-
```
294199

295-
Results:
200+
# Then you can attach the disk to the VM:
296201

297-
<!-- expected_similarity=0.3 -->
298-
```JSON
299-
{
300-
"encryptionSettingsCollection": null,
301-
"extendedLocation": null,
302-
"hyperVGeneration": null,
303-
"id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/LinuxRG-e4c4b4/providers/Microsoft.Compute/disks/LUN2-e4c4b4",
304-
"lastOwnershipUpdateTime": null,
305-
"location": "australiaeast",
306-
"managedBy": null,
307-
"managedByExtended": null,
308-
"maxShares": 1,
309-
"name": "LUN2-e4c4b4",
310-
"networkAccessPolicy": "AllowAll",
311-
"optimizedForFrequentAttach": null,
312-
"osType": null,
313-
"propertyUpdatesInProgress": null,
314-
"provisioningState": "Succeeded",
315-
"publicNetworkAccess": "Disabled",
316-
"purchasePlan": null,
317-
"resourceGroup": "LinuxRG-e4c4b4",
318-
"securityProfile": null,
319-
"shareInfo": null,
320-
"sku": {
321-
"name": "PremiumV2_LRS",
322-
"tier": "Premium"
323-
}
324-
}
325-
```
326-
327-
Then you can attach the disk to the VM:
328-
329-
```bash
330202
LUN2_ID=$(az disk show --resource-group $MY_RESOURCE_GROUP_NAME --name $LUN2_NAME --query 'id' -o tsv)
331203

332204
az vm disk attach \
@@ -335,11 +207,9 @@ az vm disk attach \
335207
--disks $LUN2_ID \
336208
--sku PremiumV2_LRS \
337209
--lun 2
338-
```
339210

340-
In this third scenario the LUN2 is going to be our data disk, the following example shows how to format and mount the data disk.
211+
# In this third scenario the LUN2 is going to be our data disk, the following example shows how to format and mount the data disk.
341212

342-
```bash
343213
ssh -o StrictHostKeyChecking=no $MY_VM_USERNAME@$FQDN -- "sudo parted -s -a optimal -- /dev/disk/azure/scsi1/lun2 mklabel gpt mkpart primary xfs 0% 100%"
344214
ssh -o StrictHostKeyChecking=no $MY_VM_USERNAME@$FQDN -- "sudo partprobe -s /dev/disk/azure/scsi1/lun2"
345215
ssh -o StrictHostKeyChecking=no $MY_VM_USERNAME@$FQDN -- "sudo mkfs.xfs /dev/disk/azure/scsi1/lun2-part1"

0 commit comments

Comments
 (0)