Virtual machine Linux expansion disk space

Turn off the virtual machine first, then click Settings>Storage
Insert picture description here
Insert picture description here
Insert picture description here

Insert picture description here

Insert picture description here
Enter linux to view the mount point, you can see that the current disk is almost full

df -lh

Insert picture description here
View the disk, you can see all current disks

fdisk -l

Insert picture description here
Partition and format the newly added hard disk. From the above, we can see that the disk we want to operate here is /dev/sdb

fdisk /dev/sdb

输入:p   查看已分区数量(这里我们能看到一个是后面我分好的,新盘是没有的)

Insert picture description here

输入:n    //新建分区
输入:p    //创建逻辑分区
输入:3    //分区号1-4,选fdisk /dev/sdb查看里没有的
输入:回车    //默认(起始扇区)
输入:回车    //默认(结束扇区)
输入:t    //修改分区类型
输入:8e    //修改为LVM(8e就是LVM)
输入:w   //写分区表
输入:q    //完成,退出fdisk命令

Format the partition after restarting the system

mkfs.ext3 /dev/sdb3

Insert picture description here

Add a new LVM to the existing LVM group to achieve expansion (if there is an error in the process, it may be that the remaining capacity of Linux is too small, delete a little useless file and try again)

lvm                  进入lvm管理

lvm> pvcreate /dev/sdb3         初始化刚才的分区

lvm> vgextend centos /dev/sdb3   将初始化过的分区加入到虚拟卷组

lvm> vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               3.95 TiB
  PE Size               4.00 MiB
  Total PE              1036542
  Alloc PE / Size       12542 / 48.99 GiB
  Free  PE / Size       127999/ <500 GiB
  VG UUID               DW27Vv-y1GY-pFVB-0BBz-TSlT-AXnY-n70wtL

lvm>lvextend -L +127999 /dev/mapper/centos-root  扩展已有卷的容量

lvm>pvdisplay              查看卷容量

lvm>quit                 退出

The above is just volume expansion, the following is the real expansion of the file system, enter the following command:

resize2fs /dev/mapper/centos-root
或者
xfs_growfs /dev/mapper/centos-root

Run again: df -h check our machine
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44455388/article/details/107914652