centos7虚拟机扩容
?
?
df -h
vgdisplay
vgdisplay -v centos
2、确认当前磁盘容量信息,/dev/sda大小为53.7GB,划分了2个分区,已划分的总容量不到20GB。还有将近30GB可用空间
fdisk -l
3、在未用空间创建新的分区sda3。(很重要)
主要输入:n p w,其他的就默认就好
[root@backup03 ~]# fdisk /dev/sda ? Command (m for help): n ? Select (default p): p ? Partition number (3,4, default 3): ? First sector (25593856-104857599, default 25593856): ? Using default value 25593856 ? Last sector, +sectors or +size{K,M,G} (25593856-104857599, default 104857599): ? Using default value 104857599 ? Partition 3 of type Linux and of size 37.8 GiB is set ? Command (m for help): w ? The partition table has been altered! ? Calling ioctl() to re-read partition table. ? WARNING: Re-reading the partition table failed with error 16: Device or resource busy. ? 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 ? Syncing disks.
4、根据上面步骤的提示,需要重启或者运行命令partprobe重新同步磁盘分区信息,分区重新识别后可以看到新分区sda3。
[root@backup03 ~]# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
5、使用lvm命令pvcreate格式化sda3分区。
[root@backup03 ~]# pvcreate /dev/sda3 Physical volume "/dev/sda3" successfully created. [root@backup03 ~]# pvdisplay
?
6、将分区sda3加入root所在的vg(centos)里 。
[root@backup03 ~]# vgextend centos /dev/sda3 Volume group "centos" successfully extended [root@backup03 ~]# vgdisplay -v centos
7、扩展root根分区所在的逻辑卷大小,vgdisplay可以看到root所在lv大小已经发生变化。
这里37G要按照实际情况来。当然也可以不挂在/dev/centos/root,有些是挂在/dev/centos/home里面的。
lvextend -L +37G /dev/centos/root
vgdisplay -v
8、根目录大小依然没变化
df -h
9,确认root文件系统的类型是xfs后,使用xfs_growfs命令扩展根目录大小。
mount
10,使用xfs_growfs命令扩展根目录大小
xfs_growfs /dev/centos/root
11,最后使用df命令,确认根目录大小已经从原来的10GB扩展为40GB。
df -h