一、LVM初始化
1.物理卷pv
常用命令
pvs/pvscan 查看系统里有pv的磁盘
pvdisplay 显示系统上面的pv状态
pvremove 删除pv
创建pv
pvcreate /dev/sdb2
Physical volume "/dev/sdb2" successfully created.
查看pv列表
pvs/pvscan
PV VG Fmt Attr PSize PFree
/dev/sda2 vg_root lvm2 a-- 35.00g 1.00g
/dev/sda3 vg_new lvm2 a-- 64.50g 9.50g
/dev/sdb1 lvm2 --- 95.36g 95.36g
/dev/sdb2 lvm2 --- <104.64g <104.64g
查看pv状态
pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name vg_root
PV Size 35.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 8960
Free PE 256
Allocated PE 8704
PV UUID yC67Cm-Hvxr-aXde-ovxA-1qME-UEIa-hmkzgq
--- Physical volume ---
PV Name /dev/sda3
VG Name vg_new
PV Size <64.51 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 16513
Free PE 2433
Allocated PE 14080
PV UUID NTfuir-ISnX-Z3n0-EW4K-lVO8-dW6W-92Qrsx
"/dev/sdb1" is a new physical volume of "95.36 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 95.36 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID IDvczi-rEfG-t6ZW-fZeE-HBIY-2kkl-TH4nMf
2.卷组vg
常用命令
vgcreate [-s xM] vgName /dev/sd 新建vg,-s后面接pe的大小(可选),单位是M,G,可以放多块pv
vgextend 扩展vg,就是增加pv
vgs/vgscan 查看系统里有vg的磁盘
vgdisplay 显示系统上面的vg状态
vgremove 删除vg
vgreduce 在vg里删除pv
创建卷组vg
vgcreate -s 1g vgtest /dev/sdb2
Volume group "vgtest" successfully created
扩容卷组
vgextend vgtest /dev/sdb1
缩容卷组
vgreduce vgtest /dev/sdb1
查看卷组列表
vgs/vgscan
VG #PV #LV #SN Attr VSize VFree
vg_new 1 2 0 wz--n- 64.50g 9.50g
vg_root 1 5 0 wz--n- 35.00g 1.00g
vgtest 1 0 0 wz--n- 104.00g 104.00g
删除卷组
vgremove vgtest
3.逻辑卷lv
常用命令
lvcreate -l penum /-L size -n lvname vgName 新建lv,-l指定pe的个数,-L指定容量,M,G
lvextend 增加容量
lvs/lvscan 查看系统里有lv的磁盘
lvdisplay 显示系统上面的lv状态
lvremove 删除lv
lvreduce 在lv里减少容量
创建逻辑卷lv
lvcreate -L 1g -n lvtest vgtest
Logical volume "lvtest" created.
格式化逻辑卷
两种文件格式二选一(ext4支持扩容缩容,xfs只支持扩容)
mkfs.ext4 /dev/vgtest/lvtest
mkfs.xfs /dev/vgtest/lvtest
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
lvs
lvtest vgtest -wi-a----- 1.00g
挂载逻辑卷
mount /dev/vgtest/lvtest /mntt
df -h
/dev/mapper/vgtest-lvtest 976M 2.6M 907M 1% /mntt
二、LVM动态扩容/缩容/删除
1.扩容
lvs
lvtest vgtest -wi-ao---- 1.00g
lvextend -L +2g /dev/vgtest/lvtest
resize2fs /dev/vgtest/lvtest (ext4文件系统)
xfs_growfs /dev/vgtest/lvtest (xfs文件系统)
lvs
lvtest vgtest -wi-ao---- 3.00g
df -h
/dev/mapper/vgtest-lvtest 3.0G 3.0M 2.8G 1% /mntt
2.缩容
umount文件系统
umount /dev/vgtest/lvtest
缩容
e2fsck -f /dev/vgtest/lvtest
resize2fs /dev/vgtest/lvtest 1g
lvreduce -L 1g /dev/vgtest/lvtest
lvs
lvtest vgtest -wi-ao---- 1.00g
mount /dev/vgtest/lvtest /mntt
df -h
/dev/mapper/vgtest-lvtest 976M 2.6M 914M 1% /mntt
3.删除LVM
- 卸载文件系统 umount /dev/vgtest/lvtest
- 删除逻辑卷 lvremove /dev/vgtest/lvtest
- 删除卷组 vgremove vgtest
- 删除物理卷 pvremove /dev/sdb2
三、T/Q环境逻辑卷扩容
vgs/vgdisplay
lvs/lvdisplay
扩容/缩容卷组
vgextend vg_root /dev/sdb1
vgreduce vg_root /dev/sdb1
vgs
VG #PV #LV #SN Attr VSize VFree
vg_new 1 2 0 wz--n- 64.50g 9.50g
vg_root 1 5 0 wz--n- 35.00g 1.00g
vgextend vg_new /dev/sdb1
vgs
VG #PV #LV #SN Attr VSize VFree
vg_new 2 2 0 wz--n- 159.86g 104.86g
vg_root 1 5 0 wz--n- 35.00g 1.00g
扩容逻辑卷
lvextend -L +10G /dev/vg_new/lvnew
针对ext2/ext3/ext4文件系统(支持扩容缩容):resize2fs /dev/vg_new/lvnew
针对xfs_growfs文件系统(只支持扩容):xfs_growfs /dev/vg_new/lvnew
四、参考文档
https://blog.csdn.net/qq_27281257/article/details/81603410
来源:CSDN
作者:lj淡然一笑
链接:https://blog.csdn.net/lj_1129/article/details/103816225