How to extend the size of a Linux LVM by adding a new disk
LVM stands for Logical Volume Management. It is a system of managing logical volumes, or filesystems, that is much more advanced and flexible than the traditional method of partitioning a disk into one or more segments and formatting that partition with a filesystem
In this example, we will extend one LVM partition for 120GB which is the size of the newly added hard disk. Before any ‘gameplay’ with the disk, the recommendation is to make data backup first.
First, let’s check current spaces in the system by using command df -h and filesystem used under LVM partition which we want to extend (in our case is ext4) by using command mount | grep <<fajlsistem>>
Situation before adding new disk we check with command fdisk -l
We added a new disk – and here is how it looks like in fdisk now. Please notice the newly added disk with 120G of space. We don’t see any partition bellow (like /dev/sdb1).
Follow the instructions below. We start with disk partitioning by command fdisk /dev/sdb
Be careful, after this step – there is no back.
After adding disk we can continue with LVM extend process.
# pvcreate <<newly created partition>>, or in our case pvcreate /dev/sdb1 # Listing of curent volume group. # We will use later VG Name - so remember it somewhere (or copy-paste) vgdisplay # vgextend <<VG Name>> <<newly created partition>>, or in our case vgextend cl_centos7 /dev/sdb1 # Scanning for psychical volumes (please notice our with 120GB) pvscan # Listing of logical volumes. # We want to extend this with name root and important info for us is LV path lvdisplay # Logical volume extending # lvextend <<LV path>> <<newly created partition>>, or in our case lvextend /dev/cl_centos7/root /dev/sdb1 # Logical volume extending for free space which we added by new disk # resize2fs <<LV path>>, or in our case resize2fs /dev/cl_centos7/root # If you use xfs please use xfs_growfs instead of resize2fs
New check the space by command df -h. Instead of initial 77GB of root partition now we see 195GB.