Linux expands the home directory

Linux expands the /home directory

Reprint address:After adding a new disk in Linux (centos), expand the capacity of the specified directory

In fact, the principle is the same as LVM logical volume expansion. The steps are:

  • Create a physical volume, which can be an entire disk or a partition (partitions need to be of LVM type).
  • Check which volume group /home or /root is in.
  • Volume group expansion.
  • /home logical volume expansion.
  • Format file system

Problem background

The server (linux system) has insufficient disk space. After mounting a new hard disk, is transparent to ordinary users and the designated directory expansion (such as / home) is the most direct method, which canavoid migrating data (directory copy) and do not affect the original partition< /span>
System release:, minimize the impact on the basic environment.

$ cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)

    
    
     
     
  • 1
  • 2

basic concept

Physical volume (PV, physical volume)
Logical volume (LV, logical volume)
Logical group (VG, volume group)LVM
Logical partition

Add a new disk to expand the capacity of the specified directory

The method is basically copied completelyUnder the Linux system, add a new hard disk and expand the existing /home directory.
Here is a record of part of the configuration process in your own environment. If there is anything unclear, please check the original steps;
CentOS8.4 expands the home directory a> is explained in more detail. It is best to read it carefully before doing it. After all, modifying the disk configuration is not a trivial matter, so be cautious.

View existing disk usage

Reference command:df -h, unmounted hard disk cannot be read

Add a new hard drive and view device information

Newly added hardware devices can be found in the /dev directory. The hard disk is usually /dev/fd*
View the newly added device information, fdisk -l, can view all disk information that can be read in the existing system (including unmounted hard disks, but this is slightly doubtful in different distributions).
You can further use cfdisk /dev/sd* to view the partition information of the target disk.

CreateLogical Volume

Create a logical volume for the newly added hard disk:pvcreate /dev/sdc
Prompt if successful

$ sudo pvcreate /dev/sdc
  Physical volume "/dev/sdc" successfully created.

    
    
     
     
  • 1
  • 2

