Introduction to Linux Directory Expansion Method

foreword

In the actual development and maintenance work, it is often encountered that the disk mount directory space is not enough. In this case, the original directory is often full of files, and it is very difficult to back up the entire directory.

        In the above background, there are three solutions to solve the insufficient disk space of the directory. (Here take the /home directory as an example)

Option One

1. First copy the target file (/home) to another directory (/tmp), and then unmount the partition (/home).

2. Re-allocate the disk space, and then remount the directory or mount a larger disk space to the directory.

3. Copy the file data back to the target directory (/home).

In the actual operation process, the first scheme has many limitations.

Restriction 1: The target directory (/home) is large, and copying takes a long time. If necessary, consider using the mv command instead of the cp command, because the mv command is more efficient. See the reference article for details.

Restriction 2 In most cases, the current disk has no free space, and another disk is provided.

Option II

1. Determine which subdirectory of the target directory (/home) occupies the most disk space.

2. Mount the disk partition to the subdirectory that takes up the most space, and the new files in this directory will be saved to the new disk partition from then on.

Option 2 is a compromise solution, and the operation is not thorough. However, it avoids the time-consuming situation of copying and can be used as a temporary operation . It also has many limitations.

Restriction 1 The applicability is not high. Assuming that each subdirectory of the target directory (/home) takes up a lot of space, the solution will not work at this time.

Restriction 2: It is inconvenient to maintain in the later stage , and it makes the colleagues in the operation and maintenance later feel very uncomfortable.

third solution

        If the target directory (/home) is a logical partition, you can expand the space by expanding the logical partition . This situation is the best, and the operation method is relatively the simplest. See below for details.


        The operations of Scheme 1 and Scheme 2 are relatively simple, and there are many articles on the Internet, so I won’t repeat them here. Only the operation steps of scenario three are discussed.

Precautions:

1. Be highly vigilant against operations that may cause data loss.

2. Novices should not directly operate the official server, it is best to demonstrate it on the local virtual machine first.

3. During the actual operation, there is a high probability that you will encounter strange problems, so be patient.

Logical partition (LVM) expansion

1. Determine whether the partition to be expanded is a logical partition

Use the lsblk command to determine whether the target partition is a logical partition. If the TYPE is lvm, it is a logical partition, otherwise it is not. Only logical partitions can use this method, remember. (The / partition will be used as the target partition here)

Goal: Split 5G from the blank disk sdb to the / directory.

2. Add the free partition to the specified virtual volume group

2.1 First separate the sdb1 partition from the disk sdb

Before that, we must first figure out how the logical partition (LV) is partitioned. As shown in the figure below, the space size of the logical partition (LV) is derived from the volume group. The larger the volume group, the larger the logical partition can be expanded. At the same time, if the logical partition space is not enough, free partitions can be allocated from the volume group to the logical partition at any time. The size of the volume group comes from the disk partition.

Obviously, the next thing we need to do is to add the sdb1 partition to the VG volume group, then the VG volume group will have free disk space, and finally allocate the free space of the VG volume group to the target logical volume. 

2.2 Determine the logical volume group information of the target directory

 2.3 Add the sdb1 partition to the same VG volume group

3. Allocate free space in the VG volume group to the target partition

So far, the expansion operation of the logical partition is completed.

reference article

In-depth understanding of file system inodes | Comparing Linux mv and cp commands - Short Book (jianshu.com)

Partition process Yuque (yuque.com)

Introduction to the method of directory expansion under the Linux system | "Linux should learn like this" (linuxprobe.com)

(1 message) LINUX - LVM principle and PV, VG, LV, PE, LE relationship diagram_ApacheCrazyFan's Blog-CSDN博客

Linux LVM Logical Partition - 01234567 - Blog Garden (cnblogs.com)

Guess you like

Origin blog.csdn.net/qq_41057885/article/details/125358508