准备
添加新硬盘
创建linux lvm(8e)
格式的主分区
创建逻辑卷的步骤:
1)通过pvcreate命令将linux分区处理成物理卷(PV);
2)通过vgcreate命令将创建好的物理卷处理成卷组(Vg);
3)通过lvcreate命令将卷组分成若干个逻辑卷(Lv);
LVM 扩容
创建pv
pvcreate /dev/vdb1
使用pvs查看
[root@tomcat-tst ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/vda2 VolGroup lvm2 a-- 19.51g 0
/dev/vdb1 lvm2 --- 20.00g 20.00g
添加到vg
查看vg
[root@tomcat-tst ~]# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup 1 2 0 wz--n- 19.51g 0
添加pv到vg
[root@tomcat-tst ~]# vgextend VolGroup /dev/vdb1
Volume group "VolGroup" successfully extended
[root@tomcat-tst ~]# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup 2 2 0 wz--n- 39.50g 20.00g
LVM扩容
查看lvm
[root@tomcat-tst ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv_root VolGroup -wi-ao---- 17.51g
lv_swap VolGroup -wi-ao---- 2.00g
扩容 lvresize
通过 lvresize -L +19G /dev/VolGroup/lv_root
命令扩容LV大小
方法一:添加剩余大小
[root@tomcat-tst ~]# lvresize -L +19G /dev/VolGroup/lv_root
Size of logical volume VolGroup/lv_root changed from 17.51 GiB (4482 extents) to 36.51 GiB (9346 extents).
Logical volume lv_root successfully resized
方法二:添加剩余pv数
[root@tomcat-tst ~]# lvresize -l +5682 /dev/VolGroup/lv_root
...
刷新逻辑卷
#xfs_growfs /dev/mapper/centos-root //刷新文件系统,针对xfs文件格式
#resize2fs /dev/mapper/centos-root //刷新文件系统,针对ext4文件格式
[root@tomcat-tst ~]# resize2fs /dev/VolGroup/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/VolGroup/lv_root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 3
Performing an on-line resize of /dev/VolGroup/lv_root to 9570304 (4k) blocks.
The filesystem on /dev/VolGroup/lv_root is now 9570304 blocks long.
[root@tomcat-tst ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
36G 6.3G 28G 19% /
tmpfs 6.9G 0 6.9G 0% /dev/shm
/dev/vda1 477M 57M 395M 13% /boot
[root@tomcat-tst ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv_root VolGroup -wi-ao---- 36.51g
lv_swap VolGroup -wi-ao---- 2.00g