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
stunnel How To Set Up an SSL Tunnel Using Stunnel on Ubuntu
Viewed 1835 times since Sun, Dec 6, 2020
RHEL: Force system to prompt for password in Single User mode
Viewed 7475 times since Sat, Jun 2, 2018
Installing and Configuring stunnel on CentOS 6
Viewed 4175 times since Fri, Sep 28, 2018
LVM: Recovering Physical Volume Metadata
Viewed 13209 times since Sat, Jun 2, 2018
Linux - How to get network speed and statistic of ethernet adapter in Linux
Viewed 2241 times since Fri, Jun 8, 2018
stunnel basics and pki standards
Viewed 9542 times since Fri, Sep 28, 2018
ZPOOL: Create a new zpool for zfs filesystems
Viewed 2316 times since Sun, Jun 3, 2018
RHEL: Displaying/setting kernel parameters - ’sysctl’
Viewed 3102 times since Sat, Jun 2, 2018
watchdog How to restart a process out of crontab on a Linux/Unix
Viewed 6102 times since Tue, Jul 31, 2018
stunnel Howto A Guide to create SSL access to a HTTP-only webserver with stunnel
Viewed 2780 times since Fri, Sep 28, 2018