azureazure-cliazure-disk

Expand virtual hard disks on a Linux VM with the Azure CLI


I am trying to extend a disk in my vm (azure). I used to do it like this:

sudo umount /dev/sdc1 

(sdc1 as an example)

sudo parted /dev/sdc

after typing print, I should see something like this:

GNU Parted 3.2
Using /dev/sdc1
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: Unknown Msft Virtual Disk (scsi)
Disk /dev/sdc1: 215GB
Sector size (logical/physical): 512B/4096B
Partition Table: loop
Disk Flags:

Number  Start  End    Size   File system  Flags
    1      0.00B  107GB  107GB  ext4

I can't go any further because in my case after typing this command I see:

GNU Parted 3.3
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print                                                            
Model: Msft Virtual Disk (scsi)
Disk /dev/sdc: 550GB
Sector size (logical/physical): 512B/4096B
Partition Table: msdos
Disk Flags: 

As you can see, there are no partitions, so I can't use resizepart command.

lsblk -o NAME,HCTL,SIZE,MOUNTPOINT | grep -i "sd"

sda     1:0:1:0      16G 
└─sda1               16G /mnt
sdb     0:0:0:0      30G 
├─sdb1             29.9G /
├─sdb14               4M 
└─sdb15             106M /boot/efi
sdc     3:0:0:0     512G 

Solution

  • As you can see, there are no partitions, so I can't use resizepart command.

    You Need to format the disk sdc to create partitions using either xfs or ext4 file system & to procced further resize/expand the disk partition & file system.

    Cmdlets for disk format & diskpartition using XFS file system:

    sudo parted /dev/sdc --script mklabel gpt mkpart xfspart xfs 0% 100%
    sudo mkfs.xfs /dev/sdc1
    sudo partprobe /dev/sdc1
    

    Here we are formatting the disk using XFS file system & using the partprobeutility to make sure the kernel is aware of the new partition and filesystem.

    Reference documentation to format the disk & also you can refer this blog on How to create a ext4 file system partition in Linux.

    We have tested in our local environment creating a disk partition (to newly attached disk to the linux machine running with ubuntu 20.84 image) & initializing the disk partition with xfs file system.

    Below is the reference image when we created a new disk & attached it to the virtual machine. When ran lsblk you see that disk is not mounted & it has no partitions.

    enter image description here

    enter image description here

    In the above image, post running the above mentioned disk format & file partition cmdlets you can see a new partition with sdc1 got created.