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
- Go to the Azure Portal
- Use the top search bar to search for Disks
- Click + Add to create a new managed disk
📷 Refer to below screenshots
🔹 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
Run lsblk command to check the existing volumes in the server.
lsblk
Formatting the Disk
Run “fdisk /dev/sdb” command
sudo fdisk /dev/sdb
- Type “n” to create a new partition.
Create a Physical Volume
- Run "pvcreate /dev/sdb1" to create the physical volume
sudo pvcreate /dev/sdb1
- Run "pvdisplay /dev/sdb1" to display the physical volume created
sudo pvdisplay /dev/sdb1
Create a Volume Group
- Run "vgcreate vg_u01 /dev/sdb1" to create the volume group
sudo vgcreate vg_u01 /dev/sdb1
- Run “vgdisplay vg_u01” to display the volume group created and to see the Number of Physical Extent.
sudo vgdisplay vg_u01
Create a logical volume and map it to our volume group
- 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
- Logical volume is now created inside our volume group
Format this logical volume using a file system
sudo mkfs.ext4 /dev/mapper/vg_u01-lv_u01
Create a Directory to mount the logical volume
- Run the below commands to mount the logical volume
mkdir /u01
sudo mount -t ext4 /dev/mapper/vg_u01-lv_u01 /u01
- Now we are able to see that the logical volume is mounted.
Mount the volume permanently in /etc/fstab or else it will get removed after the server reboots.
- Add the line below in /etc/fstab
sudo vi /etc/fstab
/dev/mapper/vg_u01-lv_u01 /u01 ext4 defaults,_netdev,nofail 0 2
- Run the command "systemctl daemon-reload" to mount this volume premanently
mount -a
Restart the VM and run "lsblk" and "df -h" command to check the new partition