LLI Wiki — My Digital Knowledge Base

Extend an LVM volume after a VMware disk resize

Grow an LVM logical volume on Linux after extending the VMDK disk, or add a new disk to the volume group.

This guide explains how to grow an LVM logical volume on Linux after enlarging the virtual disk (VMDK in VMware), or how to add a new disk to a volume group. Device, group and volume names are generic.

1. Identify the disks and the LVM layout

List the disks seen by the system:

lsscsi
ls /sys/class/scsi_disk/
lsblk
dmesg | grep -i 'Attached SCSI disk'
sudo fdisk -l
sudo fdisk -l | grep '^Disk /dev/'

Show the LVM components:

sudo pvs
sudo pvdisplay
sudo vgs
sudo vgdisplay
sudo lvs
sudo lvmdiskscan -l
ls -l /dev/mapper/*
lvdisplay | awk '/LV Name/{n=$3} /Block device/{d=$3; sub(".*:","dm-",d); print d,n;}'
iostat -Nd

Check the filesystems and mount points:

df -Th
fsck -N /dev/sdb1
lsblk -f
mount | grep "^/dev"
sudo file -sL /dev/sda3
blkid /dev/sda3
cat /etc/fstab

fsck -N prints the command without running it.

Glossary:

2. Extend an existing disk (VMDK)

  1. Enlarge the disk in VMware.
  2. Recreate the LVM partition with fdisk:
    • sudo fdisk /dev/sda
    • p to print the partitions
    • d then 3 to delete the last partition (the LVM partition)
    • n to create a new partition, following the prompts
    • answer y if fdisk asks whether to keep the detected LVM signature
    • t to set the partition type to Linux LVM
    • w to write the partition table
  3. Make the kernel re-read the partition table: sudo partprobe (or reboot).

Expected result:

[root@server01 ~]# fdisk -l /dev/sda
Disk /dev/sda: 75 GiB, 80530636800 bytes, 157286400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 00000000-0000-0000-0000-000000000000

Device      Start       End   Sectors  Size Type
/dev/sda1    2048    391167    389120  190M EFI System
/dev/sda2  391168    903167    512000  250M Linux filesystem
/dev/sda3  903168 157286366 156383199 74.6G Linux filesystem
  1. If the new size is not visible, rescan the SCSI bus (as root):
ls /sys/class/scsi_host
echo "- - -" > /sys/class/scsi_host/host0/scan
echo 1 > /sys/class/scsi_device/0:0:0:0/device/rescan
echo 1 > /sys/class/scsi_disk/2:0:2:0/device/rescan
partprobe
partx -v -a /dev/sda

3. Add a new disk

  1. Add the disk in VMware.
  2. Create a partition on the new disk with fdisk, then run partprobe.
  3. Check the new disk:
sudo lvmdiskscan
sudo fdisk -l
sudo fdisk -l | grep '^Disk /dev/'
  1. Create the physical volume (PV):
sudo pvcreate /dev/sde1
sudo pvcreate /dev/sdf1
sudo lvmdiskscan -l
sudo pvdisplay
  1. For an existing disk that was enlarged, resize the PV and check it:
sudo pvresize /dev/sdb
sudo pvdisplay
  1. Add the PV to the volume group:
sudo vgdisplay
sudo vgextend vg_data /dev/sde1
sudo pvscan

4. Extend the logical volume

Check the mount point, then extend the LV:

mount | grep '/mnt'
sudo lvextend -l +100%FREE /dev/mapper/vg_data-lv_data
# or a fixed size:
sudo lvextend -L+1GB /dev/mapper/vg_data-lv_data
# or a number of physical extents:
sudo lvextend -l +2560 /dev/mapper/vg_data-lv_data

5. Resize the filesystem

sudo resize2fs -p /dev/mapper/vg_data-lv_data
sudo xfs_growfs /mnt/data

Then verify:

df -H
sudo sfdisk --list-free /dev/sdX
cfdisk /dev/sdX

Notes

References

Mastodon LLIMastodon SocialFosstodon