Linux磁盘条带化--LVM

什么是磁盘条带化

条带(stripe)是把连续的数据分割成相同大小的数据块,把每段数据分别写入到阵列中的不同磁盘上的方法。对操作系统层面来说是一种系统磁盘I/O负载均衡策略。

当多个进程同时访问磁盘时,会出现磁盘冲突。大多数磁盘系统都对访问次数(每秒的I/O操作)和数据传输率(每秒传输的数据量)有限制。当达到这些限制时,后面需要访问磁盘的进程就需要等待,这就是所谓的磁盘冲突。磁盘条带化将一块连续的数据分成很多小部分,并把它们分别存储到不同磁盘上。(这里不同磁盘一般是指磁盘阵列)这样进程在访问数据的时候,可以同时向多个不同部分同时发出I/O请求,由于这些数据存放在不同的磁盘上,因而不会造成磁盘冲突,而且在需要对这种数据进行顺序访问的时候可以获得最大程度上的I/O并行能力,从而获得非常好的性能。很多操作系统、磁盘设备供应商、各种第三方软件都能做到条带化。

什么是LVM

LVM是 Logical Volume Manager(逻辑卷管理)的简写,它是Linux环境下对磁盘分区进行管理的一种机制,它由Heinz Mauelshagen在Linux 2.4内核上实现。

磁盘条带化方案分软硬两种,硬件层面的方案主要是通过外接式磁盘整列柜和内接式磁盘整列卡两种,将物理磁盘组成RAID;软件层面是依靠软件做仿真,Linux中流行的是LVM软件。

LVM技术通过在硬盘分区和文件系统之间增加一个逻辑层,提供了一个抽象的卷组,这样就可以把多块硬盘设备、硬盘分区,甚至RAID整体进行卷组合并。并可以根据情况进行逻辑上的虚拟分割,这样一来,用户不用关心物理硬盘设备的底层架构和布局,就可以实现对硬盘分区设备的动态调整。LVM适合于管理大存储设备,LVM最大的特点就是可以对磁盘进行动态管理。因为逻辑卷的大小是可以动态调整的,而且不会丢失现有的数据。我们如果新增加了硬盘,其也不会改变现有上层的逻辑卷。作为一个动态磁盘管理机制,逻辑卷技术大大提高了磁盘管理的灵活性!

使用LVM

LVM有几个概念:

  • PD Physical Disk,物理磁盘,对应实际的存储设备,比如/dev/sda。
  • PP Physical Partition,物理分区,对应磁盘设备的分区,比如/dev/sda设备划分出来的/dev/sda{1..4}四个分区
  • PE Physical Extend,物理拓展,是卷组中的基本分配单元。每个物理卷都会被划分成多个大小相等的 PE,默认的 PE 大小可以在创建卷组时指定,通常为 4MB。当创建逻辑卷时,LVM 会将若干 PE 分配给逻辑卷,逻辑卷的大小实际上就是 PE 大小的倍数。PE 和 PP(物理分区)可以看作是类似的概念,不过 PE 是 LVM 的概念,而 PP 是传统分区管理中的概念。
  • PV Physical Volume,物理卷,是 LVM 的基础存储单元,LVM 会在多个物理卷上执行数据的管理和分布操作。
  • VG Volume Group,卷组,将多个物理卷组合在一起形成的一个存储池。它是逻辑卷的管理单元,所有的逻辑卷都是在卷组基础上创建的。卷组可以由多个物理卷组成,形成一个统一的大空间。这个空间可以用来创建多个逻辑卷。 当需要扩展存储时,可以向卷组中添加新的物理卷,而不会影响逻辑卷的正常运行。
  • LV Logical Volume,逻辑卷,是 LVM 提供给用户实际使用的虚拟存储设备,类似于传统分区,可以像对待物理磁盘分区一样对其格式化、挂载文件系统等。逻辑卷的大小可以动态调整(扩展或缩小),不需要重新分区或格式化。逻辑卷是从卷组中分配的空间,用户可以根据需要创建多个逻辑卷,类似于创建多个分区。

通过一个案例学习一下LVM的使用。

有个需求如下图,有四块硬盘,均为10GB空间大小,现在希望创建两个存储池,一个存储池vg1划分15G空间,另一个存储池vg2划分25G空间。vg1存储池希望目前先实例化一个5G大小的挂载点lv1出来,给应用使用,等后续空间不够了再扩展lv1的空间大小。vg2存储池划分两个挂载点lv1为10G,lv2为5G空间,由于lv2应用流量比较大,后续可能要再扩展10G空间出来。

lvm

