LVM dynamic disk expansion management

Before:
Recently, some people often reported that because they didn’t know much about Linux partitions, they basically defaulted to it. Now the company’s project server database stores a certain partition is full, and they have to reinstall the operating system. Here I share an article about myself dynamic expansion experience

Introduction: LVM is the abbreviation of Logical Volume Manager. It is a mechanism for managing disk partitions in the Linux environment. LVM is a logical layer built on hard disks and partitions to improve disk partition management. flexibility. The LVM system administrator can easily manage disk partitions, such as connecting several disk partitions into a whole block volume group (volumegroup) to form a storage pool. Administrators can freely create logical volume groups (logical volumes) on volume groups, and further create file systems on logical volume groups. Administrators can easily adjust the size of storage volume groups through LVM, and can name, manage and allocate disk storage in groups.

Model diagram
insert image description here
Experimental environment:
a Linux server, two disks, one system comes with 20GB, one additional 20GB disk
imitates the system directory home/meishu disk is full, add a new disk, and increase the newly added capacity to the already full disk superior

1. When installing the operating system, select manual partitioning, change the disk type, and create a directory home/meishu, and allocate 20GB. 2. After installing the system, check the partition
insert image description here
df -h
insert image description here
2.1, check the volume group name and volume group usage vgdisplay (Keep in mind the name of VG name, it will be used when expanding the capacity later)
insert image description here
2.2, check the space status of the current logical volume lvdisplay
insert image description here
insert image description here
3, assuming that the capacity of the home_meishu volume group is not enough and needs to be expanded, now it is 20GB, let’s add a new one below 20GB disk, and then execute the fdisk -l command to check it.
insert image description here
4. The name of the newly added disk is dev/sdb. Next, start to format the partition operation, fdisk /dev/sdb

insert image description here

Five, continue the previous step (do not close) set the newly added disk to LVM mode,
insert image description here
confirm and save the partition
insert image description here

Sixth, create the newly added partition dev/sdb1 as a physical volume

insert image description here
7. Query the name of the volume group and expand the volume group.
insert image description here
Extend the physical volume dev/sdb1 to the centos_lvm volume group.
insert image description here
8. Extend all the free space to the directory home/meishu
insert image description here
. 9. At this time, although the 20G disk space has been expanded to the home/meishu It has not been written to the file system, enter etc/fstab to confirm the home/meishu file system—ext4
insert image description here
10, write to the file system to make the expansion take effect
insert image description here
11, check df -h
insert image description here
at this time it already has the sum of two disk capacities up! ! !

Summary of this expansion instruction
1. Create a partition#fdisk /dev/sdb

2. Create a physical volume #pvcreat /dev/sdb1

3. View volume group name and usage #vgdisplay

4. Extend the physical volume to the volume group #vgextend cl /dev/sdb1 (where 'cl' is the volume group name)

5. Extend the free space in the volume group to /home #lvextend -l +100%FREE /dev/mapper/cl-home

6. Refresh the file system to take effect after expansion #resize2fs /dev/mapper/cl-home

Use reiserfs file system instead of ext2/ext3 #resize_reiserfs /dev/mapper/cl-home

The default file system of Centos7 is 'xfs', and I chose 'ext4' when partitioning

Attached are some personal understandings of Linux partitions:
in Linux, everything is a file, and all devices and disks are hung in '/' in the form of files. The /var mentioned in this article, if you do not manually partition /var when installing the os, the system will create /var by default, but the maximum available storage space for /var created by the system is the size of '/'. In addition, only the boot files of linux os are stored in /boot or /boot/efi, so there is no need to divide them too much.
Summary: Choose LVM when installing the OS. When you run the database and find that the partition is not enough, you can use this method to achieve dynamic expansion without destroying the original files in the partition, let alone reinstalling the system.

Guess you like

Origin blog.csdn.net/weixin_44200830/article/details/118421275