11 ‐ Create and attach managed disk - SanjeevOCI/Azure GitHub Wiki

💾 Create and Attach a Managed Disk to an Azure VM

This lab demonstrates how to create a managed disk and attach it to an existing Azure Virtual Machine using the Azure Portal.


🧱 Prerequisites

  • An active Azure subscription
  • An existing Azure Virtual Machine (VM)
  • Appropriate permissions to create disks and modify VMs

🔹 Step 1: From BastionVM, SSH to PrivateVM. Now Navigate to “Disks” in the Private VM

  1. Go to the Azure Portal
  2. Use the top search bar to search for Disks
  3. Click + Add to create a new managed disk

📷 Refer to below screenshots

11_Create_Attach_Managed_Disk_1

11_Create_Attach_Managed_Disk_2

11_Create_Attach_Managed_Disk_3

AppserverVM_creation_3


🔹 Step 2: Create a New Managed Disk

Fill in the disk creation details:

  • Subscription and Resource Group: Match the VM’s
  • Disk Name: e.g., DataDisk1
  • Region: Same as the VM’s region
  • Availability Zone: Optional; align with the VM if needed
  • Size and Performance: Choose a disk type (Standard HDD, Standard SSD, Premium SSD) and size (e.g., 128 GiB)

Click Review + Create, then C

AppserverVM_creation_4

AppserverVM_creation_5

AppserverVM_creation_6


Run lsblk command to check the existing volumes in the server.

lsblk

AppserverVM_creation_7


Formatting the Disk

Run “fdisk /dev/sdb” command

sudo fdisk /dev/sdb

  1. Type “n” to create a new partition.

Create a Physical Volume

  1. Run "pvcreate /dev/sdb1" to create the physical volume

sudo pvcreate /dev/sdb1

  1. Run "pvdisplay /dev/sdb1" to display the physical volume created

sudo pvdisplay /dev/sdb1

AppserverVM_creation_8

AppserverVM_creation_9

Create a Volume Group

  1. Run "vgcreate vg_u01 /dev/sdb1" to create the volume group
sudo vgcreate vg_u01 /dev/sdb1
  1. Run “vgdisplay vg_u01” to display the volume group created and to see the Number of Physical Extent.

sudo vgdisplay vg_u01

AppserverVM_creation_10

AppserverVM_creation_11

Create a logical volume and map it to our volume group

  1. Run the below commands to create the logical volume

sudo lvcreate -l 12799 -n lv_u01 vg_u01

ls -l /dev/mapper/vg_u01-lv_u01

  1. Logical volume is now created inside our volume group

AppserverVM_creation_12

AppserverVM_creation_13

Format this logical volume using a file system

sudo mkfs.ext4 /dev/mapper/vg_u01-lv_u01

AppserverVM_creation_14

Create a Directory to mount the logical volume

  1. Run the below commands to mount the logical volume

mkdir /u01

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

  1. Now we are able to see that the logical volume is mounted.

AppserverVM_creation_15

AppserverVM_creation_16

AppserverVM_creation_17

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

  1. Add the line below in /etc/fstab

sudo vi /etc/fstab

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

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

mount -a

AppserverVM_creation_18

AppserverVM_creation_19

AppserverVM_creation_20

Restart the VM and run "lsblk" and "df -h" command to check the new partition

AppserverVM_creation_21

AppserverVM_creation_22

AppserverVM_creation_23