Shut down the virtual machine and open virtual machine settings->Add
Click the hard disk -> Select next step
. It is recommended to use SCSI. The default is enough.
Create a new virtual disk. Next step
is to split the virtual machine disk into multiple files. Next step
is to name it and customize it. Complete.
The addition is completed. Turn on the virtual machine and set it up.
This article introduces how to expand the "/" directory
View file system
[root@localhost ~]# df -h
Check the partition and you can see that the newly added disk is in /dev/sdb
fdisk -l 查看分区使用情况
Enter "p" and press Enter, #View the number of partitions
. Enter "n" and press Enter, #Add a new partition.
Enter "p" and press Enter, #Use the default partition number, and
press Enter at the starting sector (use the default value)
Press Enter after popping up last,
then enter "p" to view the current partition information,
enter "w" to write the disk information and save it.
Restart the virtual machine to format the new partition;
[root@localhost ~]# init 6 重启虚拟机
[root@localhost ~]# fdisk -l
[root@localhost ~]# vgdisplay
Initialize the created partition,
[root@localhost ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created. #命令执行结果,物理卷“/dev/sdb1”创建成功。
To expand the space of the original file system, you need to perform the following steps:
Add partition to virtual volume
[root@localhost ~]# vgextend centos /dev/sdb1
Volume group "centos" successfully extended #命令执行结果,卷组“centos”成功扩展
Then lvextend -L +19G /dev/mapper/centos-root to expand the volume group capacity, and use fdisk -l to query the disk /dev/mapper/centos-root.
[root@localhost ~]# lvextend -L +19G /dev/mapper/centos-root
Insufficient free space: 5120 extents needed, but only 5119 available
xfs_growfs /dev/mapper/centos-root expands disk space
[root@localhost ~]# xfs_growfs /dev/mapper/centos-root
The next step is to mount, df -h to check the disk status before mounting
Mounting cannot be done directly here because the disk system format is not ext4.
[root@localhost ~]# mount /dev/sdb1 /
mount: 未知的文件系统类型“LVM2_member”
Use the command mkfs.ext4 /dev/sdb1 to format the hard disk to ext4
[root@localhost ~]# mkfs.ext4 /dev/sdb1
mount mounts the disk
[root@localhost ~]# mount /dev/sdb1 /
The root directory of the mounted disk has 20G of available space.