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
How To Ping Specific Port Number
Viewed 4157 times since Mon, Jun 1, 2020
Applescript: Run or Call a Shell Script
Viewed 4212 times since Tue, Aug 6, 2019
linux-training.be gives you books for free to study Linux
Viewed 4928 times since Sat, Jun 2, 2018
Linux File Systems (mkfs, mount, fstab) ext4
Viewed 3179 times since Sat, Jun 2, 2018
RHEL: Adding a boot entry to GRUB/GRUB2 configuration
Viewed 4644 times since Sun, May 27, 2018
RHEL: Crash kernel dumps configuration and analysis on RHEL 6
Viewed 4762 times since Sat, Jun 2, 2018
systemd Auto-restart a crashed service in systemd
Viewed 3188 times since Fri, Jan 17, 2020
How to sort IP addresses in Linux
Viewed 3585 times since Sun, May 20, 2018
Odpalenie polecenia tylko na jedną godzinę
Viewed 2832 times since Thu, May 24, 2018
LVM: Create a new Volume Group
Viewed 2078 times since Sat, Jun 2, 2018