centos7 下创建LVM流程
简单介绍
- PV(Physical Volume)- 物理卷
- VG(Volumne Group)- 卷组
- LV(Logical Volume)- 逻辑卷
- PE(Physical Extent)- 物理块
一、创建系统分区
Command (m for help): n (创建新分区)
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p (选择创建主分区)
Partition number (1-4, default 1): 1 (分区号选择1)
First sector (2048-31457279, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-31457279, default 31457279):
Using default value 31457279
Partition 1 of type Linux and of size 15 GiB is set
Command (m for help): p (查看已经创建的分区)
Disk /dev/sdb: 16.1 GB, 16106127360 bytes, 31457280 sectors
Device Boot Start End Blocks Id System
/dev/sdb1 2048 31457279 15727616 83 Linux (系统默认为83,即:Linux)
Command (m for help): t (修改分区格式)
Selected partition 1
Hex code (type L to list all codes): 8e (8e为Linux LVM格式)
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/sdb: 16.1 GB, 16106127360 bytes, 31457280 sectors
Device Boot Start End Blocks Id System
/dev/sdb1 2048 31457279 15727616 8e Linux LVM
Command (m for help): w
二、创建PV
# pvcreate /dev/sdb1 (创建PV)
# pvdisplay
"/dev/sdb1" is a new physical volume of "10.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 10.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID dZRM2W-X2Lz-I3Jz-i4S4-E8fN-BF4K-oZqhd3
# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 lvm2 --- 10.00g 10.00g
# pvscan
PV /dev/sdb1 lvm2 [10.00 GiB]
三、创建VG
- raid:磁盘阵列;
- 分区,如:/dev/sdb1;
- 整个磁盘,如:/dev/sdc;
# vgcreate vg0 /dev/sdb1 /dev/sdc -s 64M
Physical volume "/dev/sdc" successfully created
Volume group "vg0" successfully created
使用分区/dev/sdb1 和 磁盘/dev/sdc 来创建vg,并设置PE大小为64M
# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 vg0 lvm2 a-- 10.00g 10.00g
/dev/sdc vg0 lvm2 a-- 10.00g 10.00g
# vgs
VG #PV #LV #SN Attr VSize VFree
vg0 2 0 0 wz--n- 19.99g 19.99g
上面知道:/dev/sdb1和/dev/sdb都是10G,所以vg0的大小为19.99G;
--- Volume group ---
VG Name vg0
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 19.99 GiB
PE Size 64.00 MiB
Total PE 320
Alloc PE / Size 0 / 0
Free PE / Size 5118 / 19.99 GiB
VG UUID m58K2q-eIsC-1Z3T-DySZ-cgKb-Sd3L-UbrW2z
四、创建LV-->格式化LV-->挂载LV
- 创建LV;
- 格式化LV,如:ext3,ext4等;
- 挂载LV到指定目录下;
# lvcreate -L 8G -n lv1 vg0
Logical volume "lv1" created.
从vg0中分出8G的空间给lv1使用
# vgs
VG #PV #LV #SN Attr VSize VFree
vg0 2 1 0 wz--n- 19.99g 11.99g
由于分出了8G给lv1,所以VFree之剩下:11.99G
# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg0 -wi-a----- 8.00g
# lvdisplay
--- Logical volume ---
LV Path /dev/vg0/lv1
LV Name lv1
VG Name vg0
LV UUID wevRbf-Iy3b-wPfa-mK4a-DFoq-A24w-8q5axT
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2016-09-08 09:58:34 +0800
LV Status available
# open 0
LV Size 8.00 GiB
Current LE 2048
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:3
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
524288 inodes, 2097152 blocks
104857 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2147483648
64 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
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
# mount /dev/vg0/lv1 /mnt/lv1
# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg0-lv1 ext3 7.8G 19M 7.4G 1% /mnt/lv1
五、LV扩容
- 使用VG的Free空间,对LV扩容;
- 完成后需要在对文件系统扩容;
# vgs
VG #PV #LV #SN Attr VSize VFree
vg0 2 1 0 wz--n- 19.99g 11.99g
现在还有11.99G可用
# lvextend -L +3G /dev/vg0/lv1
Size of logical volume vg0/lv1 changed from 8.00 GiB (2048 extents) to 11.00 GiB (2816 extents).
Logical volume lv1 successfully resized.
将lv1添加3G容量
# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 3 0 wz--n- 99.45g 4.00m
vg0 2 1 0 wz--n- 19.99g 8.99g
由原先的11.99G可用变为8.99G可用
# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg0 -wi-ao---- 11.00g
由原先的8G增加到了11G
对文件系统进行扩容
# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg0-lv1 ext3 7.8G 19M 7.4G 1% /mnt/lv1
可是发现实际容量并没有变化,还是7.8G
这时需要对文件系统进行扩容
# resize2fs /dev/vg0/lv1
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vg0/lv1 is mounted on /mnt/lv1; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/vg0/lv1 is now 2883584 blocks long.
对文件系统扩容
# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg0-lv1 ext3 11G 21M 11G 1% /mnt/lv1
发现此时lv1的容量变为了11G
六、VG扩容
使用/dev/sdd来创建一个PV
# pvcreate /dev/sdd
Physical volume "/dev/sdd" successfully created
创建PV
# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 vg0 lvm2 a-- 10.00g 0
/dev/sdc vg0 lvm2 a-- 10.00g 8.99g
/dev/sdd lvm2 --- 15.00g 15.00g
新增加的PV有15G
# vgextend vg0 /dev/sdd
Volume group "vg0" successfully extended
使用PV对VG扩容
# vgs
VG #PV #LV #SN Attr VSize VFree
vg0 3 1 0 wz--n- 34.99g 23.99g
扩容后的vg0由19.99G变为了34.99G
版权声明:
作者:SE_You
链接:https://www.cnesa.cn/1066.html
来源:CNESA
文章版权归作者所有,未经允许请勿转载。
共有 0 条评论