创建物理卷

在创建物理卷之前,需要先将 /dev/sdc 存储设备分区。

# 罗列块信息
root@localhost:~# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda               8:0    0   32G  0 disk
├─sda1            8:1    0    1M  0 part
├─sda2            8:2    0    1G  0 part /boot
└─sda3            8:3    0   31G  0 part
  └─fedora-root 253:0    0   15G  0 lvm  /
sdb               8:16   0   10G  0 disk
sdc               8:32   0   10G  0 disk
sdd               8:48   0   10G  0 disk
sde               8:64   0   10G  0 disk
sr0              11:0    1 1024M  0 rom
zram0           252:0    0  7.7G  0 disk [SWAP]

# 将/dev/sdc设备分区成 /dev/sdc1 /dev/sdc2
root@localhost:~# fdisk /dev/sdc

Welcome to fdisk (util-linux 2.40.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS (MBR) disklabel with disk identifier 0xb6e8a013.

Command (m for help): m # 查看帮助信息

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition
   e   resize a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty MBR (DOS) partition table
   s   create a new empty Sun partition table


Command (m for help): p # 罗列分区信息
Disk /dev/sdc: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: VBOX HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xb6e8a013

Command (m for help): d # 如果有分区就把旧分区删除掉
No partition is defined yet!

Command (m for help): n # 新建磁盘分区
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p # 创建主分区
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-20971519, default 20971519): +5G # 分配5G空间大小

Created a new partition 1 of type 'Linux' and of size 5 GiB.

Command (m for help): n # 创建第二个分区
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2):
First sector (10487808-20971519, default 10487808):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (10487808-20971519, default 20971519):

Created a new partition 2 of type 'Linux' and of size 5 GiB.

Command (m for help): w # 写入分区信息
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

再次查看块设备信息 /dev/sdc1 /dev/sdc2 已经创建出来了

root@localhost:~# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda               8:0    0   32G  0 disk
├─sda1            8:1    0    1M  0 part
├─sda2            8:2    0    1G  0 part /boot
└─sda3            8:3    0   31G  0 part
  └─fedora-root 253:0    0   15G  0 lvm  /
sdb               8:16   0   10G  0 disk
sdc               8:32   0   10G  0 disk
├─sdc1            8:33   0    5G  0 part
└─sdc2            8:34   0    5G  0 part
sdd               8:48   0   10G  0 disk
sde               8:64   0   10G  0 disk
sr0              11:0    1 1024M  0 rom
zram0           252:0    0  7.7G  0 disk [SWAP]

使用 pvcreate 创建物理卷

root@localhost:~# pvcreate /dev/sdc{1,2} /dev/sd{b,d,e}
  Physical volume "/dev/sdc1" successfully created.
  Physical volume "/dev/sdc2" successfully created.
  Physical volume "/dev/sdb" successfully created.
  Physical volume "/dev/sdd" successfully created.
  Physical volume "/dev/sde" successfully created.

使用 pvs 查看物理卷列表

root@localhost:~# pvs
  PV         VG     Fmt  Attr PSize   PFree
  /dev/sda3  fedora lvm2 a--  <31.00g <16.00g
  /dev/sdb          lvm2 ---   10.00g  10.00g
  /dev/sdc1         lvm2 ---    5.00g   5.00g
  /dev/sdc2         lvm2 ---   <5.00g  <5.00g
  /dev/sdd          lvm2 ---   10.00g  10.00g
  /dev/sde          lvm2 ---   10.00g  10.00g

或者通过 pvdisplay 查看物理卷的详细信息

root@localhost:~# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               fedora
  PV Size               <31.00 GiB / not usable 0
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              7935
  Free PE               4095
  Allocated PE          3840
  PV UUID               7BDOS1-1FxF-zA34-tylK-4eKo-dwNw-WuMnwv

  "/dev/sdb" is a new physical volume of "10.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb
  VG Name
  PV Size               10.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               epZAiA-BcPQ-aNEp-O41j-8TVN-gC7C-og0XER

  "/dev/sdc1" is a new physical volume of "5.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc1
  VG Name
  PV Size               5.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               eCJhVu-VKY9-cVr7-2RYo-ZC0K-BjRN-MMiosx

  "/dev/sdc2" is a new physical volume of "<5.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc2
  VG Name
  PV Size               <5.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               OQLZFh-0upw-MeUm-TZri-F4WN-Xlv4-ProdsX

  "/dev/sdd" is a new physical volume of "10.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdd
  VG Name
  PV Size               10.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               GkzPvZ-RrwQ-h2Vs-2sez-Ta6i-QJt5-5WoTvO

  "/dev/sde" is a new physical volume of "10.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sde
  VG Name
  PV Size               10.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               cxepbm-CLzL-dneQ-s0jl-2uPX-HT3I-edEvdB

