Skip to main content

LVM Migration

·685 words·4 mins

This procedure is how to move data from one Physical Volume to another in a LVM configuration on a RHEL based system.

Acronyms #

AcronymMeaning
PVPysical Volume
LVLogical Volume
VGVolume Group

Highlevel Procedure #

  1. Check Current Configuration (Using Multipath/powermt)
  2. Check Space on Existing LUNs and VGs
  3. Configure/Present LUN to server
  4. Scan for LUN on server
  5. Add LUN to PV
  6. Extend VG to include new LUN
  7. Check new LUN and VG have enough space to migrate
  8. Migrate data from one PV to new PV
  9. Remove old PV from VG
  10. Check VG has correct LUNs

Detailed Procedure #

For the example below, it is assumed 3 LUNs will be used and 1 will be updated/swapped.

LUN Presentation #

Confirm LUN is presented to new server from the storage.

LUN Rescan #

Rescan for presented LUNs. Check how many fibre channels are on the system.

[root@server ~]# ls /sys/class/fc_host
host0  host1  host2  host3
Perform rescan on each fc port/host.
[root@server ~]# echo "1" > /sys/class/fc_host/host0/issue_lip
[root@server ~]# echo "- - -" > /sys/class/scsi_host/host0/scan
[root@server ~]# echo "1" > /sys/class/fc_host/host1/issue_lip
[root@server ~]# echo "- - -" > /sys/class/scsi_host/host1/scan
[root@server ~]# echo "1" > /sys/class/fc_host/host2/issue_lip
[root@server ~]# echo "- - -" > /sys/class/scsi_host/host2/scan
[root@server ~]# echo "1" > /sys/class/fc_host/host3/issue_lip
[root@server ~]# echo "- - -" > /sys/class/scsi_host/host3/scan
[root@server ~]# cat /proc/scsi/scsi | egrep -i 'Host:' | wc -l

Restart Multipathd (If Used) #

Restart Multipathd when scan has been completed.

[root@server ~]# service multipathd restart
Check Multipath has new routes for newly presented LUNs and both paths are active.
[root@server ~]# multipath -ll

Rescan Powerpath (If Used) #

Rescan powerpathd

[root@server ~]# powermt config
Check powerpath has new routes for newly presented LUNs and both paths are active.
[root@server ~]# powermt display dev=all

Check Current LUNs #

Check the current LUNs in the VG.

[root@server ~]# pvs
  PV                 VG        Fmt  Attr PSize    PFree
  /dev/mapper/mpatha vg_test01 lvm2 a--  1023.00m       0
  /dev/mapper/mpathb vg_test01 lvm2 a--  1020.00m       0
  /dev/mapper/mpathc vg_test01 lvm2 a--  1020.00m       0

Add New Luns #

If the scan was successful add the new LUNs.

[root@server ~]# pvcreate /dev/mapper/mpathd

Check Current LUNs #

As you can see below it is added, it is not currently assigned to a VG.

[root@server ~]# pvs
  PV                 VG        Fmt  Attr PSize    PFree
  /dev/mapper/mpatha vg_test01 lvm2 a--  1023.00m       0
  /dev/mapper/mpathb vg_test01 lvm2 a--  1020.00m       0
  /dev/mapper/mpathc vg_test01 lvm2 a--  1020.00m       0
  /dev/mapper/mpathd           lvm2 ---  1020.00m 1023.00m

Add PV to VG #

Add newly added PV to VG.

[root@server ~]# vgextend vg_name /dev/mapper/mpathd

Check VG #

Make sure you can see the PV As you can see below it is added, and now it is assigned to a VG. Also you can see the new lun /dev/mapper/mpathd has free space.

[root@server ~]# pvs
  PV                 VG        Fmt  Attr PSize    PFree
  /dev/mapper/mpatha vg_test01 lvm2 a--  1023.00m       0
  /dev/mapper/mpathb vg_test01 lvm2 a--  1020.00m       0
  /dev/mapper/mpathc vg_test01 lvm2 a--  1020.00m       0
  /dev/mapper/mpathd vg_test01 lvm2 a--  1020.00m 1023.00m

Migrate Data #

Now to move the data from an old LUN to the new LUN

[root@server ~]# pvmove /dev/mapper/mpatha /dev/mapper/mpathd
  /dev/mapper/mpatha: Moved: 0.39%
  /dev/mapper/mpatha: Moved: 38.04%
  /dev/mapper/mpatha: Moved: 75.69%
  /dev/mapper/mpatha: Moved: 100.00%

Check VG #

Check the data has moved. You can now see the old lun /dev/mapper/mpatha is now the one with the free space and /dev/mapper/mpathd isn’t 100% free.

[root@server ~]# pvs
  PV                 VG        Fmt  Attr PSize    PFree
  /dev/mapper/mpatha vg_test01 lvm2 a--  1020.00m 1020.00m
  /dev/mapper/mpathb vg_test01 lvm2 a--  1020.00m       0
  /dev/mapper/mpathc vg_test01 lvm2 a--  1020.00m       0
  /dev/mapper/mpathd vg_test01 lvm2 a--  1020.00m       0

Remove Old LUN #

Now remove the old lun from the VG. Make sure this is the LUN with 100% free.

[root@server ~]# vgreduce vg_test01 /dev/mapper/mpatha

Check VG #

Check the old LUN has been disassociated from the VG.

[root@server ~]# pvs
  PV                 VG        Fmt  Attr PSize    PFree
  /dev/mapper/mpatha           lvm2 ---  1023.00m 1023.00m
  /dev/mapper/mpathb vg_test01 lvm2 a--  1020.00m       0
  /dev/mapper/mpathc vg_test01 lvm2 a--  1020.00m       0
  /dev/mapper/mpathd vg_test01 lvm2 a--  1020.00m       0

Remove Old PV #

Remove the old LUN

[root@server ~]# pvremove /dev/mapper/mpatha

Check VG #

Check the old LUN /dev/mapper/mpatha has been removed

[root@server ~]# pvs
  PV                 VG        Fmt  Attr PSize    PFree
  /dev/mapper/mpathb vg_test01 lvm2 a--  1020.00m     0
  /dev/mapper/mpathc vg_test01 lvm2 a--  1020.00m     0
  /dev/mapper/mpathd vg_test01 lvm2 a--  1020.00m     0