LVM file system of the Logical Volume Manager

1, LVM Introduction

LVM is a Logical Volume Manager abbreviation, Chinese is the Logical Volume Manager.

  • Physical volume (PV, Physical Volume): is the real physical hard disk or partition.
  • Volume group (VG, Volume Group): a plurality of physical volumes together to form the volume group, physical volume consisting of a volume group with the same hard disk may be different partitions may be different in different partitions on the hard disk. We can imagine the volume group is a logical hard disk
  • Logical Volume (LV, Logical Volume): logical volume group is a hard, hard to be used after partition which we call logical volume. Logical volume and write data may be formatted. We can imagine the logical
    partition.
  • Physical extension (PE, Physical Extend): PE is the minimum unit for storing data, our data are actually written among PE, PE size is configurable, default is 4MB.
2, the establishment of LVM steps
  • First, the physical hard disk is divided into partitions need, of course, also be a physical hard block.
  • Then the physical partition becomes established physical volume (PV), the block can also be directly established as a hard disk physical volume.
  • Next, the physical volumes integrated into a volume group (VG). Volume Group would be able to dynamically adjust the size, and can be added to the volume group physical partitions, physical partitions can also be removed from the volume group.
  • The final step is to re-divided into a volume group logical volume (LV), of course, the logical volume is directly resized. We say that to be logical partition can imagine, so it needs to be formatted and mounted.
3, physical volume management
1, partition

Creating interactive way is to use fdisk command, but it needs to be noted that the ID system partition is no longer the default Linux partition ID No. 83, while we wanted to change the ID number 8e LVM

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    10487807     5242880   8e  Linux LVM
/dev/sdb2        10487808    14682111     2097152   8e  Linux LVM
/dev/sdb3        14682112    20973567     3145728   8e  Linux LVM
Establish PV

When you create a physical volume, we can say that is the entire hard drive are built into a physical volume, also can build a partition as a physical volume. If the entire hard drive should have been established as a physical volume, the following command

[root@localhost ~]# pvcreate [设备文件名]

[root@localhost ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.
[root@localhost ~]# pvcreate /dev/sdb2
  Physical volume "/dev/sdb2" successfully created.
[root@localhost ~]# pvcreate /dev/sdb3
  Physical volume "/dev/sdb3" successfully created.

或者

[root@localhost ~]# pvcreate /dev/sdb
Query PV
1)pvscan
[root@localhost ~]# pvscan 
  PV /dev/sdb3                      lvm2 [3.00 GiB]
  PV /dev/sdb2                      lvm2 [2.00 GiB]
  PV /dev/sdb1                      lvm2 [5.00 GiB]
  Total: 4 [<29.00 GiB] / in use: 1 [<19.00 GiB] / in no VG: 3 [10.00 GiB]
2)pvdisplay
  "/dev/sdb1" is a new physical volume of "5.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1   物理卷名
  VG Name                           所属卷组名
  PV Size               5.00 GiB    物理卷大小
  Allocatable           NO          是否已经分配
  PE Size               0           PE大小
  Total PE              0           总共PE
  Free PE               0           空闲PE数
  Allocated PE          0           可分配PE
  PV UUID               3TGUYI-7y28-ilGh-uNus-FJfZ-3mn2-a1E2MM  UUID
4) delete the physical volume
[root@localhost ~]# pvremove /dev/sdb3 
4, volume groups
1, the establishment of volume group
[root@localhost ~]# vgcreate [选项] 卷组名 物理卷名 
选项:  
-s PE 大小:指定 PE 的大小,单位可以是 MB,GB,TB 等。如果不写默认 PE 大小事 4MB  

We have three physical volumes / dev / sdb1-3, we first / dev / sdb1 and / dev / sdb2 volume group is added, keep the / dev / sdb3 adjusted volume group size experiments

[root@localhost ~]# vgcreate -s 2Mb  vg1 /dev/sb1 /dev/sdb2
2, view the volume group
1)vgscan
[root@localhost ~]# vgscan
  Reading volume groups from cache.
   Found volume group "vg1" using metadata type lvm2