创建卷组

通过图示,vg1由/dev/sdb和/dev/sdc1组成,vg2由/dev/sdc2,/dev/sdd,/dev/sde组成。通过vgcreate命令将他们组成卷组。

# 第一个参数是卷组名 后续可以跟多个PV名称
root@localhost:~# vgcreate vg1 /dev/sdb /dev/sdc1
  Volume group "vg1" successfully created
root@localhost:~# vgcreate vg2 /dev/sdc2 /dev/sdd /dev/sde
  Volume group "vg2" successfully created

当希望扩展卷组时,可以使用 vgextend 命令

root@localhost:~# vgextend vg2 /dev/sdf /dev/sdg
  Volume group "vg2" successfully extended

可以通过 vgs 命令查看卷组列表

root@localhost:~# vgs
  VG     #PV #LV #SN Attr   VSize   VFree
  fedora   1   1   0 wz--n- <31.00g <16.00g
  vg1      2   0   0 wz--n-  14.99g  14.99g
  vg2      3   0   0 wz--n- <24.99g <24.99g

也可以通过 vgdisplay 命令查看卷组详细信息

root@localhost:~# vgdisplay
  --- Volume group ---
  VG Name               vg2
  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               <24.99 GiB
  PE Size               4.00 MiB
  Total PE              6397
  Alloc PE / Size       0 / 0
  Free  PE / Size       6397 / <24.99 GiB
  VG UUID               2lUKgA-afkl-iZfI-2Xdv-yWxX-SJX3-WZEvG2

  --- Volume group ---
  VG Name               fedora
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <31.00 GiB
  PE Size               4.00 MiB
  Total PE              7935
  Alloc PE / Size       3840 / 15.00 GiB
  Free  PE / Size       4095 / <16.00 GiB
  VG UUID               csfcrM-lYI3-oLG6-59sA-F3rt-Acep-QpPWuE

  --- 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               14.99 GiB
  PE Size               4.00 MiB
  Total PE              3838
  Alloc PE / Size       0 / 0
  Free  PE / Size       3838 / 14.99 GiB
  VG UUID               UGAaPT-zHSN-SSq4-cXNw-CiZ3-EyEU-UbdP5O

创建逻辑卷

依照要求,从vg1中创建一个初始大小5G空间的lv1,从vg2创建一个初始大小10G的lv1,初始大小5G的lv2

与前面创建 pv,vg类似,创建逻辑卷lv的命令是lvcreate

# 第一个参数指定哪个卷组 后续指定参数 --name 逻辑卷名称 --size 逻辑卷分配大小
root@localhost:~# lvcreate vg1 --name lv1 --size 5G
  Logical volume "lv1" created.
root@localhost:~# lvcreate vg2 --name lv1 --size 10G
  Logical volume "lv1" created.
root@localhost:~# lvcreate vg2 --name lv2 --size 5G
  Logical volume "lv2" created.

使用 lvs 查看逻辑卷列表

root@localhost:~# lvs
  LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root fedora -wi-ao---- 15.00g
  lv1  vg1    -wi-a-----  5.00g
  lv1  vg2    -wi-a----- 10.00g
  lv2  vg2    -wi-a-----  5.00g

使用 lvdisplay 查看逻辑卷详细信息

root@localhost:~# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg2/lv1
  LV Name                lv1
  VG Name                vg2
  LV UUID                KfXIbQ-Qy81-lnFZ-loqc-25uR-0zsH-D2X7bu
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2025-01-01 02:20:00 +0800
  LV Status              available
  # open                 0
  LV Size                10.00 GiB
  Current LE             2560
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

  --- Logical volume ---
  LV Path                /dev/vg2/lv2
  LV Name                lv2
  VG Name                vg2
  LV UUID                AwTuO2-wXmG-jZFt-kxPS-6HrZ-ON1Y-Lryv3v
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2025-01-01 02:20:12 +0800
  LV Status              available
  # open                 0
  LV Size                5.00 GiB
  Current LE             1280
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3

  --- Logical volume ---
  LV Path                /dev/fedora/root
  LV Name                root
  VG Name                fedora
  LV UUID                FMiHAW-Ig7D-MJ6G-ySXm-O2Zp-dVuZ-N7r4gw
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2025-01-01 01:09:44 +0800
  LV Status              available
  # open                 1
  LV Size                15.00 GiB
  Current LE             3840
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/vg1/lv1
  LV Name                lv1
  VG Name                vg1
  LV UUID                8QaxjQ-7FaI-hBqS-3nRY-u3Oh-Zyi7-fngIGN
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2025-01-01 02:18:13 +0800
  LV Status              available
  # open                 0
  LV Size                5.00 GiB
  Current LE             1280
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

