Skip to content

How to Resize a Logical Volume (LVM) in CentOS 7

Summary

When extending a virtual disk in Xen Center, it's not as simple as just opening the Storage tab and allocating free space. This is only the first part of it, as all this is doing is adding unallocated space into a separate volume.

This article assumes that additional storage has already been added to the virtual disk within Xen Center.

How To

The following steps should be taken inside an elevated (sudo) Terminal window after you've ssh'd into the Docker VM...

Begin resizing the logical volume

# fdisk -l /dev/xvda

Create a new primary partition and set the type as Linux LVM.

# Add a new partition
n

# Primary partition
p

# Partition number 3 (may need to be adjusted depending on number of partitions; likely just use default)
3 

# First Cylinder
default

# Last Cylinder
default

# Verify new partition has been created; type on new partition is likely not LVM and will need to be changed.
p 

# Change the partition's system ID
t

# Partition Number
default

# Linux LVM
8e

# Confirm partition type is now LVM
p 

# Write table to disk and exit
w

# Reboot the VM
reboot

Create a new primary volume and extend the volume group to the new volume.

# Display the volume group; make note of volume name
vgdisplay

# Display the logical volume
lvdisplay

# 'centos' is the name of the volume from vgdisplay
pvcreate centos /dev/xvda3

# Extend the volume group
vgextend /dev/centos /dev/xvda3

Check the physical volume for free space, extend the logical volume with the free space.

# Shows amount of virtual free space; make note of this
vgs

# Extend virtual free space to logical volume
lvextend -L+{virtual free space} /dev/mapper/centos/root

# Should no longer have unallocated virtual free space
vgs

Finally, resize the logical volume, then check the available free space.

# Resize the logical volume
xfs_growfs /dev/mapper/centos/root

# Check free space
df -h

Reference

Reference video:
https://www.youtube.com/watch?v=LT2Hd4UWmOQ

Reference on Stack Overflow
https://stackoverflow.com/a/26320277