I came across the need to extend a partition on a Centos VM deployed in Azure which was not running LVM, but XFS. This seems to be a common way of how the templates are deployed in Azure.
I won’t go into detail on how you increase the disk space on the virtualization layer, I’ll leave that to you since it’s different for every platform and a fairly basic task.
This example is for increasing /dev/sda2. Let’s say you’ve increased your disk from 32GB to 64GB, however when issuing the below command to list your disks, you still see it at 32GB!
df -h Resulting Output - Filesystem Size Used Avail Use% Mounted on udev 1.5G 0 1.5G 0% /dev tmpfs 291M 33M 259M 12% /run /dev/sda2 32G 3.9G 32G 11% / tmpfs 1.5G 4.0K 1.5G 1% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 1.5G 0 1.5G 0% /sys/fs/cgroup /dev/vda1 472M 171M 277M 39% /boot tmpfs 291M 0 291M 0% /run/user/0
From here, you’ll want to run the below command to see that the OS is recognizing the increase space and just hasn’t allocated it –
fdisk -l Resulting Output - Disk /dev/vda: 64 GiB, 42949672960 bytes, 83886080 sectors
Now that we have confirmed the OS is seeing the extra space, lets assign it to the partition we need –
1) fdisk -l /dev/sda 2) p (This will print the existing partition table) 3) d (This will enter delete mode to remove the partition) 4) 2 (This is the partition number we want to delete) 5) p (This will print the partition table again to confirm) 6) n (Wizard to create new partition) 7) p (This selects type of partition, in our case P for primary) 8) 2 (Re use the partition number we had previously) 9) First sector - just press enter to accept the default 10) Last sector - same as above, this will ensure its assigned all available free space on that disk 11) w - this will write the partition
After completing the above steps, you will be given a warning about the device or resource being busy, don’t worry this is completely fine. One more command before we reboot –
partprobe
This will synchronize the partition to the kernel however fail due to requiring a reboot to take effect. Reboot now and execute the final step once back up –
xfs_growfs /
This will now assign all the free space available and we should be fine!
Leave a Reply
You must be logged in to post a comment.