[LINUX] I tried to expand the size of the logical volume with LVM

Just the other day, the capacity of the database server managed by our department became 100% and died, so I added a new disk and expanded the size of the logical volume with LVM to recover. I did. However, I didn't understand the meaning of this work, because I didn't know many words and knowledge. I reviewed it so that I could understand what I was doing there, so I will summarize it so that I will not forget it.

What is LVM in the first place?

A disk management function that can combine storage areas that span multiple hard disks and partitions into a single volume group and treat it as a single logical volume (LV).

is what they said. If you use this, you can expand the logical volume later, which is convenient. When I looked up LVM, I found a word I didn't know, so make a note.

- Physical volume </ b>: Refers to the hard disk or partition itself - Volume group </ b>: A collection of one or more physical volumes - Logical volume </ b>: Volume cut out from the volume group

Create a partition on a new disk

The added disk name is / dev / sdc. First, start fdisk in interactive mode with the following command

$ fdisk /dev/sdc

Then interactive mode will start, so create a partition by following the steps below.

Command (m for help): n #Create a new partition with n, various options will appear, but all by default

Command (m for help): t #Change partition type with t. Partition type=The type of file system using that partition
Partition number: 1
Hex code (type L to list codes) : 8e #8e is the Linux LVM partition number

Command (m for help): p #View partition table and partition/dev/Confirm that sdc1 is created

Command (m for help): w #Save and exit partition table changes

Create a physical volume on disk

Since we created partition / dev / sdc1 earlier, we created a physical volume to manage it with LVM.


$ pvcreate /dev/sdc1 #Physical volume creation

$ pvscan #/dev/Confirm that sdc1 is displayed as a physical volume

Register physical volume in volume group

Next, I created a physical volume earlier, but it has not yet been assigned to any volume group. So let's register it in an existing volume group.


$ vgextend centos /dev/sdc1 #Physical volumes in volume group centos/dev/Register sdc1

$ pvscan #/dev/Check if sdc1 belongs to volume group centos

Create a logical volume from a volume group

Allocate all the extended parts of the volume group to the logical volume.


$ lvextend -l +100%FREE /dev/centos/root

If you think this is the end, you must expand the file system or the file system will not be able to use the expanded part of the logical volume, so expand it. Then, the size of the logical volume should be expanded, so check with lvscan whether the target logical volume is expanded.


$ xfs_growfs /dev/centos/root #Extend file system

$ lvscan #Display a list of logical volumes.

Finally

This series of flow was a delicate degree of understanding that seemed to be understood at first, but I was convinced when I saw this image on the following site. https://www.atmarkit.co.jp/ait/articles/0302/08/news002_2.html

r5zu03.gif

Recommended Posts