🌐 🇵🇱 Polski · 🇬🇧 EN
Assuming you have an old and failing disk that needs to be replaced in the system, how can you move the data to a new one? In a system with standard partitions, you can copy all data from one disk to another, provided the disk is offline (otherwise, files might be locked). Working with LVM is much easier because you can migrate data while the disk is "online" without disrupting operations. This capability is very useful, especially when a disk replacement is necessary. So, if you need to replace the disk /dev/hdb because something happened to it, you can use the "pvmove" command to move data from its physical location—where the data actually resides—to another physical volume, e.g., /dev/hdc.
Assuming we are adding a new disk and want to migrate the data, the entire process will follow these steps:
Step 1 - Check which physical volumes are inside the volume group
Using volume group(s) on command line
Finding volume group “vg_group01”
-- Volume group --
VG Name vg_group01
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 14
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 15.99 GiB
PE Size 4.00 MiB
Total PE 4094
Alloc PE / Size 1750 / 6.84 GiB
Free PE / Size 2344 / 9.16 GiB
VG UUID IvjXga-898Y-1vCC-azRt-pszL-PeWR-E5athz
-- Logical volume --
VG Name vg_group01
LV UUID mk9dJM-3qt7-ypbC-nsks-I8Gh-9V3d-4BNE6s
LV Write Access read/write
LV Status available
# open 0
LV Size 1.95 GiB
Current LE 500
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
-- Physical volumes --
PV Name /dev/sdb
PV UUID B0K2qH-0UF4-gphE-MLi3-RFXH-HEP9-9FMbA9
PV Status allocatable
Total PE / Free PE 2047 / 297
Step 2 - Extend the volume group with the new disk
# vgextend vg_group01 /dev/sdc
Volume group “vg_group01” successfully extended
Step 3 - Create a logical volume to store the migrated data
# lvcreate -L 5000 vg_group01
Logical volume “lvol0” created
Step 4 - Check the changes made to the logical volumes
# lvdisplay vg_group01
-- Logical volume --
LV Name /dev/vg_group01/SecretData
VG Name vg_group01
LV UUID mk9dJM-3qt7-ypbC-nsks-I8Gh-9V3d-4BNE6s
LV Write Access read/write
LV Status available
# open 0
LV Size 1.95 GiB
Current LE 500
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
-- Logical volume --
LV Name /dev/vg_group01/lvol0
VG Name vg_group01
LV UUID 6vsP79-Gu7W-PO4p-tCHg-OMqN-W8QN-QAIrhH
LV Write Access read/write
LV Status available
# open 0
LV Size 4.88 GiB
Current LE 1250
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:3
Step 5 - We can also verify if we now have two physical disks in the volume group.
# vgdisplay -v vg_group01
Using volume group(s) on command line
Finding volume group “vg_group01”
-- Volume group --
VG Name vg_group01
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 14
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 15.99 GiB
PE Size 4.00 MiB
Total PE 4094
Alloc PE / Size 1750 / 6.84 GiB
Free PE / Size 2344 / 9.16 GiB
VG UUID IvjXga-898Y-1vCC-azRt-pszL-PeWR-E5athz
-- Logical volume --
LV Name /dev/vg_group01/SecretData
VG Name vg_group01
LV UUID mk9dJM-3qt7-ypbC-nsks-I8Gh-9V3d-4BNE6s
LV Write Access read/write
LV Status available
# open 0
LV Size 1.95 GiB
Current LE 500
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
-- Logical volume --
LV Name /dev/vg_group01/lvol0
VG Name vg_group01
LV UUID 6vsP79-Gu7W-PO4p-tCHg-OMqN-W8QN-QAIrhH
LV Write Access read/write
LV Status available
# open 0
LV Size 4.88 GiB
Current LE 1250
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:3
-- Physical volumes --
PV Name /dev/sdb
PV UUID B0K2qH-0UF4-gphE-MLi3-RFXH-HEP9-9FMbA9
PV Status allocatable
Total PE / Free PE 2047 / 297
PV Name /dev/sdc
PV UUID Wn52Tv-ZEJR-IkYb-2oi1-5Iw7-2oN7-wHihl4
PV Status allocatable
Total PE / Free PE 2047 / 2047
Step 6 - Migrate data from the failing disk to the new one
# pvmove /dev/hdb /dev/hdc
/dev/sdb: Moved: 0.2%
/dev/sdb: Moved: 7.0%
/dev/sdb: Moved: 13.7%
/dev/sdb: Moved: 20.2%
/dev/sdb: Moved: 26.9%
/dev/sdb: Moved: 28.6%
/dev/sdb: Moved: 35.4%
/dev/sdb: Moved: 40.8%
/dev/sdb: Moved: 47.2%
/dev/sdb: Moved: 53.9%
/dev/sdb: Moved: 60.4%
/dev/sdb: Moved: 67.0%
/dev/sdb: Moved: 73.7%
/dev/sdb: Moved: 80.4%
/dev/sdb: Moved: 87.0%
/dev/sdb: Moved: 93.8%
/dev/sdb: Moved: 100.0%
Step 7 - Verify that the physical volume is empty
# pvdisplay /dev/hdb
-- Physical volume --
PV Name /dev/sdb
VG Name vg_group01
PV Size 8.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2047
Free PE 2047
Allocated PE 0
PV UUID B0K2qH-0UF4-gphE-MLi3-RFXH-HEP9-9FMbA9
Data migrated!
Comments