Centos7 uses LVM to achieve dynamic expansion method

Abstract: Recently, many newcomers have come to the project team. They don’t understand Linux partitions and the partitions used by various applications. When testing the database, they suddenly found that a certain partition was full and had to reinstall the OS. I can’t stand it anymore. I hereby share some of my experience using LVM to achieve dynamic expansion, I hope it will be helpful to everyone.

Knowledge reserve:

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 the flexibility of disk partition management . Through LVM system administrators can easily manage disk partitions, such as connecting several disk partitions into a single volume group to form a storage pool. Administrators can create logical volume groups (logicalvolumes) on the volume group at will, and further create file systems on the logical volume group. The administrator can easily adjust the size of the storage volume group through LVM, and can name, manage and allocate the disk storage according to the group.

The LVM model is as follows:

  1. When installing the OS, select manual partitioning, and select LVM for Device Type. Mysql/Mariadb data is stored in /var, and oracle data is stored in /home, so when manually partitioning, please divide /var and /home into larger ones according to the actual disk size. The following partitions are for demonstration purposes only:

  1. After installing the OS, enter the system and check the partitions. You can see the three partitions using LVM when installing the system: /, /home, /var

  1. I forgot to create a root account when installing os, but it’s okay, execute'sudosu root' and enter the current login user password to get some root permissions

  1. View the volume group name and volume group usage vgdisplay

  1. View the space status of the current logical volume, as shown below: /50G, /var 200G, /home 100G, swap 20G

  1. Now I feel that /home 100G is not enough, and I want to expand the capacity to 120G, and insert a new 20G hard drive; use'fdisk -l' to view

  1. Format partition operation'fsdisk/dev/sdb'

  1. Set the newly added disk to LVM mode

Confirm partition

  1. Create the newly added partition /dev/sdb1 as a physical volume

  1. Expand the volume group'cl', and expand the physical volume /dev/sdb1 to the'cl' volume group

At this time, the volume group'cl' has 20G free space, and /dev/sdb1, expand it all to /home

  1. At this time, although the 20G disk has been expanded to /home, it has not been written into the file system; enter /etc/fstab to confirm the /home file system—>ext4

  1. Write to the file system to make the expansion take effect

  1. If it is an xfs file system, use'xfs_growfs /dev/mapper/cl-home'; to view /home, the expansion has been achieved. That's it!

Summary of this expansion instruction:

  1. Create partition #fdisk /dev/sdb

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

  3. View the 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. Refreshing the file system is the expansion effect #resize2fs /dev/mapper/cl-home

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

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

**Project actual combat: **

MPX ran the disk to fill/full, resulting in GUI inaccessible, use this method to / dynamically expand, the GUI is back, hahaha

Before expansion

After expansion

GUI is back

Also attached are some personal knowledge of Linux partitions:

In Linux, everything is a file, and all devices and disks are hung on the'/' in the form of files. For /var mentioned in this article, if you do not manually partition /var when installing 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, like /boot or /boot/efi, only the linux os boot files are stored, there is no need to divide them too much.

Summary: Choose LVM when installing os. When running the database and finding that the partition is not enough, you can use this method to dynamically expand without destroying the original files in the partition, let alone reinstalling the system. Mom no longer has to worry about my partition size !

The above is the whole content of this article, I hope it will be helpful to everyone's study.

Recommended Posts

Centos7 uses LVM to achieve dynamic expansion method
Centos8 uses yum to install mongodb 4.2 method
Centos7.6 method to install Tomcat-8.5.39
Centos6 method steps to build gitlab
CentOS 6.8 method steps to install vsftpd
Centos7 uses vim to build powerful pyt
Centos install sshfs to achieve mount directory
Explain Centos7 Expansion Disk Space (LVM Management)
Centos7 uses yum to install pip, ipython
Summary of CentOS method to set static IP
Centos7 uses yum to install Apache, mariadb, PHP
LVM disk expansion problem of Centos7 in Linux
Centos7 uses Ansible to install Chinese fonts in batches
CentOS uses Nginx to build a download function server
Online expansion of file system by LVM under Centos7