Adding an LVM PV on Centos 7.
When you install CentOS 7, choosing automatic partitioning, as shown on the screenshot below, the installer will not create a classic disk storage layout using partitions. By default, CentOS 7 uses the logical volume manager (LVM), that allows to create logical volumes out of one or multiple physical harddisks. LVM volumes can be created on both software RAID partitions and standard partitions. Such volumes can be extended, giving greater flexibility to systems as requirements change. This tutorial shows, how to add a second harddisk to the existing LVM disk storage layout. For details about LVM and the definitions of physical volume (PV), volume group (VG) and logical volume (LV), please have a look at the first paragraphs of my Using LVM disk storage layout on Ubuntu Server tutorial.
In fact, it was a lucky situation for me, that CentOS uses LVM by default. I had configured my VMware virtual machine with one 50 GB harddisk, that would normally be largely enough. However, when I tried to install OnlyOffice, the installer refused to setup the application, because the minimum storage capacity requirement wasn't fulfilled. I added a second harddisk (25 GB) to the VM and asked myself where I could mount this disk in order to make the supplementary storage available to the system and to OnlyOffice in an optimal way. CentOS 7 doesn't include gParted, as do most Linux distributions, but has GNOME Disks, a disk management utility for GNOME. When I used this application to have a look at the storage layout on the first harddisk (screenshot), I realized that there were two partitions: a 1.1 GB EFI partition, needed for UEFI boot (/dev/sda1) and a 53 GB partition of type Linux LVM (the 50 gigabyte harddisk corresponds in fact to a disk of 50 GiB, what's the same than 54 GB). No more need to worry about mount points: Just adding the disk as a second PV to the existing LVM.
There are some useful utilities to view information about LVM: pvdisplay shows information about physical volumes; vgdisplay shows information about volume groups and lvdisplay shows information about logical volumes. On the screenshots below, we can see
- The physical volume /dev/sda2, 49 GB in size, that is part of the LVM group "centos".
- The volume group "centos" that is made from one 49 GB area, and being extendable.
- The logical volume "swap" (LV path: /dev/centos/swap), 4.88 GB in size, and the logical volume "root" (LV path: /dev/centos/root), 45.12 GB in size.
- Create a physical volume.
- Extend the volume group (add the physical volume to the volume group).
- Extend the logical volume.
- Extend the logical volume's filesystem
We will now add the second hard disk to the LVM system in order to extend our root filesystem from actually some 45 GB to 45 + 25 = 70 GB. This is done in 4 steps:
To do the LVM changes, you must, of course, be root. In a terminal, enter su to become the superuser. The creation of the physical volume is
done by the command
pvcreate /dev/sdb
The extension of the volume group "centos", adding the newly created volume, is done by the command
vgextend centos /dev/sdb
The screenshot shows the volume group information after the volume group extension has been done. You can see that the VG now has two areas: 12,542 allocated physical extends (corresponding to the 48.99 GB /dev/sda2) and 6,400 free physical extends (corresponding to the 25 GB /dev/sdb). This is similar to a disk with a 49 GB partition and 25 GB of free (unallocated) space.
A logical volume is similar to a partition in a non-LVM system, we said. Thus, after having extended the volume group "centos", we'll have to extend the logical volume
"root":
lvextend /dev/centos/root −l +6400
When using the lvextend command, we have to specify, beside the name of the logical volume, the size by which the LV has to be extended. This is done here by using the -l option, that needs a physical extend (PE) value as argument (another possibility is to use the -L option, that needs a size value in MB, GB...). The PE value used here (6400) corresponds to the size of the entire free PE available (what actually corresponds to the entire disk /dev/sdb). Do not forget the "+" sign when specifying the size by which the LV has to be extended (as I did; cf. screenshot below).
The screenshot shows the volume group information after the logical volume extension has been done: the VG "centos" is made of two areas, that now, from a logical point of view, form one big area of 12,542 + 6,400 = 18,942 PE, or 48.99 + 25.00 = 73.99 GB. Within this VG, the logical volume "root" will be 45.12 GB + 25 GB = 70.12 GB.
So far done, the space added to the logical volume isn't usable because it hasn't yet been formatted. If you try to extend the filesystem, as on Ubuntu, using the
command:
resize2fs /dev/centos/root
you get the error message "Bad magic number in super-block while trying to open /dev/centos/root. Couldn't find valid filesystem super-block."
In fact, on CentOS, you must not use resize2fs, but the utility xfs_growfs:
xfs_growfs /dev/centos/root
To terminate this tutorial, lets have a look at the "Other Locations" in CentOS filemanager. The location Computer, which corresponds to the root filesystem (the space that we have on the disks for the OS and our application files), is reported to be 75.3 GB. This is equivalent to the 70.12 GB (that actually are 70.12 GiB) of the logical LVM volume "root".
If you find this text helpful, please, support me and this website by signing my guestbook.