创建文件系统

通过上面的命令,已经创建出来了vg1卷组的lv1,vg2卷组的lv1和lv2这三个逻辑卷,现在可以将他们当做块设备来使用了,我们对这三个逻辑卷做文件系统的初始化就可以正常使用了。

root@localhost:~# mkfs.ext4 /dev/vg1/lv1
mke2fs 1.47.1 (20-May-2024)
创建含有 1310720 个块(每块 4k)和 327680 个 inode 的文件系统
文件系统 UUID:8ec609ed-5fed-4dce-8a9b-ee9cebee0c1e
超级块的备份存储于下列块:
        32768, 98304, 163840, 229376, 294912, 819200, 884736

正在分配组表:完成
正在写入 inode表:完成
创建日志(16384 个块):完成
写入超级块和文件系统账户统计信息:已完成

root@localhost:~# mkfs.ext4 /dev/vg2/lv1
mke2fs 1.47.1 (20-May-2024)
创建含有 2621440 个块(每块 4k)和 655360 个 inode 的文件系统
文件系统 UUID:9e3b6cb0-6c65-4a73-8756-4eb82dd58292
超级块的备份存储于下列块:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

正在分配组表:完成
正在写入 inode表:完成
创建日志(16384 个块):完成
写入超级块和文件系统账户统计信息:已完成

root@localhost:~# mkfs.xfs /dev/vg2/lv2
meta-data=/dev/vg2/lv2           isize=512    agcount=4, agsize=327680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=1
         =                       reflink=1    bigtime=1 inobtcount=1 nrext64=1
data     =                       bsize=4096   blocks=1310720, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=16384, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

我们做一下磁盘挂载看看

root@localhost:~# mkdir mnt{1..3}
root@localhost:~# mount /dev/vg1/lv1 mnt1
root@localhost:~# mount /dev/vg2/lv1 mnt2
root@localhost:~# mount /dev/vg2/lv2 mnt3
root@localhost:~# df -h
文件系统                 大小  已用  可用 已用% 挂载点
/dev/mapper/vg1-lv1      4.9G  1.3M  4.6G    1% /root/mnt1
/dev/mapper/vg2-lv1      9.8G  2.1M  9.3G    1% /root/mnt2
/dev/mapper/vg2-lv2      5.0G  130M  4.9G    3% /root/mnt3

到此,磁盘已经挂载上了。接下来我们进行磁盘的动态扩容。

扩展逻辑卷

我们需要将vg1的lv1扩容到15G,vg2的lv2扩容到后续的所有空间,使用 lvextend 命令进行。

root@localhost:~# lvextend /dev/mapper/vg1-lv1 --size 15G
  Insufficient free space: 1280 extents needed, but only 1278 available

发现进行空间扩展时失败了,原因是磁盘空间不够,我们使用另外的命令,将vg1的所有空间分配给lv1

root@localhost:~# lvextend /dev/mapper/vg1-lv1 -l +100%FREE
  Size of logical volume vg1/lv1 changed from 10.00 GiB (2560 extents) to 14.99 GiB (3838 extents).
  Logical volume vg1/lv1 successfully resized.

此时,我们再查看当前挂载的文件系统

root@localhost:~# df -h
文件系统                 大小  已用  可用 已用% 挂载点
/dev/mapper/vg1-lv1      4.9G  1.3M  4.6G    1% /root/mnt1
/dev/mapper/vg2-lv1      9.8G  2.1M  9.3G    1% /root/mnt2
/dev/mapper/vg2-lv2      5.0G  130M  4.9G    3% /root/mnt3

发现文件系统此时可用空间大小还是5G,因为文件系统不会随着块设备的空间变化而变化,需要使用重新调整文件系统大小的命令来上块设备的文件系统重新调整大小,对于ext4文件系统,使用resize2fs命令

root@localhost:~# resize2fs /dev/mapper/vg1-lv1
resize2fs 1.47.1 (20-May-2024)
/dev/mapper/vg1-lv1 上的文件系统已被挂载于 /root/mnt1;需要进行在线调整大小

old_desc_blocks = 1, new_desc_blocks = 2
/dev/mapper/vg1-lv1 上的文件系统大小已经调整为 3930112 个块(每块 4k)。

