Centos7 LVM管理的逻辑卷根目录扩容和/var目录扩容

时间:2021-01-25 18:49:23

Centos7 LVM管理的逻辑卷根目录扩容

fdisk /dev/sdb       #对新加磁盘进行分区操作
pvcreate /dev/sdb1 #创建一个物理卷
vgs #查看现有的卷组
vgextend centos /dev/sdb1 #将创建的物理卷扩展至现有的root卷组
lvs #查看现有逻辑卷
lvextend -L +1.95T /dev/centos/root #将空间扩展至根分区的逻辑卷中
xfs_growfs /dev/centos/root #格式化扩展的逻辑卷,如果是ext4格式的文件,使用resize2fs  对ext4格式的磁盘格式化

/var目录扩容

1、查看初始的磁盘目录

[root@localhost ~]# df -HT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 4.1G 0 4.1G 0% /dev
tmpfs tmpfs 4.2G 0 4.2G 0% /dev/shm
tmpfs tmpfs 4.2G 9.3M 4.1G 1% /run
tmpfs tmpfs 4.2G 0 4.2G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 11G 2.2G 8.1G 21% /
/dev/mapper/centos-var xfs 2.2G 145M 2.0G 7% /var
/dev/mapper/centos-home xfs 2.2G 34M 2.2G 2% /home
/dev/sda1 xfs 521M 145M 377M 28% /boot
tmpfs tmpfs 821M 0 821M 0% /run/user/0

2、服务器增加一个硬盘并分区

[root@localhost ~]# fdisk -l
...
Disk /dev/sdb: 4294 MB, 4294967296 bytes, 8388608 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x2e0f7732 Device Boot Start End Blocks Id System
/dev/sdb1 2048 8388607 4193280 8e Linux LVM

3、查看var所在的卷组(查看到VG Name:centos)

[root@localhost ~]# lvdisplay
....
--- Logical volume ---
LV Path /dev/centos/var
LV Name var
VG Name centos
LV UUID rRzpmV-wmlt-0IHk-KBR8-rRRy-BBxs-VJ92E5
LV Write Access read/write
LV Creation host, time localhost, 2020-06-12 16:37:42 -0400
LV Status available
# open 1
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:3
#VG默认信息
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 4
Open LV 4
Max PV 0
Cur PV 1
Act PV 1
VG Size <15.51 GiB
PE Size 4.00 MiB
Total PE 3970
Alloc PE / Size 3969 / 15.50 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID fvDOrI-1z8x-7Lkq-s8kR-9UfE-UpEa-BkVVjH

4、扩容/var目录所在的vg和lv

#扩容VG
[root@localhost ~]# vgextend centos /dev/sdb1
Volume group "centos" successfully extended #扩容LV
[root@localhost ~]# lvextend -L +2G /dev/centos/var
Size of logical volume centos/var changed from 2.00 GiB (512 extents) to 4.00 GiB (1024 extents).
Logical volume centos/var successfully resized. #更新
[root@localhost ~]# xfs_growfs /dev/centos/var

5、查看磁盘空间

df -Th

https://www.cnblogs.com/kevingrace/p/5825963.html

umount /home           卸载掉/home目录

vi /etc/fstab                编辑分区表文件,注释掉/home分区

systemctl reboot       重启

df -h                           查看磁盘情况
Mount 查看挂载情况 vgdisplay -v 查看lvm情况 lvremove /dev/cl/home 删除/home分区 vgdisplay -v 查看lvm情况 lvextend -L850GiB /dev/cl/root 将磁盘空间添加给/目录 vgdisplay -v xfs_growfs /dev/cl/root df -h systemctl reboot