How to create a physical volume in Linux using LVM
Physical volumes (
PV) are the base "block" that you need in order to manipulate a disk using Logical Volume Manager (
Now, let’s not rush ahead. What exactly is a physical volume? What in the world is LVM?
In short, LVM is a type of storage virtualization that allows operators far more flexibility in storage management than standard partitioning. A physical volume is any physical storage device, such as a Hard Disk Drive (
HDD), Solid State Drive (
SSD), or partition, that has been initialized as a physical volume with LVM. Without properly initialized physical volumes, you cannot create Volume Groups or logical volumes.
So let's get started! First, there are a few considerations.
Don't try to pinpoint the exact amount of space you need down to the nearest byte. The reason for this is that LVM places labels on the physical volumes'
UUID, as well as metadata storage. While this doesn't take up very much space, understand that if you initialize a 1Gb PV, you do not have 1Gb of usable space.
Also, although LVM allows you to create physical volumes using multiple partitions, it is recommended that you use a single partition for a PV. This is for a couple of reasons—single partitions are easier to track for sysadmins, and you will experience better Striping performance. For more info on this, see Red Hat Documentation.
Initializing physical volumes
So, now that we have considered our options, let’s look at the actual initialization process. It is always good practice to see what physical volumes you already have configured on your system. To do this, use the
pvs command. You should get something similar to this:
[root@rhel ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 rhel lvm2 a-- <29.00g 0
Here we can see that my VM only has a single physical volume
/dev/sda2 that is 29.00Gb. Let's create two additional PVs at 1Gb to demonstrate the process:
[root@rhel ~]# pvcreate /dev/sdb /dev/sdc Physical volume "/dev/sdb" successfully created. Physical volume "/dev/sdc" successfully created.
You can verify the creation worked using the
[root@rhel ~] # pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name rhel PV Size <29.00 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 7423 Free PE 0 Allocated PE 7423 PV UUID q9VFt3-YR0m-XATY-BADn-Vbnb-PVl5-9wIAhd "/dev/sdb" is a new physical volume of "1.00 GiB" --- NEW Physical volume --- PV Name /dev/sdb VG Name PV Size 1.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID 3MHooU-799T-xe8q-24Jk-MMdc-pkhF-Tnqpbg "/dev/sdc" is a new physical volume of "1.00 GiB" --- NEW Physical volume --- PV Name /dev/sdc VG Name PV Size 1.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID ydegao-MGb8-X5Mc-VuLp-JnFH-vmx9-rYa9wQ>
However, I find that in most use cases, the
pvs command is much more reader-friendly:
[root@rhel ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 rhel lvm2 a-- <29.00g 0 /dev/sdb lvm2 --- 1.00g 1.00g /dev/sdc lvm2 --- 1.00g 1.00g>
Wrap up and troubleshooting
If you were able to follow those steps successfully, congratulations on initializing a physical volume! If not, be sure that your new drives or partitions are formatted but NOT mounted prior to using the
pvcreate command. Otherwise, you will see the following error:
[root@rhel ~]# pvcreate /dev/sdb /dev/sdc Can't open /dev/sdb exclusively. Mounted filesystem? Can't open /dev/sdc exclusively. Mounted filesystem?
I hope that this quick look at physical drive creation was helpful. Next, I recommend that you try creating a volume group using
vgcreate. More on that in a future article!
[ Free online course: Red Hat Enterprise Linux technical overview. ]