Expand Linux root directory disk space

Problem: If you create a virtual machine at the beginning , the disk space mounted to the root directory (/) of the virtual machine is too small, so the disk space will fill up quickly. If the root directory occupies more than 90% of the disk space, the software cannot be reinstalled.

View root directory disk space:

Yes - right click root directory - properties

 It can also be viewed in - Disk Utility -

 View in terminal:

Use the df command to view the remaining space of the disk

The full English name of the df command is "Disk Free". As the name implies, the function is to display the available disk space on the system.

df -h

 The following steps are the methods to expand the disk space

Add a hard disk to the virtual machine

 

 Start the virtual machine, enter the centos system, open the terminal, and enter in the terminal interface

df -h

Command, and press Enter, you can see the original disk space in the terminal interface, and it has not been expanded.

Next, enter in the terminal interface

fdisk -l

Command, ( if you are an ordinary user, add sudo before the command, that is, "sudo fdisk -l") to view the partition information of the new disk.

 Then start to operate on the newly added disk

Enter the command: fdisk /dev/sdb (here /dev/sdb is the name of the expanded disk above)

In the terminal command, enter the "p" command and press Enter to view the number of partitions. 

 I don't have a partition here, if there is a partition, it should be like this

In the terminal command, enter the "n" command and press Enter to add a new partition.

Enter the "p" command in the terminal command window, press Enter, hit the default partition number in the opened partition number, and press Enter.

In the displayed starting sector, press the Enter key directly, and in the pop-up Last, directly press the Enter key to enter the next step (directly use the Enter key at the position of the picture frame to enter the next step).

Enter "p" in the terminal command window and press Enter to view the information of the current partition. In the displayed information, you can see that a new partition has been added, and the size is the size just set.

Enter the "w" command in the terminal command, press Enter, write the disk information and save it.

In a terminal command window, enter

reboot

And press Enter, restart the virtual machine to format the new partition

After waiting for the system to restart automatically, open the terminal command and enter in the command window

vgdisplay

View disk volume group name

In the terminal command window enter

pvcreate  /dev/sdb1

Command and press Enter, (ordinary users add sudo, root users do not) initialize the newly created partition. (sdb1 is the name of the partition you just partitioned)

In the terminal command window enter

vgextend centos /dev/sdb1

command and press Enter to add the newly initialized partition to the virtual volume group name (command: vgextend virtual volume group name to add a new partition). (centos is your volume group name, according to what you checked above)

Next, continue to enter the "vgdisplay" command in the terminal command window to view the detailed information of the volume group. In the detailed information, you can see that the newly added 42G space is still in an idle state.

Then, continue to enter the "df -l" command in the terminal command window and press Enter, check and write down the file system name that needs to be expanded (the system name I checked here is: /dev/mapper/centos-root, different The versions viewed should be different, and everyone should pay attention to the distinction).

Next, continue typing in the terminal command window

lvextend -L +2G /dev/mapper/centos-root

Command and press Enter to expand the capacity of the existing volume group (Note: If the system will report an error that the expansion fails, the 2G cannot be fully expanded here, and only the capacity smaller than 2G can be expanded.

Command: lvextend -L + the capacity to be extended The file system name to be extended

Pay attention to the case-sensitive letters in the command).

Next, continue to enter the "pvdisplay" command in the terminal command window and press Enter to view the current volume group. In the displayed information, the volume group has been expanded successfully, and the file system needs to be expanded next.

Next, continue typing in the terminal command window

cat /etc/fstab | grep centos-root

Command and press Enter to view the format of the file system.

You have seen the format of the file system in the previous step, you need to use the corresponding command to expand the disk space, enter in the terminal command

xfs_growfs /dev/mapper/centos-root

Command and press Enter (command: xfs_growfs file system name, use different commands for different file systems, otherwise it will cause an error) as shown in the figure:

Then, wait for the system to automatically expand the capacity. After completion, enter the "df -h" command in the terminal command window and press Enter to check whether the disk size expansion is successful. In the displayed disk information, you can see that the disk expansion is successful. (Before it was 36G, now it is 38G) 

Disk Utility View --Success

 So far, VMware virtual machine disk expansion is over

Guess you like

Origin blog.csdn.net/weixin_55988897/article/details/128712009