Linux CentOS 7 根目录扩容 一、现状描述 现有一台CentOS 7的虚拟机,硬盘容量为30GB
通过lsblk命令查看分区容量,当前根目录容量为27.5GB左右 二、扩容需求 将硬盘容量扩容到40GB,将增加的10GB分配给/根目录
三、扩容步骤 查看硬盘容量 虚拟机调整磁盘容量后(该步骤不赘述),fdisk -l检查系统是否已增加 [root@centos ~]# fdisk -l 可以看到,增加的10GB容量已经增加到了/dev/sda这块硬盘
分区 接下来需要对增加的这10GB容量进行分区:执行fdisk /dev/sda命令,输入n,输入p,回车,回车,输入w,即可对完成对新增的磁盘容量进行分区 [root@centos ~]# fdisk /dev/sda 欢迎使用 fdisk (util-linux 2.23.2)。 更改将停留在内存中,直到您决定将更改写入磁盘。 使用写入命令前请三思。 命令(输入 m 获取帮助):n Partition type: ? ?p? ?primary (2 primary, 0 extended, 2 free) ? ?e? ?extended Select (default p): p 分区号 (3,4,默认 3): 起始 扇区 (62914560-83886079,默认为 62914560): 将使用默认值 62914560 Last 扇区, +扇区 or +size (62914560-83886079,默认为 83886079): 将使用默认值 83886079 分区 3 已设置为 Linux 类型,大小设为 10 GiB 命令(输入 m 获取帮助):w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: 设备或资源忙. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) 正在同步磁盘。 此时可以看到多了个分区/dev/sda3
创建物理卷组、扩容 创建物理卷组之前,先看一下当前卷组的名称 [root@centos ~]# vgdisplay -v 当前卷组名称为:centos
为刚才新增的分区创建物理卷组 [root@centos ~]# pvcreate /dev/sda3 执行以上命令,可能会报以下错误 这是因为系统还不能正常识别该分区,此时需要重启系统! 重启完成系统后,重新执行创建物理卷组命令 将/dev/sda3分区扩容到centos卷组 [root@centos ~]# vgextend centos /dev/sda3 查看根目录的分区路径,此处为:/dev/mapper/centos-root [root@centos ~]# df -h 将新增的容量扩容到根目录(+10G可能会报错,写小一点可正常写入,这里按9.99G写入) [root@centos ~]# lvextend -L +9.99G /dev/mapper/centos-root 调整根目录大小 [root@centos ~]# xfs_growfs /dev/mapper/centos-root 到这里,根目录的扩容已经完成,再看一下根目录的大小,可以看到容量增加了10G |