DEV Community

Cover image for Guide to adding storage disks to Linux Virtual Machine on Azure.
Barbra Mududa
Barbra Mududa

Posted on

Guide to adding storage disks to Linux Virtual Machine on Azure.

Are you new to Linux virtual machines on Azure? Need more storage or flexibility? This step-by-step guide will show you how to create, connect, and format a data disk for your Linux VM in Azure.

Create a Linux VM:

Navigate to the Virtual Machines section of the Azure interface and build a new VM. Choose a Linux distribution, such as Ubuntu or Windows, and the suitable VM size for your needs. To create the VM, simply follow the steps.

Once the VM has been developed, you must connect to it. To connect to the VM, use the SSH client of your choice.

Create a data disk

Consider adding a data drive to your Linux virtual machine (VM) if you're utilizing Azure. You can store data on a data disk, which is a different virtual hard drive, store data, install applications, or run scripts on it. Here is a step-by-step tutorial on creating a disk:

Step 1: Creating a data disk

  1. - Log in to your account using the Azure portal (portal.azure.com).
  2. - Click on "Disks" in the "Storage" section of the left-hand menu.
  3. - To create a new disk, click the "+ Add" button.
  4. - Click the "Create" button to create the new data disk

Image description

Step 2: Attach the data disk to your VM

  1. - Select the Linux VM you want to attach the data disk to.
  2. - Under the "Settings" menu, select the "Disks" option.
  3. - To add a new data disk, click the "+ Add data disk" button.
  4. - From the drop-down option, choose the data drive you created in Step 1.
  5. - Click "OK" to attach the data disk after making the necessary selections, such as the cache type and size.

Step 3: Format and mount the data disk

Log in to your Linux VM using SSH

  • Click on the VM you want to connect to
  • Go to the "Connect" tab
  • Locate the SSH command to connect to your VM
  • Store the connection command and SSH key in the same folder, such as your Home or Desktop
  • This will ensure easy access and connection to your Linux virtual machine using the SSH command.

To identify the new data drive, use the "lsblk" command to list the available block devices. It will most likely be named "/dev/sdc".

lsblk -o NAME,HCTL,SIZE,MOUNTPOINT | grep -i "sd"
Enter fullscreen mode Exit fullscreen mode

To create a new partition on the data disk, use the "fdisk" command. For a simple partition, you can utilize the default settings.

To format the new partition, use the "mkfs" command. For example, if you created a new partition at "/dev/sdc1", you can format it as an ext4 file system using the command "sudo mkfs -t ext4 /dev/sdc1".

sudo parted /dev/sdc --script mklabel gpt mkpart xfspart xfs 0% 100%
sudo mkfs.xfs /dev/sdc1
sudo partprobe /dev/sdc1
Enter fullscreen mode Exit fullscreen mode

Make a mount point for the new hard drive. For example, you can use the following command to create a directory called "/mnt/data":

sudo mkdir /mnt/data.

Enter fullscreen mode Exit fullscreen mode

Mount the new data disk to the mount point. For example, if you formatted the new partition at "/dev/sdc1" and created a mount point at "/mnt/data", you can mount the data disk with the following command:

sudo mount /dev/sdc1 /mnt/data

Enter fullscreen mode Exit fullscreen mode

After you have successfully mounted the new data disk to your Linux virtual machine, you can verify that it has been mounted correctly using the "df -h" command.

Image description

Conclusion

Attaching a data disk to your Azure Linux VM is a simple step that can provide more storage and flexibility. You may quickly build a new data disk, attach it to your VM, format it, and mount it for usage by following the instructions indicated in this blog post.

Top comments (0)