How to add a data disk to your Azure Linux VM the right way

In this blogpost I shall describe how you add an extra data disk to your Linux VM running on Azure.

Step 1 Add a new disk to your Linux VM using the Azure Portal

2019-06-08 07_55_11-Microsoft Edge.png

Choose Add data disk to add an extra data disk and choose create data disk.

2019-06-08 07_57_12-Microsoft Edge.png

For demo purposes I quickly entered a default 20 GiB HD, nothing fancy 🙂

Don’t forget to save your changes!

2019-06-08 07_58_27-Microsoft Edge.png

Step 2 Connect to your VM using SSH or use the Serial console on your VM Pane in the Azure Portal

2019-06-08 07_53_04-Microsoft Edge.png

Use the following command to find all your data drives :

dmesg | grep SCSI

You see all your drives and the newly created drive

2019-06-08 08_00_53-Microsoft Edge.png

Here, sdc is the newly added disk. Let’s continue.

Now we have to partition the added disk using the following command :

sudo fdisk /dev/sdc

Use the n command to add a new partition. In this example, we also choose p for a primary partition and accept the rest of the default values. The output will be similar to the following example:

2019-06-08 08_04_33-Microsoft Edge.png

Now we are going to write a partition (format) the newly added disk using the following command :

sudo mkfs -t ext4 /dev/sdc1

2019-06-08 08_06_03-Microsoft Edge.png

Now we are going to mount the formatted drive using the following commands :

sudo mkdir /MyDataDrive
sudo mount /dev/sdc1 /MyDataDrive

2019-06-08 08_07_45-Microsoft Edge.png

You see your newly created disk :

2019-06-08 08_08_55-Microsoft Edge.png

To ensure that the drive is remounted automatically after a reboot, it must be added to the /etc/fstab file. Herefore I’m going to use the blkid utility:

sudo blkid

2019-06-08 08_10_11-VMLIN01 - Serial console - Microsoft Azure ‎- Microsoft Edge.png

Now copy the UUID :

2019-06-08 08_11_15-VMLIN01 - Serial console - Microsoft Azure ‎- Microsoft Edge.png

Now we are going to add the UUID to the /etc/fstab. You can use VI or (like I prefer to use) nano.

sudo nano /etc/fstab

The format is als follows :

UUID=<YourUUID> /<YourMountPoint> ext4 defaults,nofail 1 2

In my case it looks as follows :

2019-06-08 08_13_41-Microsoft Edge.png

Ok, let’s reboot the VM and check if the drive still exists..

sudo reboot

2019-06-08 08_15_22-Microsoft Edge.png

Use the following command to check

df -h

As you can see the /MyDataDrive is still available after reboot.

4 Comments

  1. Please Note: At the following step in above step-by-step procedure there is one correction-

    To ensure that the drive is remounted automatically after a reboot, it must be added to the /etc/fstab file. Herefore I’m going to use the blkid utility:

    sudo blikid

    The above command is: sudo blkid [and not sudo blikid]

    Hope that saved some time for newbies troubleshooting the issue command not found while copy and pasting the command 😉

    1. Author

      Thank you very much! I’ve updated the post.

  2. What does 1 2 mean at the end of the line in the /etc/fstab ??
    I want to add more disks

    1. Author

      The 1 is for error correction and the 2 for back-up purposes!

Leave a Reply to XanderCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.