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
RHCS6: Luci - the cluster management console
Viewed 2912 times since Sun, Jun 3, 2018
YUM CRON RHEL7: Configure automatic updates.
Viewed 1699 times since Fri, Oct 26, 2018
Using stunnel to Encrypt Database Connections
Viewed 2650 times since Fri, Sep 28, 2018
How to create stunnel with systemd? stunnel
Viewed 8588 times since Thu, Jan 16, 2020
Red Hat Cluster Tutorial
Viewed 1822 times since Sun, Jun 3, 2018
RHEL: XFS basic operations
Viewed 15439 times since Sat, Jun 2, 2018
ZPOOL: Detach a submirror from a mirrored zpool
Viewed 2314 times since Sun, Jun 3, 2018
LVM: Mount LVM Partition(s) in Rescue Mode
Viewed 4388 times since Sat, Jun 2, 2018
Learn how to align an SSD on Linux
Viewed 11726 times since Fri, May 15, 2020
RHEL: Extending a vmdk (Virtual Machine disk)
Viewed 3785 times since Sun, May 27, 2018