FAQ
無法新增 PV
Device /dev/sdj not found (or ignored by filtering).
Solution: 可能該磁碟有包含其他磁區
# fdisk -l /dev/sdj
WARNING: GPT (GUID Partition Table) detected on '/dev/sdj'! The util fdisk doesn't support GPT. Use GNU Parted.
Disk /dev/sdj: 3848.3 GB, 3848290697216 bytes
255 heads, 63 sectors/track, 467861 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sdj1 1 267350 2147483647+ ee GPT
Partition 1 does not start on physical sector boundary.
移除這磁碟裡的所有磁區後再試一次。
無法移除已經損壞 PV 的 VG 與 LV
有一個 PV - /dev/sdc 發生損毀,所屬 VG 與 LV 要移除時遇到錯誤:
Couldn't find device with uuid APgmaN-yCZG-WfQS-L5zm-vd6g-oEJc-WjzNrT.
Can't remove locked LV isths_DMSCouldn't find device with uuid APgmaN-yCZG-WfQS-L5zm-vd6g-oEJc-WjzNrT.
WARNING: Partial LV isths_home needs to be repaired or removed.
WARNING: Partial LV isths_DMS needs to be repaired or removed.
WARNING: Partial LV pvmove0 needs to be repaired or removed.
There are still partial LVs in VG vg_db.
To remove them unconditionally use: vgreduce --removemissing --force.
Proceeding to remove empty missing PVs.
Solution: VG Name: vg_db
# vgcfgbackup vg_db
Couldn't find device with uuid APgmaN-yCZG-WfQS-L5zm-vd6g-oEJc-WjzNrT.
Volume group "vg_db" successfully backed up.
/etc/lvm/backup/vg_db:
...
logical_volumes {
...
...
}
...
將段落 logical_volumes 整個移除。
執行 vgcfgrestore
# vgcfgrestore vg_db
Restored volume group vg_db
重新掃描再重新執行移除 LV 與 VG
pvs
vgs
lvs
vgremove vg_db
使用 USB 掛載包含有 LVM 的硬碟,出現錯誤訊息
# mount -t ext3 /dev/VolGroup00/LogVol00 /mnt/lvm00
mount: wrong fs type, bad option, bad superblock on /dev/mapper/VolGroup00-LogVol00,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so
Solution:
vgchange -an VolGroup00
vgchange -ay VolGroup00
mount -t ext3 /dev/VolGroup00/LogVol00 /mnt/lvm00
移除 PV Disk
從一個現有 LV 中移除正在使用的一個 PV Disk (/dev/sdb1)
NOTE: 這個 LV 的所屬 VG 必須要有足夠的可用空間
# pvs -o+pv_used
PV VG Fmt Attr PSize PFree Used
/dev/sda1 myvg lvm2 a- 17.15G 12.15G 5.00G
/dev/sdb1 myvg lvm2 a- 17.15G 12.15G 5.00G
/dev/sdc1 myvg lvm2 a- 17.15G 12.15G 5.00G
/dev/sdd1 myvg lvm2 a- 17.15G 2.15G 15.00G
# pvmove /dev/sdb1
/dev/sdb1: Moved: 2.0%
...
/dev/sdb1: Moved: 79.2%
...
/dev/sdb1: Moved: 100.0%
# pvs -o+pv_used
PV VG Fmt Attr PSize PFree Used
/dev/sda1 myvg lvm2 a- 17.15G 7.15G 10.00G
/dev/sdb1 myvg lvm2 a- 17.15G 17.15G 0
/dev/sdc1 myvg lvm2 a- 17.15G 12.15G 5.00G
/dev/sdd1 myvg lvm2 a- 17.15G 2.15G 15.00G
# vgreduce myvg /dev/sdb1
Removed "/dev/sdb1" from volume group "myvg"
[root@tng3-1 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda1 myvg lvm2 a- 17.15G 7.15G
/dev/sdb1 lvm2 -- 17.15G 17.15G
/dev/sdc1 myvg lvm2 a- 17.15G 12.15G
/dev/sdd1 myvg lvm2 a- 17.15G 2.15G
搬移 PV Disk
搬移現有 PV Disk (/dev/sdb1) 內的所有資料至一個新的 PV Disk (/dev/sdd1)
方法一:使用 Mirror 方式 *建議*
參考連結:
- https://www.thegeekdiary.com/centos-rhel-7-how-to-create-and-remove-the-lvm-mirrors-using-lvconvert/
- https://linux.m2osw.com/creating-drive-mirror-lvm-including-exact-partition-cloning
說明:
- VG: vg_data
- LV: db_worktmp, lv_mydev, lv_worktmp
- PV: from /dev/sdb1 to /dev/sdc
1. 確認新硬碟的容量需求
#> lvs -a -o name,copy_percent,devices,lv_size vg_data
LV Cpy%Sync Devices LSize
db_worktmp /dev/sdb1(0) 20.00g
lv_mydev /dev/sdb1(5121) 60.00g
lv_mydev /dev/sdb1(10242) 60.00g
lv_worktmp /dev/sdb1(20482) 500.00m
2. 將新硬碟加入到同一個 VG 內
#> vgextend vg_data /dev/sdc
3. 逐一將所有 LV 作完 Mirror
#> lvconvert -m1 vg_data/db_worktmp
#> lvconvert -m1 vg_data/lv_mydev
#> lvconvert -m1 vg_data/lv_worktmp
檢查 Mirror 時的進度
#> lvs -a -o name,copy_percent,devices,lv_size vg_data
4. 逐一將所有 LV 移除 Mirror,需指定舊硬碟代號
#> lvconvert -m0 vg_data/db_worktmp /dev/sdb1
#> lvconvert -m0 vg_data/lv_mydev /dev/sdb1
#> lvconvert -m0 vg_data/lv_worktmp /dev/sdb1
5. 從 VG 裡移除 PV /dev/sdb1, 再移除整個 PV
#> vgreduce vg_data /dev/sdb1
#> pvremove /dev/sdb1
方法二:使用 PV 搬移指令 pvmove
NOTE: PV 必須在同一個 VG 才能互相搬移
# pvs -o+pv_used
PV VG Fmt Attr PSize PFree Used
/dev/sda1 myvg lvm2 a- 17.15G 7.15G 10.00G
/dev/sdb1 myvg lvm2 a- 17.15G 15.15G 2.00G
/dev/sdc1 myvg lvm2 a- 17.15G 15.15G 2.00G
# pvcreate /dev/sdd1
Physical volume "/dev/sdd1" successfully created
# vgextend myvg /dev/sdd1
Volume group "myvg" successfully extended
[root@tng3-1]# pvs -o+pv_used
PV VG Fmt Attr PSize PFree Used
/dev/sda1 myvg lvm2 a- 17.15G 7.15G 10.00G
/dev/sdb1 myvg lvm2 a- 17.15G 15.15G 2.00G
/dev/sdc1 myvg lvm2 a- 17.15G 15.15G 2.00G
/dev/sdd1 myvg lvm2 a- 17.15G 17.15G 0
# pvmove /dev/sdb1 /dev/sdd1
/dev/sdb1: Moved: 10.0%
...
/dev/sdb1: Moved: 79.7%
...
/dev/sdb1: Moved: 100.0%
[root@tng3-1]# pvs -o+pv_used
PV VG Fmt Attr PSize PFree Used
/dev/sda1 myvg lvm2 a- 17.15G 7.15G 10.00G
/dev/sdb1 myvg lvm2 a- 17.15G 17.15G 0
/dev/sdc1 myvg lvm2 a- 17.15G 15.15G 2.00G
/dev/sdd1 myvg lvm2 a- 17.15G 15.15G 2.00G
# vgreduce myvg /dev/sdb1
Removed "/dev/sdb1" from volume group "myvg"
無法新增 LV
系統剛安裝完,執行 pvdisplay -C 出現錯誤,並且無法新增 LV
Couldn't find device with uuid ZrneWS-8KHd-UiXV-rQ4q-YU0o-r9Ga-0ZVBPW
Solution: 這個硬碟可能曾經做過 LVM 格式化,這些是之前遺留的裝置名稱,要清除這些不存在的舊設定。
# vgreduce -removemissing <vg-name>
TIPs:
要查出這些不存在的 device 的所屬 VG,可以執行 pvdisplay 。