1、首先将虚拟机关闭,然后选中虚拟机,点击【编辑虚拟机设置】
2、然后选中磁盘,点击【扩展】
3、比如扩展到50G,点击【扩展】
4、出现如下提示,然后点击【确定】
5、然后启动虚拟机
6、登录虚拟机后使用如下命令查看磁盘
fdisk -l
结果如下
7、执行命令查看根目录情况
df -h
结果如下,未扩容前只剩下5.5G
8、基于分区命令进行分区创建,具体如下
[root@centos7-1 ~]# fdisk /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
命令(输入 m 获取帮助):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)
命令(输入 m 获取帮助):n # 输入n创建新的分区
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): p # 输入p,即primary类型
已选择分区 3 # 这里因为只有一个primary类型了,因此此处不需要选择,直接使用默认的4了
起始 扇区 (62914560-104857599,默认为 62914560): # 输入回车,保持默认即可
将使用默认值 62914560
Last 扇区, +扇区 or +size{K,M,G} (62914560-104857599,默认为 104857599): # 输入回车,保持默认即可
将使用默认值 104857599
分区 4 已设置为 Linux 类型,大小设为 20 GiB
命令(输入 m 获取帮助):w # 输入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)
正在同步磁盘。
[root@centos7-1 ~]#
9、再起执行命令查看分区情况
fdisk -l
结果如下、已创建新的分区
10、重启虚拟机后生效
reboot
11、常看逻辑卷的组名
lvs
结果如下,可以看出根目录的逻辑卷组名为centos
12、将磁盘分区初始化为物理卷,以便被LVM使用
vgextend centos /dev/sda3
成功后如图所示
13、将分区加入到centos的逻辑卷组中
vgextend centos /dev/sda3
成功后显示如图所示
14、查看逻辑卷组
vgdisplay
查看剩余空闲空间
15、查看需要扩展的根目录文件系统名
16、扩展卷组的容量
lvextend -L +60G /dev/mapper/centos-root
如图成功显示,如果提示失败,减小扩展空间重试即可