The previous article introduced lvm, and today I will demonstrate the process of making lvm. The production process of lvm has the following steps:
Disk partition
Use partition to make pv
Create vg with pv
Split lv from vg
Format lv and mount it to the directory using
Next, let’s complete the above process.
Partition
First, let’s take a look at the partitioning of the disk.
# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 40G 0 disk ├─sda1 8:1 0 2M 0 part ├─sda2 8:2 0 1G 0 part /boot ├─sda3 8:3 0 1G 0 part [SWAP] ├─sda4 8:4 0 10G 0 part / └─sda5 8:5 0 100M 0 part sdb 8:16 0 1G 0 disk sdc 8:32 0 1G 0 disk sdd 8:48 0 1G 0 disk sde 8:64 0 1G 0 disk
As you can see, there are 5 disks on my host. Except for the sda disk, the other disks have not been partitioned. In addition, the sda disk also has remaining space. Now, partition the other 4 disks as well. Use the fdisk or gdisk tool to partition, and the specific process is omitted here. After partitioning, the information is as follows:
# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 40G 0 disk ├─sda1 8:1 0 2M 0 part ├─sda2 8:2 0 1G 0 part /boot ├─sda3 8:3 0 1G 0 part [SWAP] ├─sda4 8:4 0 10G 0 part / └─sda5 8:5 0 100M 0 part sdb 8:16 0 1G 0 disk └─sdb1 8:17 0 1023M 0 part sdc 8:32 0 1G 0 disk └─sdc1 8:33 0 1023M 0 part sdd 8:48 0 1G 0 disk └─sdd1 8:49 0 1023M 0 part sde 8:64 0 1G 0 disk └─sde1 8:65 0 1023M 0 part
Making pv
First, we need to install the lvm2 software.
yum install lvm2
There are several related commands about pv:
pvscan View pv on the system
pvdisplay List pv Usage
pvcreate Make pv
pvremove Delete the pv, even if a partition does not have the pv attribute
Now we use partitions to make pv.
Usage: pvcreate partition...
# pvcreate /dev/sdb1 /dev/sdc1 Physical volume "/dev/sdb1" successfully created. Physical volume "/dev/sdc1" successfully created. # 这样就制作好了两个pv
The following uses pvscan to view all pvs on the system
# pvscan PV /dev/sdc1 lvm2 [1023.00 MiB] PV /dev/sdb1 lvm2 [1023.00 MiB] Total: 2 [<2.00 GiB] / in use: 0 [0 ] / in no VG: 2 [<2.00 GiB] # 共有2个pv,总大小2G左右,0个pv被使用
View the usage of a certain pv: pvdispaly [partition name]
# pvdisplay /dev/sdb1 "/dev/sdb1" is a new physical volume of "1023.00 MiB" --- NEW Physical volume --- PV Name /dev/sdb1 VG Name PV Size 1023.00 MiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID 6sl1Eg-S6BJ-1QYX-NAFs-9dIB-zEKN-jz7lYM
Then, we will delete these two PVs
# pvremove /dev/sd{b,c}1 Labels on physical volume "/dev/sdb1" successfully wiped. Labels on physical volume "/dev/sdc1" successfully wiped.
Finally, let’s make 3 PVs
# pvcreate /dev/sd{b,c,d}1 Physical volume "/dev/sdb1" successfully created. Physical volume "/dev/sdc1" successfully created. Physical volume "/dev/sdd1" successfully created.
Make vg
vg also has several related commands, as follows:
vgcreate makes vg. This command is the most complex of these commands.
vgscan Browse vg on the system
vgremove Delete a vg
vgdisplay View vg Usage
vgextend Expand vg, that is, add pv
vgreduce Remove pv from vg
First look at the command to make vg:
vgcreate [-s N[m|g|t]] vg name pv name
Options and parameters:
-s is followed by size, m, g, t can be in upper or lower case, and is used to set the pe size. If you omit this parameter, the default size will be used, which is generally 4M
vg name: Unlike the pv process, you need to customize the name of the vg here,
PV name, which PVs made vg.
Let’s make vg
# vgcreate vgwww /dev/sd{b,c,d}1 Volume group "vgwww" successfully created
Browse what vg has
# vgscan Reading volume groups from cache. Found volume group "vgwww" using metadata type lvm2
Check the relevant information of vg
# vgdisplay --- Volume group --- VG Name vgwww System ID Format lvm2 Metadata Areas 3 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 3 Act PV 3 VG Size <2.99 GiB PE Size 4.00 MiB Total PE 765 Alloc PE / Size 0 / 0 Free PE / Size 765 / <2.99 GiB VG UUID pd3HIi-NnES-DsdO-d35L-qoJB-OrwI-vkhfqV
Now we have vgwww Perform expansion operations
# vgextend vgwww /dev/sde1 Volume group "vgwww" successfully extended
Create lv
There are also some related commands for lv, as follows:
lvcreate: Make lv
lvscan: Query the lv on the system
lvdisplay: Display the status of lv
lvextend: Increase lv capacity
lvreduce: Reduce lv capacity
# lvcreate -L 1G -n lvwww vgwww Logical volume "lvwww" created. # lvscan ACTIVE '/dev/vgwww/lvwww' [1.00 GiB] inherit
# vgdisplay vgwww --- Volume group --- VG Name vgwww System ID Format lvm2 Metadata Areas 4 Metadata Sequence No 5 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 4 Act PV 4 VG Size 3.98 GiB PE Size 4.00 MiB Total PE 1020 Alloc PE / Size 256 / 1.00 GiB Free PE / Size 764 / 2.98 GiB <=== 还有剩余3G的空间 VG UUID pd3HIi-NnES-DsdO-d35L-qoJB-OrwI-vkhfqV # lvresize -L +1G /dev/vgwww/lvwww Size of logical volume vgwww/lvwww changed from 1.00 GiB (256 extents) to 2.00 GiB (512 extents). Logical volume vgwww/lvwww successfully resized.
Format and mount
/dev/vgwww/lvwww It is equivalent to a partition. If you want to use the partition, you need to format it first, and then mount it using# mkfs.xfs /dev/vgwww/lvwww # blkid …… /dev/mapper/vgwww-lvwww: UUID="fcbff612-a169-4542-ad92-6d53abe7b982" TYPE="xfs" # mount /dev/vgwww/lvwww /www [root@localhost ~]# df -h …… /dev/mapper/vgwww-lvwww 2.0G 33M 2.0G 2% /www
The above is the detailed content of Demonstration of the production process of lvm software under linux. For more information, please follow other related articles on the PHP Chinese website!