Share, , Google Plus, Pinterest,

Print

Posted in:

LVM – Physical Volume Management on CentOS 6

LVM quickly explained:

In computer storage, logical volume management or LVM provides a method of allocating space on mass-storage devices that is more flexible than conventional partitioning schemes. In particular, a volume manager can concatenate, stripe together or otherwise combine partitions into larger virtual ones that administrators can re-size or move, potentially without interrupting system use.

As seen in the LVM design scheme, Physical Volumes (PV) are the bottom layer of LVM. The second layer are Volume Groups (VG) and the final, third layer are Logical Volumes (LV). First we need to add hard drives to Physical Volumes which we next add to Volume Groups. From Volume Groups we create Logical Volumes on which we can create filesystems.

Here is the basic design scheme:

LVM Physical Volumes scheme (source: RedHat.com)
LVM Physical Volumes scheme (source: RedHat.com)

 

Physical Volume Management is a part 1/3 of LVM Management on CentOS!

In this post we will learn how to create, delete and move Physical Volumes (PV). We will learn how to prepare Physical Volume to be added to Volume Groups.

Let’s start our Physical Volume Management on CentOS 6 guide!

For this example we have 3 additional hard drives: /dev/sdb (1GB), /dev/sdc (2GB) and /dev/sdd (3GB). /dev/sda2 is a pre-existing PV on my system that holds the system root and swap partition.

1. Displaying Physical Volumes

We can display all Physical Volumes (PV’s) on the system with the “pvdisplay” command:

[root@foo ~]# pvdisplay
 --- Physical volume ---
 PV Name /dev/sda2
 VG Name vg_foo
 PV Size 14.51 GiB / not usable 3.00 MiB
 Allocatable yes (but full)
 PE Size 4.00 MiB
 Total PE 3714
 Free PE 0
 Allocated PE 3714
 PV UUID 59XWCh-xBOD-rWTe-Mqiu-NP5V-2OES-Enf032

We can also display Physical Volumes with “pvscan” or “pvs” commands, but as we see the output is a bit different – use the one you like the most:

[root@foo ~]# pvscan
 PV /dev/sda2 VG vg_foo lvm2 [14.51 GiB / 0 free]
 Total: 1 [14.51 GiB] / in use: 1 [14.51 GiB] / in no VG: 0 [0 ]
[root@foo ~]# pvs
 PV VG Fmt Attr PSize PFree
 /dev/sda2 vg_foo lvm2 a-- 14.51g 0

 

We see there is currently only one existing PV present. This PV is called /dev/sda2 and is the PV, that holds the system root and swap partition. With the “pvdisplay” command we se additional info – Total PE, Free PE and Allocated PE. This is the Physical Extent. A number of Physical Extents builds the Physical Volume.

2. Adding a hard drive to Physical Volume

We add hard drives to Physical Volumes using “pvcreate /dev/harddisk” command. It is very simple, no additional parameters are needed. Let’s see an example of adding /dev/sdb hard drive to PV:

[root@foo ~]# pvcreate /dev/sdb
 Physical volume "/dev/sdb" successfully created

We can see that Physical Volume was successfully created. Let’s check that again with “pvdisplay”:

[root@foo ~]# pvdisplay
 --- Physical volume ---
 PV Name /dev/sda2
 VG Name vg_foo
 PV Size 14.51 GiB / not usable 3.00 MiB
 Allocatable yes (but full)
 PE Size 4.00 MiB
 Total PE 3714
 Free PE 0
 Allocated PE 3714
 PV UUID 59XWCh-xBOD-rWTe-Mqiu-NP5V-2OES-Enf032
"/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 GtpT2O-B7c2-5VJt-Tk0E-yAU2-6lPN-QcyRYp

As we said, we can also check the PV status with “pvscan” and “pvs” command:

[root@foo ~]# pvscan
 PV /dev/sda2 VG vg_foo lvm2 [14.51 GiB / 0 free]
 PV /dev/sdb lvm2 [1.00 GiB]
 Total: 2 [15.51 GiB] / in use: 1 [14.51 GiB] / in no VG: 1 [1.00 GiB]
[root@foo ~]# pvs
 PV VG Fmt Attr PSize PFree
 /dev/sda2 vg_foo lvm2 a-- 14.51g 0
 /dev/sdb lvm2 a-- 1.00g 1.00g

We see, that /dev/sdb PV was created but it is not allocatable. Running “pvscan” command gives us information that 1GB of space which is in no VG (Volume Group) – this is the reason for not being allocatable.

We will repeat this step for all additional disks:

[root@foo ~]# pvcreate /dev/sdc
 Physical volume "/dev/sdc" successfully created
[root@foo ~]# pvcreate /dev/sdd
 Physical volume "/dev/sdd" successfully created
[root@foo ~]# pvscan
 PV /dev/sda2 VG vg_foo lvm2 [14.51 GiB / 0 free]
 PV /dev/sdb lvm2 [1.00 GiB]
 PV /dev/sdc lvm2 [2.00 GiB]
 PV /dev/sdd lvm2 [3.00 GiB]
 Total: 4 [20.51 GiB] / in use: 1 [14.51 GiB] / in no VG: 3 [6.00 GiB]
