// 顯示所有 LV 使用狀況 #> lvdisplay -C // 新增 LV #> lvcreate -L 10G -n LV_name VG_name // 刪除 LV #> lvremove /dev/VG_name>/LV_name // 更名 LV #> lvrename /dev/VG-name/old-LV-name /dev/VG-name/new-LV-name // 顯示 LV 狀況 #> lvs #> lvs -a -o name,copy_percent,devices #> lvs -a -o name,copy_percent,devices <vg-name> #> lvs -a --segments -o +devices // 擴充 LV 使用空間 #> lvextend -L +2G /dev/vg/lv #> lvextend -l +100%FREE /dev/vg_db2v9/lv_root 將剩餘空間都加上 #> ext2online /dev/vg/lv (RHEL v4) #> resize2fs /dev/vg/lv (RHEL v5,6) #> xfs_growfs /dev/vg/lv (RHEL v7 with XFS filesystem) // 縮小 LV 空間 (RHEL v4) 說明:445GB -> 2GB #> umount /worktmp #> e2fsck -f /dev/rootVG/worktmpLV #> resize2fs /dev/rootVG/worktmpLV 1843M #> lvreduce -L 2GB /dev/rootVG/worktmpLV #> resize2fs /dev/rootVG/worktmpLV #> mount /worktmp 註:1843MB 大約是要 2GB 的 90%,這裡的指令也能使用單位 GB // Shrinking LV (RHEL 5/6) 100 GB -> 5GB #> umount /opt/oracle/arclog #> resize2fs /dev/VolGroup00/arclogLV 5G #> lvreduce -L 5G /dev/VolGroup00/arclogLV #> e2fsck -f /dev/VolGroup00/arclogLV #> mount /opt/oracle/arclog
// 顯示 VG 使用狀況 #> vgdisplay -C // 啟動/關閉 VG #> vgchange -a y VG_name #> vgchange -a n VG_name 註:關閉後,執行 vgdisplay 仍會顯示,但 /dev/*** 已不存在。 // 新建 VG #> vgcreate VG_name /dev/pv1 /dev/pv2 // 更名 VG #> vgrename vg_esxa01db01 vg_root // 刪除 VG #> vgremove VG_name // 增加 PV 到 VG #> vgextend VG_name /dev/pv3 // 從 VG 中移除 PV NOTE: PV 必須沒有任何資料(檢查指令 pvs -o+pv_used) #> vgreduce VG_name /dev/mypv
// 顯示 PV 使用狀況 #> pvdisplay -C // 檢查所有 PV 的空間使用狀況 #> pvs -o+pv_used // 新增 PV #> pvcreate /dev/hdd1 // 刪除 PV #> pvremove /dev/hdd1 // 如果整個 disk 都要作為 PV,該磁碟不能建立任何磁區,要清除舊磁區可以執行 #> dd if=/dev/zero of=/dev/sdd bs=512 count=1
Device /dev/sdj not found (or ignored by filtering).
Ans: 可能該磁碟有包含其他磁區
# 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 - /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.
解決方案: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. # vi /etc/lvm/backup/vg_db
/etc/lvm/backup/vg_db:
... logical_volumes { ... ... } ...
將段落 logical_volumes 整個移除。
# vgcfgrestore vg_db Restored volume group vg_db
重新掃描再重新執行移除 LV 與 VG
# pvs # vgs # lvs # vgremove vg_db
fax:~# 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
解決:
# vgchange -an VolGroup00 # vgchange -ay VolGroup00 # mount -t ext3 /dev/VolGroup00/LogVol00 /mnt/lvm00
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
方法一:使用 Mirror 方式 *建議*
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 作完 Mirrir
#> 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"
Couldn't find device with uuid ZrneWS-8KHd-UiXV-rQ4q-YU0o-r9Ga-0ZVBPW
Ans:這個硬碟可能曾經做過 LVM 格式化,這些是之前遺留的裝置名稱,要清除這些不存在的舊設定,執行
# vgreduce -removemissing <vg-name>
TIPs:
要查出這些不存在的 device 的所屬 VG,可以執行 pvdisplay 。
Images 0 | ||
---|---|---|
No images to display in the gallery. |