root@localhost:~#
root@localhost:~# df -h
文件系统                 大小  已用  可用 已用% 挂载点
/dev/mapper/vg1-lv1       15G  1.3M   14G    1% /root/mnt1
/dev/mapper/vg2-lv1      9.8G  2.1M  9.3G    1% /root/mnt2
/dev/mapper/vg2-lv2      5.0G  130M  4.9G    3% /root/mnt3

此时,/dev/mapper/vg1-lv1已经被扩容而不会清除掉文件系统中的内容。

我们对 /dev/mapper/vg2-lv2 做同样的事情。额外需要注意的是,/dev/mapper/vg2-lv2 使用的是xfs文件系统,需要使用xfs_growfs重新调整文件系统大小。

root@localhost:~# lvextend /dev/mapper/vg2-lv2 -l +100%FREE
  Size of logical volume vg2/lv2 changed from 5.00 GiB (1280 extents) to <14.99 GiB (3837 extents).
  Logical volume vg2/lv2 successfully resized.
root@localhost:~# xfs_growfs /dev/mapper/vg2-lv2
meta-data=/dev/mapper/vg2-lv2    isize=512    agcount=4, agsize=327680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=1
         =                       reflink=1    bigtime=1 inobtcount=1 nrext64=1
data     =                       bsize=4096   blocks=1310720, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=16384, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 1310720 to 3929088
root@localhost:~# df -h
文件系统                 大小  已用  可用 已用% 挂载点
/dev/mapper/vg1-lv1       15G  1.3M   14G    1% /root/mnt1
/dev/mapper/vg2-lv1      9.8G  2.1M  9.3G    1% /root/mnt2
/dev/mapper/vg2-lv2       15G  326M   15G    3% /root/mnt3

此刻,4块硬盘已经按照我们的需求,被充分利用起来了。

LVM命令附录

root@localhost:~# lvm --help
  Available lvm commands:
  Use 'lvm help <command>' for more information

  config          Display and manipulate configuration information
  devtypes        Display recognised built-in block device types
  dumpconfig      Display and manipulate configuration information
  formats         List available metadata formats
  fullreport      Display full report
  help            Display help for commands
  lastlog         Display last command's log report
  lvchange        Change the attributes of logical volume(s)
  lvconvert       Change logical volume layout
  lvcreate        Create a logical volume
  lvdisplay       Display information about a logical volume
  lvextend        Add space to a logical volume
  lvmchange       With the device mapper, this is obsolete and does nothing.
  lvmconfig       Display and manipulate configuration information
  lvmdevices      Manage the devices file
  lvmdiskscan     List devices that may be used as physical volumes
  lvmsadc         Collect activity data
  lvmsar          Create activity report
  lvpoll          Continue already initiated poll operation on a logical volume
  lvreduce        Reduce the size of a logical volume
  lvremove        Remove logical volume(s) from the system
  lvrename        Rename a logical volume
  lvresize        Resize a logical volume
  lvs             Display information about logical volumes
  lvscan          List all logical volumes in all volume groups
  pvchange        Change attributes of physical volume(s)
  pvck            Check metadata on physical volumes
  pvcreate        Initialize physical volume(s) for use by LVM
  pvdata          Display the on-disk metadata for physical volume(s)
  pvdisplay       Display various attributes of physical volume(s)
  pvmove          Move extents from one physical volume to another
  pvremove        Remove LVM label(s) from physical volume(s)
  pvresize        Resize physical volume(s)
  pvs             Display information about physical volumes
  pvscan          List all physical volumes
  segtypes        List available segment types
  systemid        Display the system ID, if any, currently set on this host
  tags            List tags defined on this host
  version         Display software and driver version information
  vgcfgbackup     Backup volume group configuration(s)
  vgcfgrestore    Restore volume group configuration
  vgchange        Change volume group attributes
  vgck            Check the consistency of volume group(s)
  vgconvert       Change volume group metadata format
  vgcreate        Create a volume group
  vgdisplay       Display volume group information
  vgexport        Unregister volume group(s) from the system
  vgextend        Add physical volumes to a volume group
  vgimport        Register exported volume group with system
  vgimportclone   Import a VG from cloned PVs
  vgimportdevices Add devices for a VG to the devices file.
  vgmerge         Merge volume groups
  vgmknodes       Create the special files for volume group devices in /dev
  vgreduce        Remove physical volume(s) from a volume group
  vgremove        Remove volume group(s)
  vgrename        Rename a volume group
  vgs             Display information about volume groups
  vgscan          Search for all volume groups
  vgsplit         Move physical volumes into a new or existing volume group