centos7加硬盘给根分区扩容--lvm模式


centos 7.4 磁盘空间不足,扩容根分区 --lvm模式 (转载)

背景:根分区磁盘空间不足,需要扩容root磁盘空间

新增硬盘一块

1、查看现有磁盘信息,可以看出根分区有26G

[root@localhost ~]# df -h

https://img2018.cnblogs.com/i-beta/1751005/202002/1751005-20200226144916459-1980886794.png

 

2、查看新增加的磁盘信息(改虚拟机已经添加好了,不在细说)

[root@localhost ~]# fdisk -l

https://img2018.cnblogs.com/i-beta/1751005/202002/1751005-20200226145003222-557014026.png

 

3、根据以上信息,对新增加的磁盘进行分区(此处为虚拟机,默认格式为xfs,若需换ext4则分区后进行分区格式化即可)

[root@localhost ~]# fdisk /dev/sdb

https://img2018.cnblogs.com/i-beta/1751005/202002/1751005-20200226145059818-190792204.png

 

分区格式化(mkfs.ext4 /dev/sdb1),此处不需要,不举例说明

 

4. 创建物理卷

[root@localhost ~]# pvcreate /dev/sdb1

https://img2018.cnblogs.com/i-beta/1751005/202002/1751005-20200226145200439-384999154.png

 

 

5. 查看物理卷信息

[root@localhost ~]# pvdisplay

https://img2018.cnblogs.com/i-beta/1751005/202002/1751005-20200226145234720-1300433544.png

 

 

6、查看卷组信息

[root@localhost ~]# vgdisplay

https://img2018.cnblogs.com/i-beta/1751005/202002/1751005-20200226145307381-1491188961.png

 

 

7. 将新增加的分区/dev/sdb1加入到根目录分区centos中

[root@localhost ~]# vgextend centos /dev/sdb1

https://img2018.cnblogs.com/i-beta/1751005/202002/1751005-20200226145338834-1840533663.png

 

 

8、重新查看卷组信息

[root@localhost ~]# vgdisplay

https://img2018.cnblogs.com/i-beta/1751005/202002/1751005-20200226145415633-912348031.png

 

 

9、进行卷扩容

[root@localhost ~]# lvextend -l +100%FREE /dev/mapper/centos-root

https://img2018.cnblogs.com/i-beta/1751005/202002/1751005-20200226145451705-1792735324.png

 

 

10、查看磁盘格式(此处为xfs格式,有时候是ext4格式)

[root@localhost ~]# blkid

https://img2018.cnblogs.com/i-beta/1751005/202002/1751005-20200226145526527-577821595.png

 

 

11. 调整卷分区大小

[root@localhost ~]# xfs_growfs /dev/mapper/centos-root

https://img2018.cnblogs.com/i-beta/1751005/202002/1751005-20200226145630794-13815135.png

 

 

12、查看扩容结果
扩容前:

 https://img2018.cnblogs.com/i-beta/1751005/202002/1751005-20200226145652760-1140410591.png

 

 

扩容后:

https://img2018.cnblogs.com/i-beta/1751005/202002/1751005-20200226145708240-1790473982.png

 

 

结束


local Oct. 21, 2021, 4:39 p.m. Collection documents