Expand Storage in Ubuntu VM

Before executing the commands for expanding the storage inside the VM, make sure that the desired size is already assigned in the hypervisor level.

Steps for Expanding Storage

Verify the currently existing disks, partitions and logical volumes.

lsblk

Rescan the disks to allow OS to see the newly allocated size

echo 1 | sudo tee /sys/class/block/<DISK_DEVICE_ACCORDING_TO_LSBLK>/device/rescan

Resize the LVM physical volume.

sudo pvresize /dev/<LVM_PARTITION>

Verify the free space in the volume group. You should be able to see “Free PE / Size” showing space available to extend the logical volume.

sudo vgdisplay

Extend the logical volume. The “+100%FREE” uses all available space in the volume group.

sudo lvextend -l +100%FREE /dev/<LOGICAL_VOLUME>

Resize the file system.

sudo resize2fs /dev/<LOGICAL_VOLUME>

Verify the new disk size.

df -h


Other ways to extend the partition using PARTED:

#RUN PARTED
sudo parted /dev/nvme0n1
(parted) print
(parted) resizepart 3 100%
(parted) quit
lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv


Terms to Remember

Disk
  • The physical hard drive or SSD in your computer or VM.
  • Example: /dev/nvme0n1.
Partition
  • A section of the disk set aside for storing data.
  • Example: /dev/nvme0n1p3 is partition 3 on disk /dev/nvme0n1.
File system
  • The way data is organized on a partition so the OS can read/write files.
  • Example: ext4, FAT32.
Logical Volume (LV)
  • A “virtual disk” inside a volume group.
  • Can grow or shrink without touching the actual partition.
  • Example: /dev/ubuntu-vg/ubuntu-lv.
Volume Group (VG)
  • A pool of storage made from one or more partitions (physical volumes).
  • Logical volumes take space from this pool.
  • Example: ubuntu-vg.
Physical Volume (PV) / LVM Partition
  • A partition that has been turned into LVM storage.
  • The building block of a volume group.
  • Example: /dev/nvme0n1p3 used in ubuntu-vg.
Disk Device
  • The OS name for a disk or partition, used in commands.
  • Example: nvme0n1 for the whole disk, nvme0n1p3 for a partition.

Note:
  • Disk → Partition → File system → classic way of dividing and storing data.
  • LVM: PV → VG → LV → File system → flexible, virtualized storage that can grow/shrink easily.