Extending Partitions in Linux VMs after Expanding Virtual Disks

Edson Kimuli
3 min readJul 8, 2022

--

Extending Partitions in Linux VMs after Expanding Virtual Disks

Let’s imagine this scenario whereby your Linux virtual machine is underperforming as a result of low disk space. Virtualization software such as Proxmox VE, VMware, etc, allow you to easily configure virtual hardware such as CPU, memory, and hard disk size for your virtual machine. You can extend the size of an existing virtual disk. However, you must resize a partition manually after that since disk space added after you extend a virtual disk is unallocated.

In this article, we are going to learn how to add extra space into an existing Linux partition.

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

Step 1: Check the disk

Use the command below to check the disk.

sudo fdisk -l
Check Linux Hard Disk

Step 2: Extend boot partition

Use cfdisk to extend boot partition,select it, (/dev/sda3 in my case) and select “Resize”

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

Your disk space is now successfully increased.

Conclusion

Such an issue is quite common when running virtual machines and this way, you can be able to overcome it.

--

--

Responses (1)