Course contentsShow
← Linux
Lesson 680 of 1,8197. Storage Management and Logical VolumesFree lesson

Migrating filesystems to LVM

Transition traditional partition-based systems to LVM without downtime.

In this lesson, you will learn how to transition a standard partition-based filesystem to a Logical Volume (LVM) without taking your system offline.

The Strategy: Pivot Through Empty Space

Migrating an existing, "live" filesystem—like your /home directory—into LVM usually involves moving data between physical devices. Since we cannot simply "convert" a mounted partition in place, we use the pvmove tool.

The workflow relies on having a "staging area." If you have a second physical disk or an unpartitioned space, you initialize it as a Physical Volume (pvcreate) and add it to your Volume Group (vgextend). Once the new space is available, you use LVM to orchestrate a background migration.

The Migration Process

Imagine you have a filesystem on /dev/sda1 that you want to move into a managed LVM volume. You would perform these steps:

  1. Prepare the new target: Initialize your new, empty disk (/dev/sdb) and add it to the volume group.
    pvcreate /dev/sdb
    vgextend my_vg /dev/sdb
    
  2. Create a target Logical Volume: Create a new LV inside your Volume Group that is at least as large as the data currently on your old partition.
  3. Sync the data: Use rsync to mirror the contents of the old partition to the new LV while the system is running:
    rsync -avx /old/mount/ /new/lv/mount/
    
  4. The Cutover: Once the data is synced, you perform a brief remount. Update your /etc/fstab to point to the new /dev/my_vg/my_lv path, unmount the old partition, and mount the new LV in its place.

Why Use This Approach?

By using rsync to populate the new volume while the original is still mounted, you keep your services accessible. You are essentially creating a clone. If something goes wrong during the final mount, the original data on the physical partition remains untouched and ready to be remounted instantly, providing a safety net for your production storage.

Key Takeaway: Migrating to LVM is safely achieved by provisioning new storage as an LVM volume, syncing live data via rsync, and performing a final fstab update to switch the mount point to the logical volume.