2)vgdisplay
[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               vg1   卷组名
  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               <7.00 GiB  卷组大小
  PE Size               2.00 MiB   PE大小
  Total PE              3582      总共PE数
  Alloc PE / Size       0 / 0   
  Free  PE / Size       3582 / <7.00 GiB   空闲PE数
  VG UUID               nffn4l-fnbY-n6ar-zy7v-PgKP-guw2-TTTOHz
3, delete the volume group
[root@localhost ~]# vgremove vg1
4, to increase the volume capacity of the group
[root@localhost ~]# vgextend  vg1 /dev/sdb3
  Volume group "vg1" successfully extended
5, to reduce the volume capacity of the group
[root@localhost ~]# vgreduce vg1 /dev/sdb3
  Removed "/dev/sdb3" from volume group "vg1"
5, logical volume management
1, the establishment of a logical volume
[root@localhost ~]# lvcreate [选项] [-n 逻辑卷名] 卷组名 
选项:  
-L 容量:指定逻辑卷大小,单位 MB,GB,TB 等  
-l 个数:按照 PE 个数指定逻辑卷大小
-n 逻辑卷名:指定逻辑卷名 

#建立一个2G的逻辑卷
[root@localhost ~]# lvcreate -L 2G -n lv1  vg1 
  Logical volume "lv1" created.

After establishing lv1 logical to 2GB vg1 volume group, after which they formatting and mount logical volumes to normal use. When the mount command and formatting and partitioning ordinary operation is the same, but it needs to be noted that the logical volume device file name is / dev / volume group / logical name,
example:

[root@localhost ~]# mkfs.ext4 /dev/vg1/lv1 
 # 格式化,建立文件系统 
[root@localhost ~]# mkdir /lv1  &&  mount /dev/vg1/lv1 /lv1/   
# 建立挂载点,并挂载
2, see Logical Volume

1)lvscan

[root@localhost ~]# lvscan
  ACTIVE            '/dev/centos/swap' [2.00 GiB] inherit
  ACTIVE            '/dev/centos/root' [<17.00 GiB] inherit
  ACTIVE            '/dev/vg1/lv1' [2.00 GiB] inherit

2)lvdisplay

  LV Path                /dev/vg1/lv1
  LV Name                lv1
  VG Name                vg1
  LV UUID                jGYU0t-hEzP-BgNw-TgdT-iXDU-oqwt-S2KjT8
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2019-12-05 22:19:48 -0500
  LV Status              available
  # open                 1
  LV Size                2.00 GiB
  Current LE             1024
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2
3, adjust the size of the logical volume
[root@localhost ~]# lvresize [选项] 逻辑卷设备文件名 
选项:  
-L 容量:安装容量调整大小,单位 KB,GB,TB 等。使用+代表增加空间,-号代表减少空间。如果直接写容量,代表设定逻辑卷大小为指定大小。  
-l 个数:按照 PE 个数调整逻辑卷大小 

#调整/dev/vg1/lv1 大小为3G
[root@localhost ~]# lvresize -L +1G /dev/vg1/lv1
  Size of logical volume vg1/lv1 changed from 2.00 GiB (1024 extents) to 3.00 GiB (1536 extents).
  Logical volume vg1/lv1 successfully resized.

#查看
[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/vg1-lv1      2.0G  6.0M  1.8G   1% /lv1

#但是此时大小还是没有变化怎么,刚刚只是逻辑卷的大小改变了,如果需要让分区使用这个新逻辑卷,我们还要使用 resize2fs 命令来调整分区的大小。
不过这里就体现了 LVM 的优势,我们不需要卸载分区,直接就能调整分区的大小。

[root@localhost ~]# resize2fs [选项] [设备文件名] [调整的大小] 
选项:  -f: 强制调整  
设备文件名:指定调整哪个分区的大小  调整的大小:指定把分区调整到多大,要加 M,G 等单位。如果不加大小,会使用整个分区

[root@localhost ~]# resize2fs -f /dev/vg1/lv1
resize2fs 1.42.9 (28-Dec-2013)
The filesystem is already 786432 blocks long.  Nothing to do! 
4) Removing a Logical Volume

You want to delete the logical volume, you need to be unmounted

[root@localhost ~]# lvremove 逻辑卷设备文件名 

[root@localhost ~]# umount /dev/vg1/lv1 
[root@localhost ~]# lvremove /dev/vg1/lv1 

Guess you like

Origin www.cnblogs.com/hjnzs/p/11994411.html