lvm逻辑卷管理
1.分区
*4个分区,每个1.5G左右,systemid为8e
*全部的分区整合成一个VG,PE大小为16M
*最初全部的VG容量都给LV
*最终LV格式化为ext4文件系统,挂载在/mnt/LVM
[root@server3 ~]# fdisk -l
sk /dev/vdc: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xa859763d
Device Boot Start End Blocks Id System
/dev/vdc1 2048 2099199 1048576 8e Linux LVM
/dev/vdc2 2099200 4196351 1048576 8e Linux LVM
/dev/vdc3 4196352 6293503 1048576 8e Linux LVM
/dev/vdc4 6293504 20971519 7339008 5 Extended
/dev/vdc5 6295552 8392703 1048576 8e Linux LVM
2.pv
pv相关命令:
pvcreate:将物理分区新建成为PV
pvscan:查询目前系统里面任何具有PV的磁盘
pvdisplay:显示出目前系统上面的PV状态
pvremove:将PV属性删除,让该分区不具有PV属性
ot@server3 ~]# pvcreate /dev/vdc1
Physical volume "/dev/vdc1" successfully created.
[root@server3 ~]# pvcreate /dev/vdc2
Physical volume "/dev/vdc2" successfully created.
[root@server3 ~]# pvcreate /dev/vdc3
Physical volume "/dev/vdc3" successfully created.
[root@server3 ~]# pvcreate /dev/vdc5
Physical volume "/dev/vdc5" successfully created.
[root@server3 ~]# pvscan
PV /dev/vdc2 lvm2 [1.00 GiB]
PV /dev/vdc1 lvm2 [1.00 GiB]
PV /dev/vdc5 lvm2 [1.00 GiB]
PV /dev/vdc3 lvm2 [1.00 GiB]
Total: 4 [4.00 GiB] / in use: 0 [0 ] / in no VG: 4 [4.00 GiB]
[root@server3 ~]# pvdisplay
"/dev/vdc2" is a new physical volume of "1.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vdc2
VG Name
PV Size 1.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID Ie4M3o-km18-qEfx-ZRzX-yy92-oAnA-Jcy82s
"/dev/vdc1" is a new physical volume of "1.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vdc1
VG Name
PV Size 1.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID dOedne-APJi-U06R-8iOH-QmDo-izbc-31bhai
"/dev/vdc5" is a new physical volume of "1.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vdc5
VG Name
PV Size 1.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID vdprDc-3htE-qNxS-NDdm-9UJ1-UD3g-PX5fhF
"/dev/vdc3" is a new physical volume of "1.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vdc3
VG Name
PV Size 1.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID ld45eP-Bmy5-pXUK-66eb-DsDu-5iSF-hjh6hQ
3.VG
相关命令介绍
vgcreate:新建vg的命令
vgscan:查看系统上是否有vg的存在
vgdisplay:显示目前系统上vg状态
vgextend:在vg内增加额外的pv
vgreduce:在vg内删除pv
vgchange:设置vg是否启动
vgremove:删除一个vg
[后根pe大小] [大小] [vg名称]
[root@server3 ~]# vgcreate -s 16M vgn /dev/vdc{1,2,3}
Volume group "vgn" successfully created
[root@server3 ~]# vgscan
Reading volume groups from cache.
Found volume group "vgn" using metadata type lvm2
[root@server3 ~]# pvscan
PV /dev/vdc1 VG vgn lvm2 [1008.00 MiB / 1008.00 MiB free]
PV /dev/vdc2 VG vgn lvm2 [1008.00 MiB / 1008.00 MiB free]
PV /dev/vdc3 VG vgn lvm2 [1008.00 MiB / 1008.00 MiB free]
PV /dev/vdc5 lvm2 [1.00 GiB]
Total: 4 [3.95 GiB] / in use: 3 [2.95 GiB] / in no VG: 1 [1.00 GiB]
[root@server3 ~]# vgdisplay
--- Volume group ---
VG Name vgn
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.95 GiB
PE Size 16.00 MiB
Total PE 189
Alloc PE / Size 0 / 0
Free PE / Size 189 / 2.95 GiB
VG UUID JjHOlH-RdcV-71dR-4wmK-NQ3N-pnRS-1y5dIV
上面我们只用了三个PV,将剩下的/dev/vdc5也交给vgn
[root@server3 ~]# vgextend vgn /dev/vdc5
Volume group "vgn" successfully extended
[root@server3 ~]# vgdisplay
--- Volume group ---
VG Name vgn
System ID
Format lvm2
Metadata Areas 4
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 4
Act PV 4
VG Size 3.94 GiB
PE Size 16.00 MiB
Total PE 252
Alloc PE / Size 0 / 0
Free PE / Size 252 / 3.94 GiB
VG UUID JjHOlH-RdcV-71dR-4wmK-NQ3N-pnRS-1y5dIV
4.lv
相关命令:
lvcreate:新建lv
lvscan:查询系统上面的lv
lvdisplay:显示系统上面的lv状态
lvextend:在lv里面增加容量
lvreduce:在lv里面减少容量
lvremove:删除一个lv
lvresize:对LV进行容量大小的调整
用法:lvcreate [-L N[mgt]] [-n LV名称] VG名称
lvcreate [-l N] [-n LV名称] VG名称
-L:后面跟容量,最小单位为pe,所以容量最好是pe的倍数
-l:后面可以跟pe的个数,而不是数量
-n:后面接的时LV的名称
[root@server3 ~]# lvcreate -l 252 -n lvn vgn
Logical volume "lvn" created.
[root@server3 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vgn/lvn
LV Name lvn
VG Name vgn
LV UUID 3cZBXM-Ef2z-wDLR-Fyxx-TmzD-Payq-BJ6eTm
LV Write Access read/write
LV Creation host, time server3, 2019-01-21 20:32:58 +0800
LV Status available
# open 0
LV Size 3.94 GiB
Current LE 252
Segments 4
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:0
5.文件系统挂载
[root@server3 ~]# mkfs.ext4 /dev/vgn/lvn
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
258048 inodes, 1032192 blocks
51609 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1056964608
32 block groups
32768 blocks per group, 32768 fragments per group
8064 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
[root@server3 mnt]# mount /dev/vgn/lvn /mnt/lvm/
/dev/mapper/vgn-lvn 3998400 16120 3759460 1% /mnt/lvm