Detailed Explanation of VMware CentOS Linux Disk Space Expansion Process

environmental information

  • Virtualization software: VMware Workstation 16
  • Virtual machine: CentOS 7.7 64bit  

A total of 20GB single disk is allocated to the Linux virtual machine in VMware, which is not enough. It needs to be expanded, because Linux uses LVM (Logical Volume Manager), so it is very convenient to expand the disk. Proceed as follows

Before expansion

Before the expansion, the disk (LV) space usage rate has reached 94%, which is seriously insufficient, and the space needs to be expanded:

[root@centosa ~]# df -T       (这里加-T选项,可显示文件系统类型)
Filesystem              Type     1K-blocks     Used Available Use% Mounted on
devtmpfs                devtmpfs   1996088        0   1996088   0% /dev
tmpfs                   tmpfs      2013112       44   2013068   1% /dev/shm
tmpfs                   tmpfs      2013112    12208   2000904   1% /run
tmpfs                   tmpfs      2013112        0   2013112   0% /sys/fs/cgroup
/dev/mapper/centos-root xfs       17811456 16695572   1115884  94% /
/dev/sda1               xfs        1038336   164512    873824  16% /boot
tmpfs                   tmpfs       402624        0    402624   0% /run/user/1000


[root@centosa ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000cf932

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM

Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Expansion steps

  1. VMware virtual machine expansion

   After the virtual machine is shut down, the original disk cannot be directly expanded due to the snapshot of the virtual machine, so a new disk can only be added in VMware.

  2. Disk creation partition

   After starting the virtual machine, use the df command to check that the disk space has not changed. Through the fdisk -l command, you can see an additional /dev/sdb Disk

Create a partition on the disk through the following fdisk /dev/sdb

The newly added partition is: /dev/sdb1

  3. Create PV and include it in VG

    At this time, the newly added Partition cannot be seen through the pvdisplay or vgdisplay command.

   After creating the PV through the following pvcreate and vgextend , add the newly installed PV to the VG (our VG is named "centos")

Then, through the pvdisplay or vgdisplay command again, you can see it, and the total capacity of VG has also increased, and the newly added space is Free.

  4. Expand the capacity of the original LV

    Before expanding the LV, you can use the command lvdisplay to view the current LV situation. can be seen:

  • There are already two LVs in the system, both of which are based on the space allocated on the VG named "centos".
  • Combining with the previous, we have insufficient free space in the LV named "  /dev/centos/root ".

Therefore, we will allocate the newly added 10GB of free space to the LV named "  /dev/centos/root ". The command format is:

  • lvextend -L +10240m LV name (-L points to the size of the space to be increased, the unit can be G, M, T, etc.)

Due to direct expansion of 10240MB, it will report "  Insufficient free space: 2560 extents needed, but only 2559 available ". The free free space in VG is not strictly 10GB, but one less PE (one PE of VG is 4MB).

So the size of the expanded space is not 10240m, but 10236m.

[root@centosa ~]# lvextend -L +10236m /dev/centos/root    
  Logical volume centos/root successfully resized.
[root@centosa ~]# 
[root@centosa ~]# 
[root@centosa ~]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  6
  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               28.99 GiB
  PE Size               4.00 MiB
  Total PE              7422
  Alloc PE / Size       7422 / 28.99 GiB
  Free  PE / Size       0 / 0   
  VG UUID               Ngcx2z-PxqT-W9Dl-jg7b-YcQd-2OD3-x4vmDo

  4. Expand the file system

    This is to view the current file system through df, which is still changing. This is because although the LV capacity has been expanded, the file system has not yet been expanded.

   If it is a file system such as ext4, it can be expanded through the command resize2fs . Because we are an xfs file system, we need to use the command xfs_growfs to complete the file system expansion.

   Then check the space situation through df again, and you can see that the space has expanded.

Guess you like

Origin blog.csdn.net/zyplanke/article/details/110701286