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:
- PV (Physical Volume): a disk or partition used by LVM (for example
/dev/sda3). - VG (Volume Group): a pool of PVs (for example
vg_data=/dev/sdb1+/dev/sde1). - LV (Logical Volume): a volume carved out of a VG (for example
vg_data/lv_data).
2. Extend an existing disk (VMDK)
- Enlarge the disk in VMware.
- Recreate the LVM partition with
fdisk:sudo fdisk /dev/sdapto print the partitionsdthen3to delete the last partition (the LVM partition)nto create a new partition, following the prompts- answer
yiffdiskasks whether to keep the detected LVM signature tto set the partition type to Linux LVMwto write the partition table
- 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
- 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
- Add the disk in VMware.
- Create a partition on the new disk with
fdisk, then runpartprobe. - Check the new disk:
sudo lvmdiskscan
sudo fdisk -l
sudo fdisk -l | grep '^Disk /dev/'
- Create the physical volume (PV):
sudo pvcreate /dev/sde1
sudo pvcreate /dev/sdf1
sudo lvmdiskscan -l
sudo pvdisplay
- For an existing disk that was enlarged, resize the PV and check it:
sudo pvresize /dev/sdb
sudo pvdisplay
- 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
- ext2, ext3, ext4:
sudo resize2fs -p /dev/mapper/vg_data-lv_data
- XFS (pass the mount point):
sudo xfs_growfs /mnt/data
Then verify:
df -H
sudo sfdisk --list-free /dev/sdX
cfdisk /dev/sdX
Notes
- Recreate the LVM partition with exactly the same start sector as the deleted one. A different start sector makes the PV unusable.
- Make a backup before changing the partition table.
xfs_growfstakes a mount point, not a device.