At this time, you can view the newly added disk information through the pvdisplay command
![Insert picture description here](https://img-blog .csdnimg.cn/235c7f271ddc4f1fac7fcb9438c0afce.pngInsert image description here
What is added here is a 1.09TB hard drive

View LV information

View the logical volume information through thelvdisplay command, and focus on "LV Path|Name|Size"
![Insert picture description here]( https://img-blog.csdnimg.cn/9f63f5832f2e4e5aa3c5421798f475d7.pngInsert image description here

Expansion

Determine expansion information

directory, here we take the /home directory as an example.
Before expansion, use the command vgdisplay to view the vg information before expansion
Insert image description here

Execute expansion command

vgextend centos /dev/sdc, this will expand the disk capacity of the newly mounted disk to VG Name
Successful execution prompt

$ sudo vgextend centos /dev/sdc
  Volume group "centos" successfully extended

    
    
     
     
  • 1
  • 2

Check VG information again

vgdisplay
Insert image description here
Although VG has been expanded at this time, the lv information has not changed. The information viewed through the commands lvdisplay and df -h has not changed yet, that is, it has not changed yet. True expansion.

lv expansion

Execute commandlvextend -L +1T /dev/centos/home, command format
lvextend -L [+size,单位可以是M|G|T,不超过新加磁盘的空间] 待扩容的逻辑卷
Success prompt after execution
Insert image description here

This is, although the lv information has changed, butdf -hthere is still no change,

Reset logical volume

Note here, first use theblkid command to check the file system type
If it is Linux6.x, the command (ext format) is
resize2fs [参数]
If it is a linux7. , still valid
xfs_growfs [参数]
Insert image description here

Insert image description here

Precautions

  1. The above commands basically require administrator rights.
  2. The expansion operation is transparent to ordinary users; there is no need to migrate data;
  3. Restart the server without manually mounting a new disk

Relevant information

Same problem, here are some other methods, such as (detailed explanation) to solve the problem that the ubuntu root directory/ and user directory/home partitions are too small (remount home and other Directory),Introduction to the method of directory expansion under Linux system: After mounting a new hard disk, re-specify the directory. Redirect to a new disk partition, but the data needs to be completely migrated to the new disk. If the directory is large, the disk speed is slow and time-consuming (it is not clear whether the space in the original directory can be recycled and reused). The general method is that after modifying the redirection, you also need to modify the configuration file to ensure that the newly added disk is automatically mounted after restartingLINUX /home directory expansion.
There are also some methods to expand the capacity of a designated directory in a virtual machine environment, such as linux to expand /home memory capacity , it has not been tested whether it is effective in the physical machine environment.
[Solution] Linux disk expansion: new disk, original disk expansion, home partition root partition expansion
CentOS8.4 expansion of home directory

The knowledge points of the article match the official knowledge archives, allowing you to further learn related knowledge.
Cloud native entry skill treefront pageSummary 15050 Human correctness and system study middle

Problem background

The server (linux system) has insufficient disk space. After mounting a new hard disk, is transparent to ordinary users and the designated directory expansion (such as / home) is the most direct method, which canavoid migrating data (directory copy) and do not affect the original partition< /span>
System release:, minimize the impact on the basic environment.

$ cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)

    
    
  
  
  • 1
  • 2

basic concept

Physical volume (PV, physical volume)
Logical volume (LV, logical volume)
Logical group (VG, volume group)LVM
Logical partition

Add a new disk to expand the capacity of the specified directory

The method is basically copied completelyUnder the Linux system, add a new hard disk and expand the existing /home directory.
Here is a record of part of the configuration process in your own environment. If there is anything unclear, please check the original steps;
CentOS8.4 expands the home directory a> is explained in more detail. It is best to read it carefully before doing it. After all, modifying the disk configuration is not a trivial matter, so be cautious.

View existing disk usage

Reference command:df -h, unmounted hard disk cannot be read

Add a new hard drive and view device information

Newly added hardware devices can be found in the /dev directory. The hard disk is usually /dev/fd*
View the newly added device information, fdisk -l, can view all disk information that can be read in the existing system (including unmounted hard disks, but this is slightly doubtful in different distributions).
You can further use cfdisk /dev/sd* to view the partition information of the target disk.

CreateLogical Volume

Create a logical volume for the newly added hard disk:pvcreate /dev/sdc
Prompt if successful

$ sudo pvcreate /dev/sdc
  Physical volume "/dev/sdc" successfully created.

    
    
  
  
  • 1
  • 2

At this time, you can view the newly added disk information through the pvdisplay command
![Insert picture description here](https://img-blog .csdnimg.cn/235c7f271ddc4f1fac7fcb9438c0afce.pngInsert image description here
What is added here is a 1.09TB hard drive

View LV information

View the logical volume information through thelvdisplay command, and focus on "LV Path|Name|Size"
![Insert picture description here]( https://img-blog.csdnimg.cn/9f63f5832f2e4e5aa3c5421798f475d7.pngInsert image description here

Expansion

Determine expansion information

directory, here we take the /home directory as an example.
Before expansion, use the command vgdisplay to view the vg information before expansion
Insert image description here

Execute expansion command

vgextend centos /dev/sdc, this will expand the disk capacity of the newly mounted disk to VG Name
Successful execution prompt

$ sudo vgextend centos /dev/sdc
  Volume group "centos" successfully extended

    
    
  
  
  • 1
  • 2

Check VG information again

vgdisplay
Insert image description here
Although VG has been expanded at this time, the lv information has not changed. The information viewed through the commands lvdisplay and df -h has not changed yet, that is, it has not changed yet. True expansion.

lv expansion

Execute commandlvextend -L +1T /dev/centos/home, command format
lvextend -L [+size,单位可以是M|G|T,不超过新加磁盘的空间] 待扩容的逻辑卷
Success prompt after execution
Insert image description here

This is, although the lv information has changed, butdf -hthere is still no change,

Reset logical volume

Note here, first use theblkid command to check the file system type
If it is Linux6.x, the command (ext format) is
resize2fs [参数]
If it is a linux7. , still valid
xfs_growfs [参数]
Insert image description here

Insert image description here

Precautions

  1. The above commands basically require administrator rights.
  2. The expansion operation is transparent to ordinary users; there is no need to migrate data;
  3. Restart the server without manually mounting a new disk

Relevant information

Same problem, here are some other methods, such as (detailed explanation) to solve the problem that the ubuntu root directory/ and user directory/home partitions are too small (remount home and other Directory),Introduction to the method of directory expansion under Linux system: After mounting a new hard disk, re-specify the directory. Redirect to a new disk partition, but the data needs to be completely migrated to the new disk. If the directory is large, the disk speed is slow and time-consuming (it is not clear whether the space in the original directory can be recycled and reused). The general method is that after modifying the redirection, you also need to modify the configuration file to ensure that the newly added disk is automatically mounted after restartingLINUX /home directory expansion.
There are also some methods to expand the capacity of a designated directory in a virtual machine environment, such as linux to expand /home memory capacity , it has not been tested whether it is effective in the physical machine environment.
[Solution] Linux disk expansion: new disk, original disk expansion, home partition root partition expansion
CentOS8.4 expansion of home directory

Guess you like

Origin blog.csdn.net/weixin_53060366/article/details/132759434