Extend a Disk on Ubuntu Server (VMware, LVM, ext4, XFS)
1. Grow the disk in vCenter
VM > Edit Settings > select the disk and increase its size. Most VMs allow hot-extend; if not, power off first. The VM must have no snapshots.
2. Make Ubuntu see the new size
lsblk -f # disks, partitions, filesystems and mount points
sudo fdisk -l /dev/sdX # real disk size
If the size hasn't changed, rescan the disk (replace sdX):
echo 1 | sudo tee /sys/class/block/sdX/device/rescan
3. Which case are you in?
| Case | How to spot it | Go to |
|---|---|---|
Disk with partitions (e.g. sda3 with LVM) |
lsblk shows children under the disk |
Section 4 |
Disk without partitions (e.g. sdb mounted directly) |
lsblk shows no children |
Section 5 |
4. Disk with partition + LVM (default Ubuntu install)
sudo growpart /dev/sda 3 # grow partition 3 to use the new space
sudo pvresize /dev/sda3 # tell LVM the PV is bigger
sudo pvs # PFree should now show free space
sudo lvextend -r -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
df -h /
-r resizes the filesystem too. If it fails, resize it by hand as in section 5.
5. Disk without partitions
Check the filesystem with lsblk -f /dev/sdb, then:
sudo resize2fs /dev/sdb # ext4: takes the device
sudo xfs_growfs /var # XFS: takes the mount point
df -h /var
Both work online, no need to unmount.
Notes
growpartcomes incloud-guest-utils(sudo apt install cloud-guest-utils).- Don't use
pvresizeorlvextendon disks without LVM. - If
lsblk -fshows an LVM PV directly on a whole disk, skipgrowpartand start atpvresize /dev/sdX. - On GPT disks, check there's no other partition after the one you want to grow.
Related: add a new disk and disk full? free space.