Skip to main content

Command Palette

Search for a command to run...

🖥️ Complete Guide: Migrating LVM Physical Volumes Without Downtime

Updated
4 min read

Linux LVM (Logical Volume Manager) is a powerful storage management tool that allows you to create flexible logical volumes on top of physical disks. One of its best features is the ability to migrate data from one disk to another without stopping applications or unmounting filesystems.

In this guide, we’ll go step by step — from creating an initial LVM setup, adding data, and then migrating that data live to a new disk.


🔑 Understanding the Basics

Before diving in, let’s clarify the building blocks:

  • Physical Volume (PV): A physical disk or partition prepared for LVM. Example: /dev/sda1.

  • Volume Group (VG): A pool of storage created from one or more PVs. Example: data_VG.

  • Logical Volume (LV): A flexible “virtual partition” carved from a VG. Example: data_LV.

  • Filesystem (ext4/xfs): The layer that stores your actual files on the LV.

Flow looks like this:

Disk → PV → VG → LV → Filesystem → Mount Point (/data)

🛠️ Step 1: Prepare the First Disk

Assume you have a 5GB disk /dev/sda. First, create a partition for LVM:

fdisk /dev/sda
# create /dev/sda1
# change type to 8e (Linux LVM)
w
partprobe

Now create the PV, VG, and LV:

pvcreate /dev/sda1
vgcreate data_VG /dev/sda1
lvcreate -L 4G -n data_LV data_VG

Format the logical volume with ext4 (or xfs):

mkfs.ext4 /dev/data_VG/data_LV

Create a mount point and mount it:

mkdir /data
mount /dev/data_VG/data_LV /data

🛠️ Step 2: Add Some Data

To verify migration later, let’s add files into /data:

echo "Hello LVM World" > /data/testfile.txt
md5sum /data/testfile.txt   # Save checksum

Now let’s copy a bigger set of files so the migration is meaningful:

cp -r /usr/sbin /data/
cp -r /etc /data/etc_backup

You can check disk usage:

du -sh /data

✅ At this point, your logical volume contains real data.


🛠️ Step 3: Attach a New Disk

Now attach a second 5GB disk /dev/sdb. Partition it:

fdisk /dev/sdb
# create /dev/sdb1
# set type to 8e (Linux LVM)
w
partprobe

Prepare it for LVM:

pvcreate /dev/sdb1

Add it into your volume group:

vgextend data_VG /dev/sdb1

Check status:

pvs
vgs

🛠️ Step 4: Migrate Data Live

Now comes the interesting part: migrating data without downtime.

pvmove -n data_LV /dev/sda1 /dev/sdb1

This command tells LVM to move all extents of the logical volume data_LV from the old PV /dev/sda1 to the new PV /dev/sdb1.

💡 While this runs, you can continue using /data normally (reading/writing files).

To monitor progress:

pvmove -i 10

🛠️ Step 5: Remove Old Disk

Once migration finishes, remove the old disk from the volume group:

vgreduce data_VG /dev/sda1

🛠️ Step 6: Verify Migration

Check logical volume placement:

lsblk

Verify your data is still intact:

md5sum /data/testfile.txt   # Should match the earlier checksum

Also, ensure the copied directories are still present:

ls /data/usr/sbin | head
ls /data/etc_backup | head

🎯 Why This Approach Rocks

  • Zero downtime: Services keep running during migration.

  • Safe upgrades: Replace small/failing disks with bigger ones.

  • Scalable: Add more PVs to expand storage dynamically.

  • Flexible: Easily reorganize data across multiple disks.


⚡ Pro Tips

  • Run pvmove in a screen/tmux session for large migrations

    • Because pvmove can take hours on large disks. If your SSH session disconnects, the command could fail. Running inside screen or tmux keeps it alive.
  • Always ensure the new disk has enough free space

    • Obvious, but critical. If the target PV is smaller than the source, pvmove will fail.
  • Use dmsetup deps if you want to see dependency mappings

    • This shows how logical volumes map to physical devices. It’s helpful if you have multiple disks/PVs and want to confirm relationships.
  • After migration, you can completely remove the old disk from the system

    • Once you vgreduce the old PV and verify everything, you can safely remove it (e.g., detach a VM disk, physically unplug old hardware).

✅ Conclusion

With just a handful of commands, LVM allows you to migrate live data across disks — a feature that makes it invaluable in production environments where uptime is critical.

Next time you need to replace, upgrade, or reorganize storage, remember that pvmove gives you the flexibility to do it without downtime.

👉 In short: LVM makes storage management professional, safe, and future-proof.

More from this blog

Usama Aijaz's blog

22 posts