提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
1.检查当前磁盘使用情况
使用 df -h
命令查看当前磁盘使用情况,确认根目录的分区和使用情况。
[root@nz ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 979M 0 979M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 9.8M 981M 1% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 3.0G 15G 18% /
/dev/sdb2 1014M 33M 982M 4% /mnt/fdisk2
/dev/sdc1 1014M 33M 982M 4% /mnt/gdisk2
/dev/mapper/vg1-lv1 501M 8.3M 493M 2% /mnt/disklv1
/dev/sda1 1014M 138M 877M 14% /boot
/dev/sdb1 976M 2.6M 907M 1% /mnt/fdisk1
/dev/mapper/vg1-lv2 74M 1.6M 67M 3% /mnt/disklv2
tmpfs 199M 0 199M 0% /run/user/0
/dev/mapper/vgce-lvce 9.0G 33M 9.0G 1% /mnt/disklvce
用命令lsblk查看磁盘和分区情况
[root@nz ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 5G 0 disk
├─sdb1 8:17 0 1G 0 part /mnt/fdisk1
├─sdb2 8:18 0 1G 0 part /mnt/fdisk2
├─sdb3 8:19 0 1G 0 part
├─sdb4 8:20 0 1K 0 part
└─sdb5 8:21 0 300M 0 part
sdc 8:32 0 5G 0 disk
├─sdc1 8:33 0 1G 0 part /mnt/gdisk2
└─sdc2 8:34 0 4G 0 part
└─vgce-lvce 253:4 0 9G 0 lvm /mnt/disklvce
sdd 8:48 0 5G 0 disk
├─sdd1 8:49 0 2G 0 part
│ ├─vg1-lv1 253:2 0 504M 0 lvm /mnt/disklv1
│ └─vg1-lv2 253:3 0 80M 0 lvm /mnt/disklv2
└─sdd2 8:50 0 3G 0 part
└─vg2-lv1 253:5 0 100M 0 lvm
sde 8:64 0 5G 0 disk
└─vgce-lvce 253:4 0 9G 0 lvm /mnt/disklvce
sdf 8:80 0 5G 0 disk
sdg 8:96 0 5G 0 disk
└─sdg1 8:97 0 3G 0 part [SWAP]
sdh 8:112 0 10G 0 disk
sr0 11:0 1 4.4G 0 rom
2.扩展分区
2.1 查看pv、vg、lv信息
[root@nz ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <19.00g 0
/dev/sdc2 vgce lvm2 a-- <4.00g 0
/dev/sdd1 vg1 lvm2 a-- <2.00g <1.43g
/dev/sdd2 vg2 lvm2 a-- <3.00g <2.90g
/dev/sde vgce lvm2 a-- <5.00g 0
/dev/sdf vgce lvm2 a-- <5.00g <5.00g
[root@nz ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- <19.00g 0
vg1 1 2 0 wz--n- <2.00g <1.43g
vg2 1 1 0 wz--n- <3.00g <2.90g
vgce 3 1 0 wz--n- <13.99g <5.00g
[root@nz ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- <17.00g
swap centos -wi-ao---- 2.00g
lv1 vg1 -wi-ao---- 504.00m
lv2 vg1 -wi-ao---- 80.00m
lv1 vg2 -wi-a----- 100.00m
lvce vgce -wi-ao---- 8.99g
2.2 对根目录(\)逻辑卷进行扩容
#标记新卷组
[root@nz ~]# pvcreate /dev/sdh
Physical volume "/dev/sdh" successfully created.
#扩容卷组vg
[root@nz ~]# vgextend centos /dev/sdh
Volume group "centos" successfully extended
#扩容逻辑卷lv
#在原基础上增加8G
[root@nz ~]# lvextend -L +8G /dev/centos/root
Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to <25.00 GiB (6399 extents).
Logical volume centos/root successfully resized.
#将卷组剩余容量按百分比扩容
[root@nz ~]# lvextend -l +100%FREE /dev/centos/root
Size of logical volume centos/root changed from <25.00 GiB (6399 extents) to 26.99 GiB (6910 extents).
Logical volume centos/root successfully resized.
3. 扩容文件系统
xfs的文件系统: xfs_growfs /dev/vg_name/lv_name
ext4的文件系统: resize2fs /dev/vg_name/lv_name
[root@nz ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1113856 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=4455424, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 4455424 to 7075840