Smooth Physical Disk Replacement (Upgrade) with LVM While Preserving Data


🤖This article was translated by AI (LLM). There may be errors or inaccuracies. For the original content, please refer to the original version.

Prerequisites

  1. Using LVM
  2. Need to upgrade (replace) hard drive but don’t want to reinstall the system or manually copy data

References: LVM (Simplified Chinese), Removing Disks from a Logical Volume

Preparation

Generally, we need to copy data between the old and new hard drives. Therefore, we need either an SSD enclosure that can hold the old or new SSD, or a portable storage device (USB drive, external hard disk, etc.) with capacity no less than the old SSD that can serve as an LVM volume.

Here, I chose an SSD enclosure because using an external hard drive would require moving data twice, which takes longer.

  • Prepare a live environment (for emergency recovery) and backups (always backup before data operations)
  • LVM identifies devices by their UUID, so we can first install the new SSD, then place the old SSD in the enclosure and connect it to the computer (if you forget to connect the enclosure before booting, GRUB bootloader may be lost - you can enter the live environment to repair the bootloader)
  • Boot the system

Data Migration

LVM supports online operations. Follow the instructions in Removing Disks from a Logical Volume.

Tips: Before loading the LVM volume, it’s recommended to create a partition table (preferably GPT) on the new hard drive to avoid Windows prompting to format the drive. Reason: Does LVM need a partition table?

Postscript

I’m using Arch Linux. In a recent version, LVM caused some hard drives (like my Western Digital Red) in the volume group to fail to mount automatically, entering rescue mode instead.

If LVM enters rescue mode due to mount failure, we can temporarily mount with these commands:

lvm vgchange -ay  # Activate all LVM groups
mount /dev/mapper/YOUR_LVM_NAME /new_root  # Replace YOUR_LVM_NAME with your LVM group name
exit  # Exit rescue mode and enter the system

Manually Compiling Fixed LVM Packages

Getting the Patch

Reference: LVM inactive logical volumes after bootup

Compiling the Patch

After obtaining the patch, enter the folder and compile it.

Reference: Arch User Repository (Simplified Chinese)

Use the command makepkg -si to compile and automatically install the package.

Reboot