This article is a sequel to the following page, so please read it before reading this article to deepen your understanding. RHCSA test preparation --General flow until using a physical drive as a data storage area on Linux OS (basic edition)
It seems that there are more cases of use in enterprise infrastructure than for workstations and general PC users.
In the case of Linux environment, unlike other OS such as Windows and VMware vSphere, the license is a subscription contract and there are no restrictions with functional differences like editions, so of course in the case of non-enterprise environment as described above But if you have a subscription contract, anyone can use it.
If you would like to know more about LVM, please check the following information.
Chapter 1 Logical Volumes-Red Hat Enterprise Linux 8 Linux Trivia 085 LVM (logical volume manager)-LinuC [Logical Volume Manager-Wikipedia](https://ja.wikipedia.org/wiki/%E8%AB%96%E7%90%86%E3%83%9C%E3%83%AA%E3%83%A5 % E3% 83% BC% E3% 83% A0% E3% 83% 9E% E3% 83% 8D% E3% 83% BC% E3% 82% B8% E3% 83% A3) Easy disk management with LVM --ITmedia
Now, let's take a look at each step according to the above flow.
yum install lvm2
Explanation Install lvm2 from the repository.
Since lvm itself is a very major package, the third line from the top said "already installed."
In the figure below, some commands are executed. I will put a commentary at the bottom of the figure.
First command lsblk-Visualization of the current drive configuration(sdb/sdc is already connected)
Second command pvdisplay-Current"Physical Volume"Check for the presence of(Only PVs that are automatically configured during initial installation are present)
Third command pvcreate/dev/sdb -Command to convert sdb to PV(However, the corresponding drive cannot be converted to PV and an error occurs.)
Fourth command pvcreate/dev/sdc -Command to convert sdc to PV(However, the corresponding drive cannot be converted to PV and an error occurs.)
Fifth command parted/dev/sdb print -Check sdb partition table(GPT format)
6th command parted/dev/sdc print -Check sdc partition table(GPT format)
The reason is that the partition table was created with two drives as GPT drives at the time of the previous verification. I hit this error. If you have never configured a partition table, you will not get this error. Since it was necessary to delete the partition table this time, we used the method described in the following article. RHCSA test preparation-How to delete partition table
We will create a PV again. I executed the following command, and the creation was completed normally and the status was confirmed.
pvcreate /dev/sdb - /dev/Convert sdb to PV
pvcreate /dev/sdc - /dev/Convert sdc to PV
pvdisplay -Display the PV recognized on the OS
Next, combine the two created PVs into one Volume Group.
First, before working, check the VG that exists on the OS.
vgdisplay
Explanation: Display the VG recognized on the OS
There is only one VG that was configured during the initial installation of CentOS.
We're going to create one VG, so you should see the other VG after you're done.
vgcreate Name you want to give to VG PV name you want to include in vg
Execution example vgcreate vg8010/dev/sdb /dev/sdc
Commentary/dev/with sdb/dev/One volume group using sdc"vg8010"Operation command to create a VG named
From the result of vgdisplay, it was confirmed that vg8010 is composed of about 40GB.
lvcreate -n The name you want to give to LV-L Number of capacities you want to reserve VG name hosting LV
Execution example lvcreate-n lv8010 -L 30G /dev/vg8010
Explanation LV with a capacity of 30GB"lv8010",/dev/Command to cut out from vg8010
At this point, all you have to do is format and mount.
This work is the same as that explained in the basic part of this series.
mkfs.ext4 partition you want to format
Execution example mkfs.ext4 /dev/vg8010/lv8010
mount The partition you want to mount The directory to mount to
Execution example mount/dev/vg8010/lv8010 /mnt/lvtest
Here's how you executed the commands in steps 5 and 6.
If you run lsblk, you can see that lvm8010 is cut out from sdb and sdc and mounted in / mnt / lvtest.
This completes the general flow of mounting in an LVM environment. Of course, for automatic mounting after rebooting, please do not forget to specify the UUID and mount destination for / etc / fstab. (The procedure is introduced in the basic part of this series, so please refer to that.)
In this environment, we configured 30GB LV for VG with 40GB size, so there is 10GB free space. So, I would like to extend the size of LV from 30GB to 35GB.
Command to check the size of the partition
parted /dev/vg8010/lv8010 print
In the figure below, the partition size is 32.You can see that it is 2GB
Next, let's check the current capacity of the file system.
Command to check the size of the file system
df -h
Also, I placed a file called "rhcsa" as a test file to confirm that it is an online extension (no data loss) work.
Now let's use two types of commands from here.
1.Logical volume"lv8010"Command to add 5GB capacity
lvextend LV name you want to extend-L +Capacity you want to add
Execution example lvextend/dev/vg8010/lv8010 -L +5G
2.Command for partition extension
resize2fs Target device name
Execution example resize2fs/dev/vg8010/lv8010
If you check the second line from the bottom in the above figure, the size of / dev / vg8010 / lv8010 has changed from 30GB to 35GB.
I was able to confirm that the file still exists after the work.