LVM: Move allocated PE between Physical Volumes

LVM: Move allocated PE between Physical Volumes

# Tested on RHEL 5.2


# I need to free up and remove /dev/sdc disk from my system. As it makes part of "datavg"
# Volume Group, and since it is not 100% free, I'll need to move the data from to another
# disk first.
# For that, I've added a new disk, /dev/sdd, to transfer all the allocated extents from
# /dev/sdc

pvs
   PV         VG         Fmt    Attr  PSize   PFree
   /dev/sda2  rootvg     lvm2   a-    11.72G  864.00M
   /dev/sdb   datavg     lvm2   a-    30.00G       0
   /dev/sdc   datavg     lvm2   a-     5.00G    2.97G           <---- In use
   /dev/sdd   datavg     lvm2   a-    15.00G   15.00G
           <---- Free


# 'pvdisplay' command used with '-m' option shows the mapping of physical extents to logical
# volumes that are spread across my disk. These are the physical extents that I will transfer
# to the new disk

pvdisplay -m /dev/sdc
  --- Physical volume ---
  PV Name               /dev/sdc
  VG Name               datavg
  PV Size               5.00 GB / not usable 3.81 MB
  Allocatable           yes
  PE Size (KByte)       4096
  Total PE              1279
  Free PE               761
  Allocated PE          518
  PV UUID               8JS7oV-6SYK-dQX9-1X24-oxG6-GBEO-Zh9Gce

  --- Physical Segments ---
  Physical extent 0 to 286:
    Logical volume      /dev/datavg/lvData
    Logical extents     4703 to 4989
  Physical extent 287 to 517:
    Logical volume      /dev/datavg/lvApp
    Logical extents     762 to 992
  Physical extent 518 to 1278:
    FREE


# If there is sufficient space in destination disk, it will be enough to run 'pvmove'
# command indicating both origin and destination disk like this:
# ('-i' reports the progress of the move at five second intervals)

pvmove -i5 /dev/sdc /dev/sdd
  /dev/sdc: Moved: 10.4%
  /dev/sdc: Moved: 21.4%
  /dev/sdc: Moved: 32.6%
  /dev/sdc: Moved: 43.6%
  /dev/sdc: Moved: 44.6%
  /dev/sdc: Moved: 54.2%
  /dev/sdc: Moved: 64.1%
  /dev/sdc: Moved: 73.9%
  /dev/sdc: Moved: 84.0%
  /dev/sdc: Moved: 93.8%
  /dev/sdc: Moved: 100.0%


# Once operation done, we can see that /dev/sdc is 100% free and that the number of PFree
# on /dev/sdd has been reduced

pvs
   PV         VG         Fmt    Attr  PSize   PFree
   /dev/sda2  rootvg     lvm2   a-    11.72G  864.00M
   /dev/sdb   datavg     lvm2   a-    30.00G       0
   /dev/sdc   datavg     lvm2   a-     5.00G    5.00G
           <---- Free
   /dev/sdd   datavg     lvm2   a-    15.00G   12.97G           <---- In use


# Now all the Physical Extents of /dev/sdc are free. The allocated ones have been
# transferred to /dev/sdd

pvdisplay -m /dev/sdc
  --- Physical volume ---
  PV Name               /dev/sdc
  VG Name               datavg
  PV Size               5.00 GB / not usable 3.81 MB
  Allocatable           yes
  PE Size (KByte)       4096
  Total PE              1279
  Free PE               1279
  Allocated PE          0
  PV UUID               8JS7oV-6SYK-dQX9-1XMO-oxG6-GBEO-Zh9Gce

  --- Physical Segments ---
  Physical extent 0 to 1278:
    FREE


pvdisplay -m /dev/sdd
  --- Physical volume ---
  PV Name               /dev/sdd
  VG Name               datavg
  PV Size               15.00 GB / not usable 4.00 MB
  Allocatable           yes
  PE Size (KByte)       4096
  Total PE              3839
  Free PE               3321
  Allocated PE          518
  PV UUID               9Rsa40-n4I2-l3m5-sEH4-VDNX-AqYl-Gj9euZ

  --- Physical Segments ---
  Physical extent 0 to 230:
    Logical volume      /dev/datavg/lvApp
    Logical extents     762 to 992
  Physical extent 231 to 517:
    Logical volume      /dev/datavg/lvData
    Logical extents     4703 to 4989
  Physical extent 518 to 3838:
    FREE


# Everything is ready for removing the disk ('vgreduce', 'pvremove', etc,..)



# ------------------------------------------------------------------------------------------

# 'pvmove' supports also following options:

# No destination disk specified: Move all allocated space off the physical volume to other
# free physical volumes in the volume group, if any:

pvmove /dev/sdc


# Move just the extents of the specified logical volume (See 'pvdisplay -m' here before) to
# other free physical volumes in the volume group:

pvmove -n lvData /dev/sdc


# Run the command in the background, '-b':

pvmove -b /dev/sdc /dev/sdd
0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
Using Kerberos security with Server for NFS
Viewed 9523 times since Wed, Jun 27, 2018
Linux - Cannot login from remote console but can access via ssh
Viewed 5024 times since Fri, Jun 8, 2018
Linux Screen
Viewed 1967 times since Sat, Jun 2, 2018
How To: Create Self-Signed Certificate – OpenSSL
Viewed 2904 times since Mon, Feb 18, 2019
Exclude multiple files and directories with rsync
Viewed 2420 times since Wed, Oct 31, 2018
Understanding System auditing with auditd
Viewed 9645 times since Fri, Apr 5, 2019
linux ssh How to Hide the OpenSSH Version Details when Telnet to Port 22
Viewed 4704 times since Wed, Apr 22, 2020
Using etckeeper with git
Viewed 6774 times since Sun, Jun 3, 2018
How to disable SSH cipher/ MAC algorithms for Linux and Unix
Viewed 46003 times since Fri, Aug 21, 2020
7 Tips – Tuning Command Line History in Bash
Viewed 5239 times since Fri, Jul 5, 2019