磁盘逻辑卷lvm分区+动态扩容
1,添加新的sdb,sdc磁盘,并查看添加的分区
[root@localhost ~]# fdisk -l
[root@localhost ~]# fdisk -l /dev/sdb
[root@localhost ~]# fdisk -l /dev/sdc
帮助信息
2,使用fdisk来对/dev/sdb盘进行分区,并修改分区类型为逻辑卷分区,添加完成后保存(w)退出
[root@localhost ~]# fdisk /dev/sdb
修改逻辑卷
逻辑分区的类型是8e
3,将新建的逻辑分区做成物理卷(PV)
[root@localhost ~]# pvcreate /dev/sdb1 (创建/dev/sdb1逻辑分区成作为物理卷)
Physical volume "/dev/sdb1" successfully created.
[root@localhost ~]# pvscan (查看做好的物理卷)
PV /dev/sdb1 lvm2 [<10.00 GiB]
4,将物理卷添加到新的卷组
[root@localhost ~]# vgcreate vg1 /dev/sdb1 (添加分区/dev/sdb1到新创建的卷组vg1)
Volume group "vg1" successfully created
[root@localhost ~]# vgscan (查看新创建的卷组)
Found volume group "vg1" using metadata type lvm2
5,分配卷组的逻辑分区容量到逻辑卷(LV)
[root@localhost ~]#lvcreate -L 9G -n lv1 vg1 (分配指定的空间大小并创建逻辑卷lv1)
[root@localhost ~]#vcreate -L +100%FREG -n lv1 vg1 (分配卷组里面的所有空闲容量并创建逻辑卷)
[root@localhost ~]# lvscan (查看创建的逻辑卷)
ACTIVE '/dev/vg1/lv1' [9.00 GiB] inherit
6,格式化分区(这里格式化为xfs文件系统)并挂载
[root@localhost ~]# mkfs.xfs /dev/vg1/lv1 (格式化分区)
meta-data=/dev/vg1/lv1 isize=512 agcount=4, agsize=589824 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=2359296, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]# mount /dev/vg1/lv1 /data (挂载逻辑卷到/data)
[root@localhost ~]# df -Th (查看挂载状态,分区及挂载成功)
7,修改配置文件到开机挂
[root@localhost ~]# vim /etc/fstab
8,动态扩容逻辑卷(新添加的磁盘制作逻辑分区跟上面一样)
[root@localhost ~]# fdisk -l /dev/sdc
[root@localhost ~]# pvcreate /dev/sdc2 (添加/dev/sdc2逻辑分区到物理卷)
Physical volume "/dev/sdb1" successfully created.
[root@localhost ~]# pvscan (查看做好的物理卷)
PV /dev/sdb1 lvm2 [<10.00 GiB]
PV /dev/sdc2 lvm2 [<10.00 GiB]
[root@localhost ~]# vgextend vg1 /dev/sdc2 (添加逻辑分区/dev/sdc2到vg1卷组)
Volume group "vg1" successfully extended
[root@localhost ~]# vgs (查看卷组信息)
VG #PV #LV #SN Attr VSize(卷组总空间) VFree(剩余卷组空间)
vg1 2 1 0 wz--n- 19.99g 10.99g
[root@locao ~]# lvextend -l +100%FREE /dev/vg1/lv1 (把卷组里面的所有空间分配到逻辑卷)
Size of logical volume vg1/lv1 changed from 9.00 GiB (2304 extents) to 19.99 GiB (5118 extents).
Logical volume vg1/lv1 successfully resized.
[root@localhost ~]# lvscan (查看逻辑卷信息)
ACTIVE '/dev/vg1/lv1' [19.99 GiB] inherit
9重新读取逻辑卷大小
[root@localhost ~]# xfs_growfs /dev/mapper/vg1-lv1
查看动态扩容的逻辑卷分区,扩容完成