创建LVM
首先添加三块磁盘:可以是/dev/sdb没有分区的也可以是/dev/sdb1已经分区的
注意:如果没有pv命令安装 #yum install -y lvm2
创建pv
[root@linux-server ~]# pvcreate /dev/sdb #创建pv
Physical volume "/dev/sdb" successfully created.
[root@linux-server ~]# pvs #查看pv
PV VG Fmt Attr PSize PFree
/dev/sdb lvm2 --- 10.00g 10.00g
[root@linux-server ~]# pvscan #查看pv
PV /dev/sda2 VG centos lvm2 [<19.00 GiB / 0 free]
PV /dev/sdb lvm2 [10.00 GiB]
Total: 2 [<29.00 GiB] / in use: 1 [<19.00 GiB] / in no VG: 1 [10.00 GiB]
[root@linux-server ~]# pvdisplay #查看pv
创建vg
[root@linux-server ~]# vgcreate vg1 /dev/sdb #创建vg
Volume group "vg1" successfully created
参数解释:
-s 16M 指的是在分区的时候指定vg的大小。
[root@linux-server ~]# vgs #查看vg
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- <19.00g 0
vg1 1 0 0 wz--n- <10.00g <10.00g
[root@linux-server ~]# vgscan
Reading volume groups from cache.
Found volume group "centos" using metadata type lvm2
Found volume group "vg1" using metadata type lvm2
[root@linux-server ~]# vgdisplay #查看vg
创建lv
[root@linux-server ~]# lvcreate -L 150M -n lv1 vg1 #创建lv
Rounding up size to full physical extent 152.00 MiB
Logical volume "lv1" created.
[root@linux-server ~]# lvcreate -l 20 -n lv2 vg1 #采用PE方式在创建一个lv
Logical volume "lv2" created.
参数解释:
-L 指定lv的大小
-n 给创建的lv起一个名字
-l 20 指定PE
[root@linux-server ~]# lvs #查看lv
制作文件系统并挂载
[root@linux-server ~]# mkfs.xfs /dev/vg1/lv1
[root@linux-server ~]# mkfs.ext4 /dev/vg1/lv2
[root@linux-server ~]# mkdir /mnt/lv{1..2}
[root@linux-server ~]# mount /dev/vg1/lv1 /mnt/lv1
[root@linux-server ~]# mount /dev/vg1/lv2 /mnt/lv2
[root@linux-server ~]# df -Th
lvm逻辑卷扩容
扩大VG vgextend
1.创建pv
[root@linux-server ~]# pvcreate /dev/sdc
Physical volume "/dev/sdc" successfully created.
2.直接vgextend扩容
[root@linux-server ~]# vgextend vg1 /dev/sdc #vg1卷组名字,将/dev/sdc扩展到vg1中
Volume group "vg1" successfully extended
[root@linux-server ~]# vgs
lv扩容(前提是vg此时有足够满足的容量,如若不满足先给vg扩容)
[root@linux-server ~]# lvextend -L 850M /dev/vg1/lv1 #扩展到850M
[root@linux-server ~]# lvextend -L +850M /dev/vg1/lv1 #在原有基础上加850M
[root@linux-server ~]# lvs
[root@linux-server ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg1-lv1 xfs 149M 7.8M 141M 6% /mnt/lv1
/dev/mapper/vg1-lv2 ext4 74M 1.6M 67M 3% /mnt/lv2
[root@linux-server ~]# xfs_growfs /dev/vg1/lv1 #xfs扩容(刷新)
[root@linux-server ~]# resize2fs /dev/vg1/lv2 #ext4扩容 (刷新)
[root@linux-server ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg1-lv1 xfs 1.7G 9.1M 1.7G 1% /mnt/lv1
/dev/mapper/vg1-lv2 ext4 74M 1.6M 67M 3% /mnt/lv2
扩容root根分区
1.先拿出一块盘或一个盘的分区(分区先得格式化)
2.将磁盘改为物理卷
[root@localhost ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.
3.扩容vg,root的vg名为centos(可以使用lvs查看)
[root@localhost ~]# vgextend centos /dev/sdb
Volume group "centos" successfully extended
4.lv扩容root 下面代码代表将扩容后vg全部内存全部给入root 。 -l +100%FREE
[root@localhost ~]# lvextend -l +100%FREE /dev/centos/root
Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to 21.99 GiB (5630 extents).
Logical volume centos/root successfully resized.
5.刷新扩容root(root为xfs类型,df -hT查看)
[root@localhost ~]# xfs_growfs /dev/centos/root