1、打开vm的磁盘扩展,需要关机加上没有快照才能拓展
2、查看分区
df -h
3、查看已有分区
[root@localhost ~]# fdisk -l
磁盘 /dev/sda:214.7 GB, 214748364800 字节,419430400 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000c74e2
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 83886079 40893440 8e Linux LVM
/dev/sda3 83886080 419430399 167772160 83 Linux
磁盘 /dev/mapper/centos-root:211.5 GB, 211518750720 字节,413122560 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
4、分区过程
[root@localhost ~]# fdisk /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
命令(输入 m 获取帮助):m
命令操作
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
选择n拓展磁盘,然后一直回车默认就行
最后选择w保存当前更改
5、格式化分区
# 假设新创建的分区是/dev/sda4
sudo mkfs -t ext4 /dev/sda4
# 可能会报错 The device apparently does not exist; did you specify it correctly?
# 解决办法就是先输入下面这个, 参考https://blog.csdn.net/tianlesoftware/article/details/6450469
partprobe
6、使用vgscan查询物理卷
[root@localhost ~]# vgscan
Reading volume groups from cache.
Found volume group "centos" using metadata type lvm2
我的group叫做centos,有的叫做cl
7、扩展lv,在/dev/mapper/目录下
lvextend -L +100G /dev/mapper/centos-root
8、接着用 df –h,发现实际容量并没有变化(这一步主要是用来对比)
9、拓展分区
xfs_growfs 加上要扩展的分区名(就是上面用的那个)
或者
resize2fs – f 加 上要扩展的分区名
xfs_growfs /dev/mapper/centos-root
10、再次df -h发现已经扩容完毕了