[root@foo ~]# pvs
 PV VG Fmt Attr PSize PFree
 /dev/sda2 vg_foo lvm2 a-- 14.51g 0
 /dev/sdb lvm2 a-- 1.00g 1.00g
 /dev/sdc lvm2 a-- 2.00g 2.00g
 /dev/sdd lvm2 a-- 3.00g 3.00g

3. Removing a Physical Volume

We can remove a Physical Volume with “pvremove” command. You should be careful when removing a PV. Make sure that no Physical Extents are allocated on your PV before removing it from the system! You can do this with “pvmove” command.

If you remove a PV with filesystem on it, YOU WILL LOOSE/CORRUPT DATA! I will be covering how to do this in a different post.

[root@foo ~]# pvremove /dev/sdd
 Labels on physical volume "/dev/sdd" successfully wiped
[root@foo ~]# pvscan
 PV /dev/sda2 VG vg_foo lvm2 [14.51 GiB / 0 free]
 PV /dev/sdb lvm2 [1.00 GiB]
 PV /dev/sdc lvm2 [2.00 GiB]
 Total: 3 [17.51 GiB] / in use: 1 [14.51 GiB] / in no VG: 2 [3.00 GiB]
[root@foo ~]# pvremove /dev/sdb
 Labels on physical volume "/dev/sdb" successfully wiped
[root@foo ~]# pvscan
 PV /dev/sda2 VG vg_foo lvm2 [14.51 GiB / 0 free]
 PV /dev/sdc lvm2 [2.00 GiB]
 Total: 2 [16.51 GiB] / in use: 1 [14.51 GiB] / in no VG: 1 [2.00 GiB]
[root@foo ~]# pvremove /dev/sdc
 Labels on physical volume "/dev/sdc" successfully wiped
[root@foo ~]# pvscan
 PV /dev/sda2 VG vg_foo lvm2 [14.51 GiB / 0 free]
 Total: 1 [14.51 GiB] / in use: 1 [14.51 GiB] / in no VG: 0 [0 ]

As we see we succesfully removed all additional Physical Volumes we added.

4. Moving allocated Physical Extents

“pvmove” command allows you to move the allocated physical extents (PEs) on SourcePhysicalVolume to one or more other physical volumes (PVs). This comes handy when you want to remove certain PV but you have to move all of the data away from it.

To move all logical extents of any logical volumes on /dev/sdb to free physical extents elsewhere in the volume group, giving verbose runtime information, use command:

[root@foo ~]# pvmove -v /dev/sdc
 Finding volume group "geekpeek"
 Archiving volume group "geekpeek" metadata (seqno 14).
 Creating logical volume pvmove0
 Moving 129 extents of logical volume geekpeek/LogVol01
 Found volume group "geekpeek"
 activation/volume_list configuration setting not defined: Checking only host tags for geekpeek/LogVol01
 Updating volume group metadata
 Found volume group "geekpeek"
 Found volume group "geekpeek"
 Creating geekpeek-pvmove0
 Loading geekpeek-pvmove0 table (253:3)
 Loading geekpeek-LogVol01 table (253:2)
 Suspending geekpeek-LogVol01 (253:2) with device flush
 Suspending geekpeek-pvmove0 (253:3) with device flush
 Found volume group "geekpeek"
 activation/volume_list configuration setting not defined: Checking only host tags for geekpeek/pvmove0
 Resuming geekpeek-pvmove0 (253:3)
 Found volume group "geekpeek"
 Loading geekpeek-pvmove0 table (253:3)
 Suppressed geekpeek-pvmove0 (253:3) identical table reload.
 Resuming geekpeek-LogVol01 (253:2)
 Creating volume group backup "/etc/lvm/backup/geekpeek" (seqno 15).
 Checking progress before waiting every 15 seconds
 /dev/sdc: Moved: 0.0%
 /dev/sdc: Moved: 78.3%
 /dev/sdc: Moved: 100.0%
 Found volume group "geekpeek"
 Found volume group "geekpeek"
 Loading geekpeek-LogVol01 table (253:2)
 Loading geekpeek-pvmove0 table (253:3)
 Suspending geekpeek-LogVol01 (253:2) with device flush
 Suspending geekpeek-pvmove0 (253:3) with device flush
 Found volume group "geekpeek"
 Resuming geekpeek-pvmove0 (253:3)
 Found volume group "geekpeek"
 Resuming geekpeek-LogVol01 (253:2)
 Found volume group "geekpeek"
 Removing geekpeek-pvmove0 (253:3)
 Removing temporary pvmove LV
 Writing out final volume group after pvmove
 Creating volume group backup "/etc/lvm/backup/geekpeek" (seqno 17).

 

With “pvmove -v /dev/sdc” we moved all of the allocated PE’s from /dev/sdc to another (free) Physical Volume.

Only now we can safely remove the PV (premove) called /dev/sdc from our system.

Share, , Google Plus, Pinterest,

3 Comments

Leave a Reply

5 Pings & Trackbacks

  1. Pingback:

  2. Pingback:

  3. Pingback:

  4. Pingback:

  5. Pingback: