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.
- Application-Server: This resides in a private application subnet under the Spoke Resource Group.
- A VNet Peering connection is established between the Hub VNet and Spoke VNet to enable internal communication between the two VMs.
-
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:
-
SSH into Bastion-Server.
-
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:
ssh Azureuser@<private-ip of Application Instance>
ssh [email protected]
Use lsblk to list current block devices:
lsblk
11_4: Create a Managed Disk
Go to Azure Portal → Application Server->Disk->Data Disk->Create and Attach a New Disk
Fill in the required details:
Size (e.g., 1024 GB Premium SSD)
Click Apply.
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
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
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
Type w in help to write the partition and then run lsblk to check the partition.
11_6: Create a Physical Volume
Step1:Run pvcreate command to create physical volume.
pvcreate /dev/sdc1
Step2: Run pvdisplay to see the volume.
pvdisplay /dev/sdc1
11_7: Create a Volume Group
Step1: Create a volume group by running vgcreate.
vgcreate vg_u01 /dev/sdc1
Step2: Run “vgdisplay vg_u01” to display the volume group created and to see the Number of Physical Extent.
vgdisplay vg_u01
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
Step2: Map it
ls -l /dev/mapper/vg_u01-lv_u01
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
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
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
Add the following line:
/dev/mapper/vg_u01-lv_u01 /u01 ext4 defaults,_netdev,nofail 0 2
Step3: After adding this line in /etc/fstab, we have to run mount –a command.
mount -a
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
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.