在我们使用liunx时,通常系统任何数据都是存储在根目录下, 但是跟目录是我们在最开始部署机器时设定好的或者要上线硬盘占用率很大的项目时,才发现我们所需要的硬盘容量不够了,导致各种报错,那么我这个运维大鹅 就来分享一下 如何给根分区扩容!!!
最好在服务器关机时操作并且我们要机房实体机上安装新的硬盘
1.首先查看我们的查看的分区信息
2.然后查看我们的跟分区是lvm逻辑卷引导格式
3.这里我们扩容的硬盘就是sdb0 是5g大小
进行分区格式化
发现已经分区成功
4.讲sdb1分区创建为物理卷
[root@localhost ~]# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created.
查看硬盘状态信息
[root@localhost ~]# vgdisplay -v --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size <19.00 GiB PE Size 4.00 MiB Total PE 4863 Alloc PE / Size 4863 / <19.00 GiB Free PE / Size 0 / 0 VG UUID KdN0TT-cRIy-daEX-rKyl-MdJz-ualK-cCQ5Ns --- Logical volume --- LV Path /dev/centos/swap LV Name swap VG Name centos LV UUID yAn7Cg-Rczt-ouUf-zLPV-sKzU-kOj2-mqVAEz LV Write Access read/write LV Creation host, time localhost, 2020-05-25 15:29:48 +0800 LV Status available # open 2 LV Size 2.00 GiB Current LE 512 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID tsN8j4-GHsb-g9ad-PVO1-sWQ9-wID1-93SNL1 LV Write Access read/write LV Creation host, time localhost, 2020-05-25 15:29:49 +0800 LV Status available # open 1 LV Size <17.00 GiB Current LE 4351 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Physical volumes --- PV Name /dev/sda2 PV UUID EAmI3a-sYw0-b1fU-ZzhC-rw9n-k1bA-huC0Vn PV Status allocatable Total PE / Free PE 4863 / 0
其中 下面4分之3处 就是我们根分区信息以及挂载位置
5.扩展容量到根分区所在的卷组
[root@localhost ~]# vgextend centos /dev/sdb1 Volume group "centos" successfully extended
6.最后一步扩展根目录卷组下分区到逻辑卷生效
这里有两种方式
第一种扩展卷组里全部剩余容量到逻辑卷
[root@v1 ~]# lvextend -l +100%FREE /dev/cl/root
第二种只扩容设定容量到逻辑卷
[root@localhost ~]# lvextend -L +2G /dev/centos/root Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to <19.00 GiB (4863 extents). Logical volume centos/root successfully resized.
最后验证
因为df -H 是查看文件系统,而我们的扩展的是lvs逻辑卷所以df查看还是17g大小
目的到达:
lvs 查看逻辑卷状态发现 多了2g 还剩余 2g
lsblk查看根目录容量已经从17G扩展到19G