Extending Partitions in Linux VMs after Expanding Virtual Disks

Extending Partitions in Linux VMs after Expanding Virtual Disks

Pre-requisites

  • Backup your VM before doing disk operations.
  • Snapshots must not be enabled on the virtual disk. If enabled, delete them before you resize the virtual disk.

Resizing a Virtual Disk in Linux

sudo fdisk -l
Check Linux Hard Disk
sudo cfdisk
Extend Boot Partition
  • Click Enter, New size is shown
Extend Linux Virtual Disk Drive
  • Then select Write, when prompted, type Yes, and then select Quit and press Enter
Confirm partition linux extension
  • Run fdisk -l /dev/sda, to confirm whether partition is extended
Confirm whether partition is extended
  • Get PV (Physical Volume) name ie (/dev/sda3)
sudo pvs
get physical volume name
  • Resize the physical volume, PV
sudo pvresize /dev/sda3
resize physical volume
  • Get root logical volume name (Filesystem value of / row; ex: /dev/mapper/ubuntu--vg-ubuntu--lv)
df -h
get root logical volume name
  • Expand the logical volume
sudo lvextend -r -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
expand logical volume

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store