RHCSA test preparation --General flow until using a physical drive as a data storage area on Linux OS (advanced version / when using LVM)

RHCSA test preparation --General flow until using a physical drive as a data storage area on Linux OS (advanced version / when using LVM)

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)

What is LVM? To put it simply, it is a function that provides the following functions for conventional partitions.
  1. Concatenate multiple partitions and treat them as one partition
  2. Providing partition size expansion and contraction function
  3. Providing snapshot function
  4. RAID-like mirroring and striping

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

Flow of partition mounting using LVM The basic flow is as follows. 1. Make sure LVM is installed 2. Configure Physical Volume 3. Configure Volume Group 4. Configure Logical Volume 5. Format the Logical Volume on the file system 6. Mount the file system formatted above

Now, let's take a look at each step according to the above flow.

1. Make sure LVM is installed ``` rpm -qa | grep lvm Explanation: Check the installed packages. In the above, only those containing the character string lvm are displayed. ``` It's a royal confirmation method. Alternatively, you can use the yum command to check for the existence of the package.
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." image.png

2. Configure Physical Volume The smallest unit that provides the capacity handled by LVM is "Physical Volume (hereinafter PV)". This time, I'm going to configure the two drives, / dev / sdb and / dev / sdc, to be treated as one Volume.

In the figure below, some commands are executed. I will put a commentary at the bottom of the figure. image.png

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

image.png Next, combine the two created PVs into one Volume Group.

3. Make up the Volume Group Volume Group (hereinafter VG) is a collection of one or more PVs. This time we will combine the two, / dev / sdb and / dev / sdc. The size of each drive is 20GB, so after work you will have one VG with a size of 40GB.

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. image.png

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. image.png

4. Configure Logical Volume Cut out a Logical Volume with a size of 30GB from the created VG with a size of 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

image.png 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.

5. Format the Logical Volume with a file system The state of command execution is posted in the latter half.
mkfs.ext4 partition you want to format
Execution example mkfs.ext4 /dev/vg8010/lv8010

6. Mount the file system formatted above The state of command execution is posted in the latter half.
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. image.png 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.)

Try expanding the size of LVM online One of the fascinating features of LVM is its non-disruptive capacity expansion.

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

image.png

Next, let's check the current capacity of the file system.

Command to check the size of the file system
df -h

image.png

Also, I placed a file called "rhcsa" as a test file to confirm that it is an online extension (no data loss) work. image.png 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

image.png 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. image.png

Try reducing the size of LVM Will be posted at a later date

Take a snapshot for an LVM volume Will be posted at a later date

Recommended Posts

RHCSA test preparation --General flow until using a physical drive as a data storage area on Linux OS (advanced version / when using LVM)
RHCSA test preparation --General flow until using a physical drive as a data storage area on Linux OS (Basic)