Adding and extending disks/volumes in LVM
From Tech-Wiki
More actions
Extend an LVM-backed Linux filesystem by adding a new partition or disk to the existing volume group and logical volume.
Check the target disk and filesystem first
Partitioning and volume-management commands can destroy data if the wrong device is selected. Confirm the disk, volume group, logical volume and filesystem type before making changes, and ensure a recoverable backup exists.
Create the LVM partition
The original procedure uses fdisk and an LVM partition type of 8e.
Open the disk in fdisk
fdisk /dev/sdb
Within fdisk:
- Press
pto print the partition table. - Press
nto create a new primary partition. - Select the required partition number and accept the appropriate start/end sectors.
- Press
tto change the partition type. - Select the newly created partition.
- Set the partition type to
8efor Linux LVM. - Press
wto write the changes.
Create the physical volume
Create the physical volume
pvcreate /dev/sdb1
Verify the new physical volume and the existing volume groups:
Verify LVM state
pvs vgdisplay
Extend the volume group
Add the new physical volume to the volume group
vgextend vg_root /dev/sdb1
The same approach can be used when spanning a volume group across an additional disk.
Check free space
vgs pvscan
Extend the logical volume
Identify the logical-volume path and available capacity:
Review volume group and logical volume
vgdisplay lvdisplay
Extend by a fixed amount:
Add 100 GB
lvextend -L +100G /dev/vg_root/vol1
Or use all remaining free extents:
Use all free space
lvextend -l +100%FREE /dev/vg_root/vol1
Grow the filesystem
The original article uses resize2fs:
Resize the filesystem
resize2fs /dev/vg_root/vol1
Filesystem-specific step
Use the filesystem resize command appropriate to the filesystem on the target logical volume. The command above is the method retained from the original article.
Verify
Review the final LVM size
vgdisplay lvdisplay