Linux Administrator

How To Migrate LVM Data

Some time there might be a issue where your PV (Physical Volume) might be failing and crash and in this situation it is require to replace the PV, so we need to move or migrate the data from such PV to another and isolate the PV.

In this article I will explain how you can migrate or move the LVM data. In my case PV /dev/sda5 has been failed and I want to replace and add a new PV such as /dev/sda6

Migrate The LVM Data

Follow the below steps to complete this task:

1. Check the failed PV data : Check and access the the mount point of the failed PV and check the data.

# cd /mydata/
# ls
file file1 file2 file3

2. Now verify the PV size : You can verify the PV size using below command:

# pvs /dev/sda5
  PV         VG        Fmt  Attr PSize PFree   
  /dev/sda5  look-vg lvm2 a--  2.00g 1020.00m
  #  pvdisplay /dev/sda5
  --- Physical volume ---
  PV Name               /dev/sda5
  VG Name               look-vg
  PV Size               2.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              511
  Free PE               255
  Allocated PE          256
  PV UUID               ccUgnt-N7XK-sa9C-DdVb-gu5l-ddeQ-I9HhVx

3. Unmount the file system : Now unmount the file system using below command:

# umount /mydata/

4. Add a new PV (Physical Volume) : Make sure your new PV should be same size or higher then the replacing PV to VG. In my case PV size is 2GB. I have created one more partition /dev/sda6 using fdisk command with same size 2GB.

# pvs /dev/sda6
  PV         VG   Fmt  Attr PSize PFree
  /dev/sda6       lvm2 ---  2.00g 2.00g

Now extended the VG with new PV partition:

# vgextend lool-vg /dev/sda6
  Volume group "look-vg" successfully extended

5. Move the failed PV data to new PV.

# pvmove /dev/sda5 /dev/sda6
  /dev/sda5: Moved: 0.0%
  /dev/sda5: Moved: 78.5%
  /dev/sda5: Moved: 100.0%

6. Remount LV

Now remount the LV.

# mount -a

7. Verify the data

Now access the mounted directory and check the data:

# cd /mydata/
# ls
file file1 file2 file3

8. Remove the failed PV from VG (Volume Group).

Now remove the failed PV from the VG using below command:

# vgreduce look-vg /dev/sda5
  Removed "/dev/sda5" from volume group "look-vg"

Thanks:)

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment