In this lesson, you will learn how to migrate data from a failing physical disk to a healthy one without ever taking your system offline, using the LVM tool pvmove.
The Challenge of Failing Hardware
In previous lessons, we discussed how Logical Volume Manager (LVM) abstracts your physical drives into a flexible pool of storage. This abstraction provides a massive advantage when a drive begins to show signs of failure: you don't have to copy files manually or unmount partitions. Instead, you can ask LVM to physically relocate the data blocks from the "bad" disk to a "good" one while your applications are still running.
Migrating Data with pvmove
The pvmove command acts as a background "mover," shuffling the extents (the chunks of data) that make up your logical volumes. Because LVM manages these extents, it knows exactly which parts of your filesystem live on which drive.
To perform an online migration, follow these steps:
-
Add the new disk: Ensure the new physical disk is initialized as a physical volume (PV) and added to your existing Volume Group (VG).
pvcreate /dev/sdb vgextend my_volume_group /dev/sdb -
Move the data: Use
pvmoveto shift data from the old disk (/dev/sda) to the new one (/dev/sdb).pvmove /dev/sda /dev/sdb
LVM will begin copying the data block-by-block in the background. You can monitor the progress by simply running lvs -a -o +devices. Once the command completes, the old disk will be empty of any data belonging to that volume group.
- Cleanup: After the data is safely moved, you can remove the old disk from the volume group:
vgreduce my_volume_group /dev/sda
This process is entirely transparent to your users and running services. Even if the disk is failing, LVM attempts to read the blocks in sequence, allowing you to migrate your data before the drive becomes completely unreachable.
Key Takeaway: The pvmove command leverages LVM’s abstraction to migrate data between physical disks online, ensuring zero downtime even when replacing failing hardware.