11_Creating_and_Attaching_Managed Disks_in_Azure - Nirvan-Pandey/Azure_DOC GitHub Wiki

11_1: Introduction

This lab walks through the process of creating and attaching managed disks to a virtual machine in Azure and setting up logical volumes to use the disk inside the Linux OS. We will first log in to the VM, check existing block devices, then attach a disk and make it available via LVM.

11_2: Lab Prerequisites

In this lab setup:

We have two virtual machines deployed:

  • Bastion-Server: This is in a public subnet inside the Hub Resource Group.

image

  • Application-Server: This resides in a private application subnet under the Spoke Resource Group.

image

  • A VNet Peering connection is established between the Hub VNet and Spoke VNet to enable internal communication between the two VMs.

image

  • The Bastion-Server will serve as our jump host, allowing us to SSH into it and then access the Application-Server from within the network.

  • We will use PuTTY (or any SSH terminal) to:

    1. SSH into Bastion-Server.

    2. From Bastion-Server, SSH into Application-Server using its private IP.

11_3: Login to the VM and Check Existing Disks

SSH into your VM using PuTTY or terminal:

image

ssh Azureuser@<private-ip of Application Instance>
ssh [email protected]

image

Use lsblk to list current block devices:

lsblk

image

11_4: Create a Managed Disk

Go to Azure Portal → Application Server->Disk->Data Disk->Create and Attach a New Disk

image

Fill in the required details:

Size (e.g., 1024 GB Premium SSD)

Click Apply.

image

Note: In another way, we can create Managed Disk and attach the managed the disk to the VM.

Go back to your VM and run lsblk

image

You’ll now see a new disk (e.g., /dev/sdc).

Now we will reflect the Managed Disk in server.

You will login through azureuser which is the instance user. For performing to root user, we need to use the sudo command.

sudo su - root

image

11_5: Create a New Partition

Use fdisk to partition the new disk and and type m for help.

fdisk /dev/sdc

Type n for new partition

image

image

Type w in help to write the partition and then run lsblk to check the partition.

image

11_6: Create a Physical Volume

Step1:Run pvcreate command to create physical volume.

pvcreate /dev/sdc1

image

Step2: Run pvdisplay to see the volume.

pvdisplay /dev/sdc1

image

11_7: Create a Volume Group

Step1: Create a volume group by running vgcreate.

vgcreate vg_u01 /dev/sdc1

image

Step2: Run “vgdisplay vg_u01” to display the volume group created and to see the Number of Physical Extent.

vgdisplay vg_u01

image

11_8: Create a Logical Volume

Step1: Create a logical volume by lvcreate and map it to our volume group

lvcreate -l 12799 -n lv_u01 vg_u01

image

Step2: Map it

ls -l /dev/mapper/vg_u01-lv_u01

image

Logical volume is created inside our volume group.

11_9: Format the Logical Volume

Step1: Running the command mkfs using ext4 file system.

mkfs.ext4 /dev/mapper/vg_u01-lv_u01

image

11_10: Mount the Logical Volume

Step1: Making directory and mounting it.

mkdir /u01
mount -t ext4 /dev/mapper/vg_u01-lv_u01 /u01

Step2:Check the mount:

After mounting run df -h to see that the logical volume is mounted.

df -h

image

11_11: Make Mount Persistent via /etc/fstab

Mount the volume permanently in /etc/fstab or else it will get removed after the server reboots.

Step1: Go to etc folder.

cd /etc

Step2: Edit the fstab file and add the line below in it.

vi fstab

image

Add the following line:

/dev/mapper/vg_u01-lv_u01 /u01 ext4 defaults,_netdev,nofail 0 2

image

image

Step3: After adding this line in /etc/fstab, we have to run mount –a command.

mount -a

image

Step4: Run the command "systemctl daemon-reload" to mount this volume premanently.

systemctl daemon-reload

Step5: See Again to confirm by using df -h & lsblk

image

After rebooting the server also we can see the disk attached.

11_12: Conclusion

In this lab, we successfully demonstrated how to create and attach managed disks to a Linux virtual machine in Microsoft Azure. We began by verifying the current disk setup using lsblk, then created a new managed disk and attached it to the virtual machine. From there, we partitioned the disk, created a physical volume, volume group, and logical volume, and finally formatted and mounted the volume for persistent use.