Linux (CentOS) in the VMware virtual machine increases the size of the system root directory, the root directory is not the solution to the last partition

In Linux, there are two ways of managing disks, non-LVM (traditional/direct) or LVM (dynamic). Whether it is LVM or not is determined when the system is installed. The two management methods correspond to different expansion methods. If it is LVM, use pvcreate, vgcreate, lvextend methods, if it is not LVM, use d, n methods in fdisk, and only the last partition of the disk can be expanded. Viewing method: run the command lvs, if there is a result, it will be LVM. The following mainly introduces the non-LVM managed disk expansion method.

1.
Since only the last partition of the disk can be expanded, it is necessary to check whether the file system mounted on the root directory is the last partition. As shown in the figure, /dev/sda2 is mounted to /, and /dev/sda3 is also used as a swap partition (ignoring the subsequent 11G LMV2 volume).
insert image description here

At this point, the swap partition must be deleted. Many methods on the Internet are used, such as swapoff and parted, but one step is enough:

  • 1) Delete the line that mounts the file system to swap in /etc/fstab. Then reboot.

Make sure the additional disk space is free (unallocated).

Two
and then assign.

  • 2) Log in as the root user
  • 3) fdisk <disk to be expanded>, for example, here is fdisk /dev/sda
  • 4) d, delete the partition (don’t worry about deleting data, as long as you don’t enter the w command, the changes will not be saved)
  • 5) <n>, the nth partition, here is 2 (/dev/sda2 is mounted to the root directory/)
  • 6) n , create a new partition
  • 7) <n> , same as step 5
  • Select the start and end block, adjust according to needs
  • If prompted Partition #n contains an ext4 signature.
    Do you want to remove this signature? Yes [Y] / No [N]: N
  • 8) w , write changes
  • 9) If df and lsblk/fdisk display different sizes, use the command resize2fs /dev/sda<n> to adjust to the size on lsblk/fdisk resize2fs <fs>, and re-adjust the disk size, such as resize2fs /dev/sda2
  • Optional: reboot

Three
You can see that the root directory has become larger.
insert image description here
In the future, a new swap will be created (if necessary).

Guess you like

Origin blog.csdn.net/qq_44345567/article/details/114630872