如何替换含数据的预测错误坏磁盘(含5PV的VG场景)
Got it, let's break down exactly how to replace that problematic PV (throwing predictive failure alerts) in your 5-PV volume group. This is a common scenario, and as long as you follow the steps carefully, you can pull this off without data loss.
Step 1: Identify the Failing PV & Verify Your Setup
First, you need to pinpoint the bad disk and confirm your VG/LV health:
- Run
pvsto list all physical volumes—look for flags likefailedor cross-reference with system logs (checkdmesgorsmartctloutput) to find the disk with predictive errors. - Use
vgsto check your volume group's free space: you’ll need enough free physical extents (PE) on the remaining 4 healthy PVs to hold all data from the failing disk. - Run
lvdisplayto see how your logical volumes are spread across the PVs—this helps you confirm there’s no dependency tied exclusively to the bad disk.
Step 2: Migrate Data Off the Failing PV
Once you’ve confirmed the failing PV (let’s say it’s /dev/sdX), use pvmove to transfer all its data to the other healthy PVs:
pvmove /dev/sdX
- This command automatically distributes the data to free space on the remaining PVs. If you want to target a specific healthy PV (e.g.,
/dev/sdZ), runpvmove /dev/sdX /dev/sdZinstead. - If the migration gets interrupted, you can resume it with
pvmove --resumeor abort cleanly withpvmove --abort.
Step 3: Remove the Failing PV from the VG
After the data migration finishes successfully, detach the bad PV from your volume group (replace myvg with your actual VG name):
vgreduce myvg /dev/sdX
- Double-check with
pvsto make sure/dev/sdXis no longer linked to the VG.
Step 4: Physically Swap the Disk
Power down your system (or use hot-swap if your hardware supports it), pull out the failing disk, and insert the new replacement drive.
Step 5: Initialize the New Disk as a PV
Once the system recognizes the new disk (use lsblk or fdisk -l to get its device name, e.g., /dev/sdY), set it up as a physical volume:
pvcreate /dev/sdY
- If the new disk has old partitions, wipe them first with
dd if=/dev/zero of=/dev/sdY bs=1M count=10(warning: this erases all data on the disk—be sure you’re targeting the right device!).
Step 6: Add the New PV to the VG
Extend your volume group to include the fresh PV:
vgextend myvg /dev/sdY
Step 7: Verify Everything’s Working
Wrap up by confirming the setup is healthy:
- Run
pvsto see the new PV listed under your VG with available space. - Use
vgsto check that the VG’s total size matches the sum of all 5 PVs (now with the new disk replacing the old one). - For file systems on your logical volumes, run a integrity check:
e2fsck /dev/myvg/mylvfor ext4, orxfs_check /dev/myvg/mylvfor XFS.
Quick Pro Tips
- Backup First: Even though
pvmoveis reliable, always back up critical data before messing with disk replacements—better safe than sorry. - Low Traffic Time: Run the
pvmoveprocess during a quiet period; it’s resource-heavy and can slow down your system if done during peak usage. - Monitor Progress: Keep an eye on the migration with
pvsorvgs—large datasets can take a while to transfer.
内容的提问来源于stack exchange,提问作者Franklin Kabiladhas

