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

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

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.

Prerequisite Linux VM

Installation Procedure:

Step 1: Log in to Azure Portal

Step 2: Select your VM

Step 3: Start the Virtual machine

Step 4: Go to command prompt login to the Linux machine

Step 5: Check the OS version by using the below command

linuxhelp@secondary-server: ~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.6 LTS
Release:        18.04
Codename:       bionic

Step 6: Once connected to your VM, you need to find the disk.

linuxhelp@secondary-server: ~$ lsblk
NAME    MAJ: MIN RM SIZE RO TYPE MOUNTPOINT
sda       8:0    0   30G 0 disk
├─sda1    8:1    0 29.9G 0 part /
├─sda14   8:14   0    4M 0 part
└─sda15   8:15   0 106M 0 part /boot/eGFI
sdb       8:16   0    4G 0 disk
└─sdb1    8:17   0    4G 0 part /mnt

Step 7: Next go to Azure portal and attach a new disk On the Disks pane, under Data disks, select Create and attach a new disk.

Step 8: Enter a name for your managed disk. Review the default settings, and update the Storage type, Size (GiB), Encryption and Host caching as necessary.

Step 9: Open fdisk to create partitions on /dev/sdc disk

root@secondary-server:~# fdisk /dev/sdc


Welcome to fdisk (util-Linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disk label with disk identifier 0x30dc808b.

Command (m for help): n'
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-16777215, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-16777215, default 16777215):

Created a new partition 1 of type 'Linux' and of size 8 GiB.

Command (m for help): p
Disk /dev/sdc: 8 GiB, 8589934592 bytes, 16777216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x30dc808b

Device     Boot Start      End  Sectors Size Id Type
/dev/sdc1        2048 16777215 16775168   8G 83 Linux

Command (m for help): w

The partition table has been altered.
Calling IOCtl () to re-read partition table.
Syncing disks.

Step 10: Use the lsblk command to find the partition mounted on the root of the file system.

root@secondary-server: ~# lsblk
NAME    MAJ: MIN RM  SIZE RO TYPE MOUNTPOINT
sda       8:0    0   30G  0 disk
├─sda1    8:1    0 29.9G  0 part /
├─sda14   8:14   0    4M  0 part
└─sda15   8:15   0  106M  0 part /boot/efi
sdb       8:16   0    4G  0 disk
└─sdb1    8:17   0    4G  0 part /mnt
sdc       8:32   0    8G  0 disk
└─sdc1    8:33   0    8G  0 part

Step 11: Format the file system “sdc” to ext4 file system

root@secondary-server: ~# mkfs. ext4 /dev/sdc1
mke2fs 1.44.1 (24-Mar-2018)
Discarding device blocks: done
Creating filesystem with 2096896 4k blocks and 524288 inodes
Filesystem UUID: 52ad0f32-d9e7-4fc1-84fd-5b626a026072
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

Step 12: Mount the disk Create a directory to mount the file system using mkdir

root@secondary-server: ~# mkdir /data
root@secondary-server: ~# mount /dev/sdc1 /data/

Step 13: Viewing the mounted status by using following command

root@secondary-server:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            438M     0  438M   0% /dev
tmpfs            92M  592K   91M   1% /run
/dev/sda1        29G  1.5G   28G   6% /
tmpfs           457M     0  457M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           457M     0  457M   0% /sys/fs/cgroup
/dev/sda15      105M  4.4M  100M   5% /boot/efi
/dev/sdb1       3.9G   28K  3.7G   1% /mnt
tmpfs            92M     0   92M   0% /run/user/1000
/dev/sdc1       7.8G   24K  7.4G   1% /data

Step 14: Next Permanently mount the file system and copy the sdc UID by using following commands.

root@secondary-server:~# blkid
/dev/sdb1: UUID="a7ee9f8c-e179-40ef-a347-d780d85327ef" TYPE="ext4" PARTUUID="f51d685b-01"
/dev/sda1: LABEL="cloudimg-rootfs" UUID="143c811b-9b9c-48f3-b0c8-040f6e65f50a" TYPE="ext4" PARTUUID="02b05550-26f1-4959-b139-aa97efeadaca"
/dev/sda15: LABEL="UEFI" UUID="FC91-4E65" TYPE="vfat" PARTUUID="5f2e8bd0-b7ad-4eca-9621-cdc22fedde98"
/dev/sda14: PARTUUID="28450b13-5b7b-4223-aaac-70ddf8590fbf"
/dev/sdc1: UUID="52ad0f32-d9e7-4fc1-84fd-5b626a026072" TYPE="ext4" PARTUUID="30dc808b-01"

Step 15: Next, open the /etc/fstab file in a text editor as follows: root@secondary-server:~# nano /etc/fstab

Step 16: Mounts all file systems listed in /etc/fstab. root@secondary-server:~# mount -a

Step 17: You can now use lsblk again to see the disk and the mountpoint.

root@secondary-server:~# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda       8:0    0   30G  0 disk
├─sda1    8:1    0 29.9G  0 part /
├─sda14   8:14   0    4M  0 part
└─sda15   8:15   0  106M  0 part /boot/efi
sdb       8:16   0    4G  0 disk
└─sdb1    8:17   0    4G  0 part /mnt
sdc       8:32   0    8G  0 disk
└─sdc1    8:33   0    8G  0 part /data

Step 18: finally go to azure portal turn off the Virtual machine

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to create, attach, and mount a disk to Linux VM (Microsoft Azure). Your feedback is much welcome.

FAQ
Q
How do you calculate disk capacity?
A
The first way would be to multiply bytes per sector times sector per track. This gives us bytes per track. Multiplying this times tracks per cylinder, we end up with bytes per cylinder. Multiplying this times the number of cylinders, we get the bytes for the disk
Q
How to permanently mount the hard disk?
A
Add the disk permanently /etc/fstab
Q
What is the maximum storage for disks?
A
In 2018, the largest hard drive had a capacity of 15 TB, while the largest capacity SSD had a capacity of 100 TB. As of 2018, HDDs were forecast to reach 100 TB capacities around 2025, but as of 2019, the expected pace of improvement was pared back to 50 TB by 2026.
Q
What types of disks can be attached to an Azure VM?
A
Persistent, secured disk storage for Azure virtual machines

We offer four disk storage options — Ultra Disk Storage, Premium SSD, Standard SSD, and Standard HDD.
Q
Can we attach the disk while running the Azure VM?
A
You can attach a data disk to a Windows VM in the Azure portal. Before you attach disks to your VM, review these tips: Check the size of the virtual machine that controls the data disks to attach