Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux LVM 安全移除物理卷 (PV) 完整實戰:縮減邏輯卷、pvchange 離線、pvmove 資料遷移、vgreduce 移除、掛載驗證零資料遺失

編輯:Linux 教學

LVM 文獻多講擴充,鮮少說明如何安全移除某個物理卷 (硬碟/分區)。本文實戰示範:/home 掛載於 7 個 PV 組成的邏輯卷,佔用 2G/2.6G,移除 200M 的 /dev/sda6,全程零資料遺失。

環境與前提

  • 目標 PV 容量 必須小於 邏輯卷剩餘可用空間 (此例 500M 餘裕,移除 200M 符合)。
  • 操作前 必須卸載 檔案系統 (umount /home)。

完整操作流程

  1. 縮減檔案系統:
    e2fsck -f /dev/liuhg_disk/home
    resize2fs /dev/liuhg_disk/home 2200M
    留出 400M 緩衝 (大於目標 PV 200M)。
  2. 縮減邏輯卷:
    lvreduce -L 2200M /dev/liuhg_disk/home
  3. 檢視 PV 分配狀態:
    pvdisplay -m
    確認目標 PV (sda6) 為 Allocated PE 50, Free PE 0 (滿載),需遷移資料。其他 PV (如 sda7) 有 Free PE 76 可接收。
  4. 設定目標 PV 離線 (禁止新配置):
    pvchange -xn /dev/sda6
    Allocatable NO 確認生效。
  5. 遷移資料:
    pvmove -i 1 /dev/sda6
    /dev/sda6: Moved: 38.0%
    /dev/sda6: Moved: 84.0%
    /dev/sda6: Moved: 100.0%
    -i 1 每秒回報進度。完成後 pvdisplay -m 顯示 Free PE 50, Allocated PE 0。
  6. 從卷組移除 PV:
    vgreduce liuhg_disk /dev/sda6
    Removed "/dev/sda6" from volume group "liuhg_disk"
  7. 驗證:
    pvdisplay -m  # 顯示 NEW Physical volume,VG Name 為空
    vgdisplay -v  # 確認無 sda6
    mount /dev/liuhg_disk/home /home
    df -h         # /home 正常掛載,資料完整

關鍵原則:縮減檔案系統 → 縮減邏輯卷 → 離線 PV → 遷移資料 → 移除 PV,每步驟驗證狀態,確保資料零遺失。

Copyright © Windows教程網 All Rights Reserved