How to extend disk using LVM in Linux
Recommendation: Read first: How to Create an LVM Partition before proceeding with the steps below.
Implementation
-
Check filesystem usage
Shows filesystem size, used space, and available space.
df -h
-
Identify the new disk
List disks and partitions. Example: /dev/nvme2n1 (8 GB).
fdisk -l lsblk
-
Create an LVM partition
fdisk /dev/nvme2n1
Inside fdisk:
- n – Create a new partition
- Accept defaults to use the whole disk.
- t- Change the partition type to Linux LVM (8e)
- w – Write changes and exit
Verify the partition was created:
lsblk
-
Check existing LVM configuration
pvs vgs lvs
- pvs – shows physical volumes (PVs)
- vgs – shows volume groups (VGs) and free space
- lvs – shows logical volumes (LVs) and their sizes
-
Create a Physical Volume (PV)
Initializes the partition for LVM
pvcreate /dev/nvme2n1p1
verify:
pvs
-
Extend the Volume Group (VG)
Adds the new PV to docker_vg, increasing its storage capacity
vgextend docker_vg /dev/nvme2n1p1
-
Extend the Logical Volume (LV)
lvextend -l +100%FREE /dev/docker_vg/docker_lv
- -l +100%FREE – Allocates all currently free space in the VG to docker_lv, including free space left on existing disks and space from newly added disks.
- Example: If the VG has 15 GB free and docker_lv is 1 GB, the LV becomes approximately 16 GB.
-
Grow the filesystem
For XFS, assuming /docker is the mount point
xfs_growfs /docker
- Expands the mounted XFS filesystem to use the additional LV space.
-
Verify
df -h /docker lvs vgs