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
Posted - Sat, Jun 2, 2018 10:21 PM. This article has been viewed 3493 times.
Online URL: http://kb.ictbanking.net/article.php?id=167

Powered by PHPKB (Knowledge Base Software)