<img alt="" src="https://secure.leadforensics.com/150446.png " style="display:none;">
Go to top icon

How to create, attach, and mount a disk to Linux VM (Microsoft Azure)

Sourabh Majali Oct 17, 2018

Microsoft Azure Startup Linux VM Virtual Machine

Virtual Machine helps you to not only run several of your applications but it also gives you the liberty to allocate the storage of your choice to store your data online securely. Although VM provides its own storage, many times you find a need for an extra storage as existing storage runs out of space. That is where additional an additional disk comes into picture. Fortunately, Microsoft has made it easy for us by introducing some easy features to attach the disk. Throughout this blog I will be elaborating the process of attaching an additional disk to your VM . The following steps show you how to attach a disk to Linux Virtual Machine through Azure Portal.

Prerequisite

  • Linux VM
  • Putty.exe
Step 1

  • Log in to Azure Portal
  • Select your Ubuntu VM
  • Go to Overview and click on 'DISK'
test-ubuntu
Step 2

  • Click "Disk"
  • Click "+ Add data disk"
  • Click "Create disk" ,if no managed disk is available

data-disks

  • Fill the details
  • Keep Source Type : None (empty disk)
  • After creating a disk, Click "Save" to make all the changes reflect
linux-vm
  • After "Save" , Now you have attached a disk to the mentioned VM.
Step 3

  • Connect to your VM using "Putty.exe"
  • If it does not connect , check "Port 22" is present in
    Azure Portal ->Networking-> Inbound rules.
  • If it does not contain port 22 you can add it from,
    "Networking -> Add Inbound Rule - > Add Rule for Port 22"
add-inbound-security-roleStep 4

  • Now we can connect to our VM & we are ready to attach
  • Use "sudo su" command to operate as root user
root@testStep 5

  • Use the following commands

    "dmesg | grep SCSI"
    This command is used to get the entire disk attached followed by filtration into SCSI disks.
root@test-1
Lastly Added disk [sdc] is our "BackupDrive" that we created using Azure Portal.

"sudo fdisk /dev/sdc"
This command is used to Partition the disk. After this press 'n' for partition type which are 'p' for Primary and 'e' for Extended, here we select 'p'
i.e primary.
You can just press 'Enter' to select default values for next steps.

root
Here now we have created a new partition of size 1 GB which is our disk size we created in portal.

Step 6

Now we can print the partition table and write it to disk.
  • type 'p' to print table and then type 'w' to write it to disk
command
Futher we need to write filesystem to disk. For this we use the following command:

"sudo mkfs -t ext4 /dev/sdc1"

roots@
  • Here we have created a filesystem with type 'ext4' on '/dev/sdc1' partition. Further we need to mount this filesystem to a directory that we will create in next step.
Step 7

  • Here we have created a new directory "TestDrive" in using the following command
    "sudo mkdir TestDrive"

root-1

Step 8

  • Mount the filesystem "/dev/sdc1" to this "TestDrive" directory
    "sudo mount /dev/sdc1 TestDrive"
root-2
  • if we see "lost+found" in your list of items in "TestDrive" then your disk is successfully mounted!!
  • To test this we can create a directory inside it
root-3
The additional disk is attached and mounted to a Virtual Machine. By referring to this blog, you can create multiple disks as per your requirements.

e-Zest is a leading digital innovation partner for enterprises and technology companies that utilizes emerging technologies for creating engaging customers experiences. Being a customer-focused and technology-driven company, it always helps clients in crafting holistic business value for their software development efforts. It offers software development and consulting services for cloud computing, enterprise mobility, big data and analytics, user experience and digital commerce.