LVM(Logical Volume Manager)逻辑卷管理是在Linux2.4内核以上实现的磁盘管理技术。LVM将一个或多个硬盘的分区在逻辑上集合,相当于一个大硬盘来使用,当硬盘的空间不够使用的时候,可以继续将其它的硬盘的分区加入其中,这样可以实现磁盘空间的动态管理,相对于普通的磁盘分区有很大的灵活性。与传统的磁盘与分区相比,LVM为计算机提供了更高层次的磁盘存储。它使系统管理员可以更方便的为应用与用户分配存储空间。在LVM管理下的存储卷可以按需要随时改变大小与移除(可能需对文件系统工具进行升级)。LVM也允许按用户组对存储卷进行管理,允许管理员用更直观的名称(如”data’、 ‘Oracle’)代替物理磁盘名(如’sda’、’sdb’)来标识存储卷。
物理存储介质(The physical media):这里指系统的存储设备/dev/sda1、/dev/xvdb1等,是存储系统最低层的存储单元。
物理卷(physical volume):物理卷就是指硬盘分区或从逻辑上与磁盘分区具有同样功能的设备(如RAID),是LVM的基本存储逻辑块,但和基本的物理存储介质(如分区、磁盘等)比较,却包含有与LVM相关的管理参数,PV即物理的磁盘分区。
卷组(Volume Group):LVM卷组类似于非LVM系统中的物理硬盘,其由物理卷组成,可以在卷组上创建一个或多个“LVM分区”(逻辑卷),LVM卷组由一个或多个物理卷组成。
逻辑卷(logical volume):LVM的逻辑卷类似于非LVM系统中的硬盘分区,在逻辑卷之上可以建立文件系统(比如/home或者/usr等)。
PE(physical extent):每一个物理卷被划分为称为PE(Physical Extents)的基本单元,具有唯一编号的PE是可以被LVM寻址的最小单元。PE的大小是可配置的,默认为4MB。
LE(logical extent):逻辑卷也被划分为被称为LE(Logical Extents) 的可被寻址的基本单位。在同一个卷组中,LE的大小和PE是相同的,并且一一对应。
创建PV
pvcreate /dev/xvdb1 /dev/xvdc1 /dev/xvde1
创建VG
vgcreate -s 8M datavg /dev/xvdb1 /dev/xvdc1 /dev/xvde1
创建LV
lvcreate -L 890G -n lvdata datavg
挂载LV
/dev/datavg/lvdata
创建PV
pvcreate /dev/xvdf1
扩展VG
vgextend datavg /dev/xvdf1
扩展LV
lvextend -L +100G /dev/datavg/lvdata
扩展文件系统
resize2fs /dev/datavg/lvdata
案例:
[root@hkpgsadg dev]# ls -l /dev/xvd*
brw-rw—- 1 root disk 202, 0 Apr 13 16:37 /dev/xvda
brw-rw—- 1 root disk 202, 1 Apr 13 16:36 /dev/xvda1
brw-rw—- 1 root disk 202, 2 Apr 13 16:36 /dev/xvda2
brw-rw—- 1 root disk 202, 3 Apr 13 16:36 /dev/xvda3
brw-rw—- 1 root disk 202, 16 Apr 13 16:39 /dev/xvdb
brw-rw—- 1 root disk 202, 17 Apr 13 16:39 /dev/xvdb1
brw-rw—- 1 root disk 202, 32 Apr 13 16:37 /dev/xvdc
brw-rw—- 1 root disk 202, 64 Apr 13 16:37 /dev/xvde
brw-rw—- 1 root disk 202, 80 Apr 13 16:37 /dev/xvdf
[root@hkpgsadg dev]# fdisk /dev/xvdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x04acd4ca.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won’t be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to
switch off the mode (command ‘c’) and change display units to
sectors (command ‘u’).
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-65270, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-65270, default 65270):
Using default value 65270
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@hkpgsadg dev]# ls -l /dev/xvd*
brw-rw—- 1 root disk 202, 0 Apr 13 16:37 /dev/xvda
brw-rw—- 1 root disk 202, 1 Apr 13 16:36 /dev/xvda1
brw-rw—- 1 root disk 202, 2 Apr 13 16:36 /dev/xvda2
brw-rw—- 1 root disk 202, 3 Apr 13 16:36 /dev/xvda3
brw-rw—- 1 root disk 202, 16 Apr 13 16:39 /dev/xvdb
brw-rw—- 1 root disk 202, 17 Apr 13 16:39 /dev/xvdb1
brw-rw—- 1 root disk 202, 32 Apr 13 16:39 /dev/xvdc
brw-rw—- 1 root disk 202, 33 Apr 13 16:39 /dev/xvdc1
brw-rw—- 1 root disk 202, 64 Apr 13 16:40 /dev/xvde
brw-rw—- 1 root disk 202, 65 Apr 13 16:40 /dev/xvde1
brw-rw—- 1 root disk 202, 80 Apr 13 16:40 /dev/xvdf
brw-rw—- 1 root disk 202, 81 Apr 13 16:40 /dev/xvdf1
[root@hkpgsadg dev]# pvcreate /dev/xvdb1 /dev/xvdc1 /dev/xvde1
Physical volume “/dev/xvdb1” successfully created
Physical volume “/dev/xvdc1” successfully created
Physical volume “/dev/xvde1” successfully created
[root@hkpgsadg dev]# pvdisplay
— Physical volume —
PV Name /dev/xvda2
VG Name VolGroup
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4994
Free PE 0
Allocated PE 4994
PV UUID Tv6PfK-cNpj-zYU2-cPeY-Xp8H-guAW-YZOm7d
— Physical volume —
PV Name /dev/xvda3
VG Name VolGroup
PV Size 100.00 GiB / not usable 3.99 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 25599
Free PE 0
Allocated PE 25599
PV UUID hhOoov-6TnF-p1Mg-mPc6-66If-zNwT-v8cIKB
“/dev/xvdb1” is a new physical volume of “100.00 GiB”
— NEW Physical volume —
PV Name /dev/xvdb1
VG Name
PV Size 100.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID OujuQi-rD1R-K91R-Ni82-jyAX-PpjD-ZnQvo5
“/dev/xvdc1” is a new physical volume of “499.99 GiB”
— NEW Physical volume —
PV Name /dev/xvdc1
VG Name
PV Size 499.99 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID grJiiL-KGug-ef3c-XF2J-ffS1-AhTl-xfHSMW
“/dev/xvde1” is a new physical volume of “300.00 GiB”
— NEW Physical volume —
PV Name /dev/xvde1
VG Name
PV Size 300.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 08dOWh-3dFQ-rQ00-VTGi-h9S2-PbaJ-aQKYSe
[root@hkpgsadg dev]# vgcreate -s 8M datavg /dev/xvdb1 /dev/xvdc1 /dev/xvde1
Volume group “datavg” successfully created
[root@hkpgsadg dev]# vgdisplay
— Volume group —
VG Name datavg
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 899.98 GiB
PE Size 8.00 MiB
Total PE 115197
Alloc PE / Size 0 / 0
Free PE / Size 115197 / 899.98 GiB
VG UUID fINMY5-wBKS-QBKi-N6QI-ihMD-YaVb-j90u0x
— Volume group —
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 119.50 GiB
PE Size 4.00 MiB
Total PE 30593
Alloc PE / Size 30593 / 119.50 GiB
Free PE / Size 0 / 0
VG UUID RdDeWr-qxlF-f1To-zNng-nxCV-e1Hd-3xVZfH
[root@hkpgsadg dev]# vgdisplay
— Volume group —
VG Name datavg
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 899.98 GiB
PE Size 8.00 MiB
Total PE 115197
Alloc PE / Size 0 / 0
Free PE / Size 115197 / 899.98 GiB
VG UUID fINMY5-wBKS-QBKi-N6QI-ihMD-YaVb-j90u0x
— Volume group —
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 119.50 GiB
PE Size 4.00 MiB
Total PE 30593
Alloc PE / Size 30593 / 119.50 GiB
Free PE / Size 0 / 0
VG UUID RdDeWr-qxlF-f1To-zNng-nxCV-e1Hd-3xVZfH
[root@hkpgsadg dev]# vgdisplay datavg
— Volume group —
VG Name datavg
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 899.98 GiB
PE Size 8.00 MiB
Total PE 115197
Alloc PE / Size 0 / 0
Free PE / Size 115197 / 899.98 GiB
VG UUID fINMY5-wBKS-QBKi-N6QI-ihMD-YaVb-j90u0x
[root@hkpgsadg dev]# lvcreate -L 890G -n lvdata datavg
Logical volume “lvdata” created
[root@hkpgsadg dev]# lvdisplay
— Logical volume —
LV Path /dev/datavg/lvdata
LV Name lvdata
VG Name datavg
LV UUID yFWfNu-E1cr-px49-K9tH-Q0vU-BjfL-yt8hWh
LV Write Access read/write
LV Creation host, time hkpgsadg, 2016-04-13 16:45:21 +0800
LV Status available
# open 0
LV Size 890.00 GiB
Current LE 113920
Segments 3
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:2
— Logical volume —
LV Path /dev/VolGroup/lv_root
LV Name lv_root
VG Name VolGroup
LV UUID 4bM3bz-gttp-qKgr-sd9L-d24M-RMEb-LO4L4h
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2014-07-07 18:28:07 +0800
LV Status available
# open 1
LV Size 115.58 GiB
Current LE 29589
Segments 2
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:0
— Logical volume —
LV Path /dev/VolGroup/lv_swap
LV Name lv_swap
VG Name VolGroup
LV UUID Ic6bZU-mt6c-b0LK-1n7F-62Kc-16V1-TkcXBU
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2014-07-07 18:28:11 +0800
LV Status available
# open 1
LV Size 3.92 GiB
Current LE 1004
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:1
[root@hkpgsadg dev]# mkfs.ext4 /dev/datavg/lvdata
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
58327040 inodes, 233308160 blocks
11665408 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
7120 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@hkpgsadg dev]# mkdir /data
[root@hkpgsadg dev]# mount /dev/datavg/lvdata /data
[root@hkpgsadg dev]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
114G 4.5G 104G 5% /
tmpfs 62G 0 62G 0% /dev/shm
/dev/xvda1 485M 32M 428M 7% /boot
/dev/mapper/datavg-lvdata
877G 200M 832G 1% /data
[root@hkpgsadg dev]#
[root@hkpgsadg data]# pvcreate /dev/xvdf1
Physical volume “/dev/xvdf1” successfully created
[root@hkpgsadg data]# vgextend datavg /dev/xvdf1
Volume group “datavg” successfully extended
[root@hkpgsadg data]# lvdisplay
— Logical volume —
LV Path /dev/datavg/lvdata
LV Name lvdata
VG Name datavg
LV UUID yFWfNu-E1cr-px49-K9tH-Q0vU-BjfL-yt8hWh
LV Write Access read/write
LV Creation host, time hkpgsadg, 2016-04-13 16:45:21 +0800
LV Status available
# open 1
LV Size 890.00 GiB
Current LE 113920
Segments 3
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:2
[root@hkpgsadg data]# vgdisplay
— Volume group —
VG Name datavg
System ID
Format lvm2
Metadata Areas 4
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 4
Act PV 4
VG Size 1.17 TiB
PE Size 8.00 MiB
Total PE 153596
Alloc PE / Size 113920 / 890.00 GiB
Free PE / Size 39676 / 309.97 GiB
VG UUID fINMY5-wBKS-QBKi-N6QI-ihMD-YaVb-j90u0x
[root@hkpgsadg data]# lvextend -L +100G /dev/datavg/lvdata
Extending logical volume lvdata to 990.00 GiB
Logical volume lvdata successfully resized
[root@hkpgsadg data]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
114G 4.5G 104G 5% /
tmpfs 62G 0 62G 0% /dev/shm
/dev/xvda1 485M 32M 428M 7% /boot
/dev/mapper/datavg-lvdata
877G 200M 832G 1% /data
[root@hkpgsadg data]# resize2fs /dev/datavg/lvdata
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/datavg/lvdata is mounted on /data; on-line resizing required
old desc_blocks = 56, new_desc_blocks = 62
Performing an on-line resize of /dev/datavg/lvdata to 259522560 (4k) blocks.
The filesystem on /dev/datavg/lvdata is now 259522560 blocks long.
[root@hkpgsadg data]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
114G 4.5G 104G 5% /
tmpfs 62G 0 62G 0% /dev/shm
/dev/xvda1 485M 32M 428M 7% /boot
/dev/mapper/datavg-lvdata
975G 200M 925G 1% /data
Created by Tony.Tang[TangYun]2016.04
-------------End-----------------
LVM2详解 http://www.linuxidc.com/Linux/2015-09/122976.htm
Ubuntu 上使用 LVM 轻松调整分区并制作快照 http://www.linuxidc.com/Linux/2015-09/122563.htm
使用LVM创建弹性磁盘存储——第一部分 http://www.linuxidc.com/Linux/2014-10/107697.htm
在Linux中扩展/缩减LVM(第二部分) http://www.linuxidc.com/Linux/2014-10/107786.htm
在 LVM中 录制逻辑卷快照并恢复(第三部分) http://www.linuxidc.com/Linux/2014-11/108867.htm
在LVM中设置精简资源调配卷(第四部分) http://www.linuxidc.com/Linux/2014-11/109757.htm
使用条块化I/O管理多个LVM磁盘(第五部分) http://www.linuxidc.com/Linux/2014-12/110532.htm
本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-04/130299.htm