Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

7.2.1 Deploy the logical volume


May 23, 2021 That's what Linux should learn



In general, it is not possible to accurately assess the future usage of each hard drive partition in a production environment, resulting in insufficient hard disk partitions previously allocated. F or example, as the volume of business increases, so does the volume of the database catalog used to hold transactions, and because analyzing and recording the user's behavior results in the log catalog being larger, these can lead to overstretched use of the original hard disk partitions. Also, there are cases of thin shrinking of larger hard disk partitions.

We can solve these problems by deploying LVM. W hen you deploy LVM, you need to configure physical volumes, volume groups, and logical volumes one by one. Common deployment commands are shown in Table 7-2.

Table 7-2 Common LVM deployment commands

Features/Commands Physical Volume Management Volume Group Management Logical Volume Management Scan pvscan vgscan lvscan Establish Pvcreate vgcreate lvcreate Display pvdisplay vgdisplay lvdisplay Remove pvremove vgremove The vgextend lvextend zoomed-out vgreduce lvreduce to avoid conflicts between multiple experiments, restore the virtual machine to its original state, add two new hard drive devices to the virtual machine, and power on, as shown in Figure 7-8.

The purpose of adding two new hard disk devices to a virtual machine is to better demonstrate the characteristics of the LVM concept in which users do not have to care about the underlying physical hard disk devices. W e first create a physical volume for these two new hard drives, which can be simply understood as allowing the hard disk device to support LVM technology, or as adding the hard disk device to the pool of hardware resources available for LVM technology, and then combining the two hard drives with volumes, the name of the volume group can be customized by the user. N ext, according to the requirements of the merged volume group cut out a logical volume device of about 150MB, and finally format the logical volume device into an EXT4 file system for mounting use. In the following section, Mr. Liu will give a few more simple descriptions of each step.

Step 1: Let the newly added two hard drive devices support LVM technology.

[root@linuxprobe ~]# pvcreate /dev/sdb /dev/sdc Physical volume "/dev/sdb" successfully created Physical volume "/dev/sdc" successfully created

7.2.1 Deploy the logical volume Figure 7-8 Adds two new hard disk devices to the virtual machine

Step 2: Add two hard drive devices to the store volume group, and then check the status of the volume group.

[root@linuxprobe ~]# vgcreate storage /dev/sdb /dev/sdc Volume group "storage" successfully created [root@linuxprobe ~]# vgdisplay --- Volume group --- VG Name storage System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 39.99 GiB PE Size 4.00 MiB Total PE 10238 Alloc PE / Size 0 / 0 Free PE / S ize 10238 / 39.99 GiB VG UUID KUeAMF-qMLh-XjQy-ArUo-LCQI-YF0o-pScxm1 .................. O mit some of the output information... Step 3: Cut out a logic roll device of about 150MB.

Attention needs to be paid here to the problem of cutting units. T here are two units of measurement when cutting a logical volume. T he first is in capacity and uses a parameter of -L. F or example, use -L 150M to generate a logical volume of 150MB in size. T he other is in the number of basic units, using the parameter -l. T he size of each base cell defaults to 4MB. For example, using -l 37, you can generate a logical volume × size of 37 to 4MB to 148MB.

[root@linuxprobe ~]# lvcreate -n vo -l 37 storage Logical volume "vo" created [root@linuxprobe ~]# lvdisplay --- Logical volume --- LV Path /dev/storage/vo LV Name vo VG Name storage LV UUID D09HYI-BHBl-iXGr-X2n4-HEzo-FAQH-HRcM2I LV Write Access read/write LV Creation host, time localhost.localdomain, 2017-02-01 01:22:54 -0500 LV Status available

open 0

  1. LV Size 148.00 MiB
  2. Current LE 37
  3. Segments 1
  4. Allocation inherit
  5. Read ahead sectors auto
  6. - currently set to 8192
  7. Block device 253:2
  8. ………………省略部分输出信息………………

Step 4: Format the generated logical volume and mount it for use.

The Linux system stores the logical volume devices in the LVM in the /dev device directory (in effect, a symbolic link) and establishes a directory with the name of the volume group, which holds the device mapping file for the logical volume (i.e., /dev/volume group name/logical volume name).

[root@linuxprobe ~]# mkfs.ext4 /dev/storage/vo mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 38000 inodes, 151552 blocks 7577 blocks (5.00%) r eserved for the super user First data block=1 Maximum filesystem blocks=33816576 19 block groups 8192 blocks per group, 8192 fragments per group 2000 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729 Allocating group tables: done Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done ( root@linuxprobe . root@linuxprobe .

[root@linuxprobe ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/rhel-root 18G 3.0G 15G 17% / devtmpfs 905M 0 905M 0% /dev tmpfs 914M 140K 914M 1% /dev/shm tmpfs 914M 8.8M 905M 1% /run tmpfs 914M 0 914M 0% /sys/fs/cgroup /dev/sr0 3.5G 3.5G 0 100% /media/cdrom /dev/sda1 497M 119M 379M 24% /boot /dev/mapper/storage-vo 145M 7.6M 138M 6% /linuxprobe [root@linuxprobe ~]# echo "/ dev/storage/vo /linuxprobe ext4 defaults 0 0" >> /etc/fstab