1 名詞解釋
磁盤或者分區(qū)可以創(chuàng)建成pv(物理卷)舌劳,一個(gè)或多個(gè)pv可以組成vg(卷組)宫补,vg可以劃分成lv(邏輯卷)提供使用
lv分為thick 和 thin類型只壳,thick會(huì)立即從vg分配所有空間饵筑,thin類型的實(shí)際占用空間會(huì)根據(jù)數(shù)據(jù)量增加而增加
2 LVM資源管理
2.1 查看系統(tǒng)disk
root@vtela:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
└─sda1 8:1 0 20G 0 part /
sdb 8:16 0 5G 0 disk
sdc 8:32 0 3G 0 disk
sr0 11:0 1 1024M 0 rom
sdb和sdc可以用來做pv
2.2 PV
2.2.1 創(chuàng)建
創(chuàng)建pv
root@vtela:~# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.
查看pv(有兩個(gè)命令可以查看,剩下的內(nèi)容以簡(jiǎn)單的pvs雷恃,lvs等展示)
root@vtela:~# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb lvm2 --- 5.00g 5.00g
root@vtela:~# pvdisplay
"/dev/sdb" is a new physical volume of "5.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb
VG Name
PV Size 5.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID OZ7y5s-VlqF-dbxn-k0yp-R1Fm-BKNW-EmBM5R
2.2.2 刪除
root@vtela:~# pvremove /dev/sdb
Labels on physical volume "/dev/sdb" successfully wiped.
root@vtela:~# pvs
root@vtela:~#
2.3 VG
2.3.1 創(chuàng)建
2.3.1.1 直接使用disk或part創(chuàng)建
不用提前創(chuàng)建pv疆股,直接創(chuàng)建vg,vg0是名字倒槐,創(chuàng)建vg成功之后可以看到提示創(chuàng)建了pv和vg
root@vtela:~# pvs
root@vtela:~#
root@vtela:~# vgcreate vg0 /dev/sdb
Physical volume "/dev/sdb" successfully created.
Volume group "vg0" successfully created
root@vtela:~# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb vg0 lvm2 a-- <5.00g <5.00g
root@vtela:~# vgs
VG #PV #LV #SN Attr VSize VFree
vg0 1 0 0 wz--n- <5.00g <5.00g
2.3.1.2 使用pv創(chuàng)建
root@vtela:~# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb lvm2 --- 5.00g 5.00g
root@vtela:~# vgcreate vg0 /dev/sdb
Volume group "vg0" successfully created
2.3.1.3 一次性使用多個(gè)設(shè)備創(chuàng)建
root@vtela:~# vgcreate vg1 /dev/sdb /dev/sdc
Volume group "vg1" successfully created
root@vtela:~# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 2 0 0 wz--n- 7.99g 7.99g
root@vtela:~# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb vg1 lvm2 a-- <5.00g <5.00g
/dev/sdc vg1 lvm2 a-- <3.00g <3.00g
2.3.2 擴(kuò)展
加入新的pv增大容量旬痹,也可直接使用未創(chuàng)建pv的設(shè)備來擴(kuò)展
root@vtela:~# vgs
VG #PV #LV #SN Attr VSize VFree
vg0 1 0 0 wz--n- <5.00g <5.00g
root@vtela:~#
root@vtela:~# vgextend vg0 /dev/sdc
Physical volume "/dev/sdc" successfully created.
Volume group "vg0" successfully extended
root@vtela:~#
root@vtela:~#
root@vtela:~# vgs
VG #PV #LV #SN Attr VSize VFree
vg0 2 0 0 wz--n- 7.99g 7.99g
root@vtela:~#
root@vtela:~# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb vg0 lvm2 a-- <5.00g <5.00g
/dev/sdc vg0 lvm2 a-- <3.00g <3.00g
root@vtela:~#
2.3.3 縮小
即把某個(gè)pv從vg里面切割掉
root@vtela:~# vgs
VG #PV #LV #SN Attr VSize VFree
vg0 2 0 0 wz--n- 7.99g 7.99g
root@vtela:~#
root@vtela:~# vgreduce vg0 /dev/sdc
Removed "/dev/sdc" from volume group "vg0"
root@vtela:~#
root@vtela:~# vgs
VG #PV #LV #SN Attr VSize VFree
vg0 1 0 0 wz--n- <5.00g <5.00g
root@vtela:~#
root@vtela:~#
2.3.4 重命名
root@vtela:~# vgrename vg0 vg1
Volume group "vg0" successfully renamed to "vg1"
root@vtela:~# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 1 0 0 wz--n- <5.00g <5.00g
2.4 LV
2.4.1 Thick 類型
2.4.1.1 創(chuàng)建
不指定lv name,會(huì)分配名字
root@vtela:~# lvcreate -L 1g vg1
Logical volume "lvol0" created.
指定lv name
root@vtela:~# lvcreate -L 1g -n lv1 vg1
Logical volume "lv1" created.
root@vtela:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-a----- 1.00g
lvol0 vg1 -wi-a----- 1.00g
2.4.1.2 resize
可以增大或減少容量,注意需要指定完整的lv路徑,因?yàn)椴煌膙g可以創(chuàng)建名字相同的lv
root@vtela:~# lvresize -L +1g /dev/vg1/lv1
Size of logical volume vg1/lv1 changed from 1.00 GiB (256 extents) to 2.00 GiB (512 extents).
Logical volume vg1/lv1 successfully resized.
root@vtela:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-a----- 2.00g
lv2 vg1 -wi-a----- 40.00m
lv3 vg1 -wi-a----- 40.00m
lvol0 vg1 -wi-a----- 1.00g
root@vtela:~# lvresize -L -1g /dev/vg1/lv1
WARNING: Reducing active logical volume to 1.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg1/lv1? [y/n]: y
Size of logical volume vg1/lv1 changed from 2.00 GiB (512 extents) to 1.00 GiB (256 extents).
Logical volume vg1/lv1 successfully resized.
root@vtela:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-a----- 1.00g
lv2 vg1 -wi-a----- 40.00m
lv3 vg1 -wi-a----- 40.00m
lvol0 vg1 -wi-a----- 1.00g
root@vtela:~#
2.4.1.3 刪除
root@vtela:~# lvremove /dev/vg1/lv1
Do you really want to remove and DISCARD active logical volume vg1/lv1? [y/n]: y
Logical volume "lv1" successfully removed
加上-f是強(qiáng)制刪除
root@vtela:~# lvremove -f /dev/vg1/lv2
Logical volume "lv2" successfully removed
2.4.1.4 重命名
lv4是新名字
root@vtela:~# lvrename vg1 lv3 lv4
Renamed "lv3" to "lv4" in volume group "vg1"
2.4.2 Thin類型
創(chuàng)建thin lv需要先創(chuàng)建一個(gè)thin pool击碗,這個(gè)thin pool也是LINSTOR lvmthin 類型的存儲(chǔ)池的backend storage
2.4.2.1 創(chuàng)建thinpool
thinpool其實(shí)也是個(gè)特殊的lv,不能超過vg的容量
root@vtela:~# lvcreate -T -L 7g vg1/thinpool1
Using default stripesize 64.00 KiB.
Thin pool volume with chunk size 64.00 KiB can address at most 15.81 TiB of data.
Logical volume "thinpool1" created.
root@vtela:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
thinpool1 vg1 twi-a-tz-- 7.00g 0.00 10.74
root@vtela:~# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 2 1 0 wz--n- 7.99g 1000.00m
2.4.2.2 創(chuàng)建thin lv
thin lv可以超過thinpool的容量人弓,后續(xù)可以通過擴(kuò)展vg,thinpool來擴(kuò)展thin lv真正能使用的空間
root@vtela:~# lvcreate -V 100G -n thinlv1 -T vg1/thinpool1
Using default stripesize 64.00 KiB.
WARNING: Sum of all thin volume sizes (100.00 GiB) exceeds the size of thin pool vg1/thinpool1 and the size of whole volume group (7.99 GiB).
WARNING: You have not turned on protection against thin pools running out of space.
WARNING: Set activation/thin_pool_autoextend_threshold below 100 to trigger automatic extension of thin pools before they get full.
Logical volume "thinlv1" created.
root@vtela:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
thinlv1 vg1 Vwi-a-tz-- 100.00g thinpool1 0.00
thinpool1 vg1 twi-aotz-- 7.00g 0.00 10.79
root@vtela:~#
2.4.2.3 resize thinpool
只能擴(kuò)展不能減少
root@vtela:~# lvresize -L -1g /dev/vg1/thinpool1
Thin pool volumes vg1/thinpool1_tdata cannot be reduced in size yet.
root@vtela:~# lvresize -L +500m /dev/vg1/thinpool1
WARNING: Sum of all thin volume sizes (100.00 GiB) exceeds the size of thin pools and the size of whole volume group (7.99 GiB).
WARNING: You have not turned on protection against thin pools running out of space.
WARNING: Set activation/thin_pool_autoextend_threshold below 100 to trigger automatic extension of thin pools before they get full.
Size of logical volume vg1/thinpool1_tdata changed from 7.00 GiB (1792 extents) to <7.49 GiB (1917 extents).
Logical volume vg1/thinpool1_tdata successfully resized.
root@vtela:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
thinlv1 vg1 Vwi-a-tz-- 100.00g thinpool1 0.00
thinpool1 vg1 twi-aotz-- <7.49g 0.00 10.79
2.4.2.4 resize thinlv
root@vtela:~# lvresize -L +500m /dev/vg1/thinlv1
WARNING: Sum of all thin volume sizes (<100.49 GiB) exceeds the size of thin pool vg1/thinpool1 and the size of whole volume group (7.99 GiB).
WARNING: You have not turned on protection against thin pools running out of space.
WARNING: Set activation/thin_pool_autoextend_threshold below 100 to trigger automatic extension of thin pools before they get full.
Size of logical volume vg1/thinlv1 changed from 100.00 GiB (25600 extents) to <100.49 GiB (25725 extents).
Logical volume vg1/thinlv1 successfully resized.
root@vtela:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
thinlv1 vg1 Vwi-a-tz-- <100.49g thinpool1 0.00
thinpool1 vg1 twi-aotz-- <7.49g 0.00 10.79
root@vtela:~# lvresize -L -500m /dev/vg1/thinlv1
WARNING: Reducing active logical volume to 100.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg1/thinlv1? [y/n]: y
Size of logical volume vg1/thinlv1 changed from <100.49 GiB (25725 extents) to 100.00 GiB (25600 extents).
Logical volume vg1/thinlv1 successfully resized.
root@vtela:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
thinlv1 vg1 Vwi-a-tz-- 100.00g thinpool1 0.00
thinpool1 vg1 twi-aotz-- <7.49g 0.00 10.79
root@vtela:~#
2.4.2.5 刪除 & 重命名
同thick類型