Centos 7.9 下创建LVM流程

Posted wx62e28ac222a20

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos 7.9 下创建LVM流程相关的知识,希望对你有一定的参考价值。


基本的逻辑卷管理概念:
PV(Physical Volume)- 物理卷
物理卷在逻辑卷管理中处于最底层,它可以是实际物理硬盘上的分区,也可以是整个物理硬盘,也可以是raid设备。

VG(Volumne Group)- 卷组
卷组建立在物理卷之上,一个卷组中至少要包括一个物理卷,在卷组建立之后可动态添加物理卷到卷组中。一个逻辑卷管理系统工程中可以只有一个卷组,也可以拥有多个卷组.

LV(Logical Volume)- 逻辑卷
逻辑卷建立在卷组之上,卷组中的未分配空间可以用于建立新的逻辑卷,逻辑卷建立后可以动态地扩展和缩小空间。系统中的多个逻辑卷可以属于同一个卷组,也可以属于不同的多个卷组。

PE(Physical Extent)- 物理块
LVM 默认使用4MB的PE区块,而LVM的LV最多仅能含有65534个PE (lvm1 的格式),因此默认的LVM的LV最大容量为4M*65534/(1024M/G)=256G。PE是整个LVM 最小的储存区块,也就是说,其实我们的资料都是由写入PE 来处理的。简单的说,这个PE 就有点像文件系统里面的block 大小。所以调整PE 会影响到LVM 的最大容量!不过,在 CentOS 6.x 以后,由于直接使用 lvm2 的各项格式功能,因此这个限制已经不存在了。

[root@ansible ~]# fdisk -l

Disk /dev/sdc: 5368 MB, 5368709120 bytes, 10485760 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 /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x000db7bd

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 209469439 103685120 8e Linux LVM

Disk /dev/sdb: 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 /dev/mapper/centos-root: 97.7 GB, 97710505984 bytes, 190840832 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 /dev/mapper/centos-swap: 8455 MB, 8455716864 bytes, 16515072 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

一.创建系统分区
选择/dev/sdc创建分区;
将整个sdc磁盘划分为一个sdc1分区,格式为Linux LVM;

[root@ansible ~]# fdisk /dev/sdc 
Welcome to fdisk (util-linux 2.23.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
Building a new DOS disklabel with disk identifier 0xc58168e5.

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
First sector (2048-10485759, default 2048): 5000000
Last sector, +sectors or +sizeK,M,G (5000000-10485759, default 10485759):
Using default value 10485759
Partition 1 of type Linux and of size 2.6 GiB is set

Command (m for help): wq
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

二.创建PV

[root@ansible ~]# pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created.
[root@ansible ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size 98.88 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 25313
Free PE 1
Allocated PE 25312
PV UUID cIWnvo-LZG7-ftaM-2zpW-MoF4-seFe-aRkAbw

"/dev/sdc1" is a new physical volume of "<2.62 GiB"
--- NEW Physical volume ---
PV Name /dev/sdc1
VG Name
PV Size <2.62 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID btPmIF-x1Mf-RBlN-Op3I-FfuN-u7LM-4gVuSK

[root@ansible ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <98.88g 4.00m
/dev/sdc1 lvm2 --- <2.62g <2.62g
[root@ansible ~]# pvscan
PV /dev/sda2 VG centos lvm2 [<98.88 GiB / 4.00 MiB free]
PV /dev/sdc1 lvm2 [<2.62 GiB]
Total: 2 [101.49 GiB] / in use: 1 [<98.88 GiB] / in no VG: 1 [<2.62 GiB]

三.创建VG

[root@ansible ~]# vgcreate vg0 /dev/sdc1 -s 1024M
Volume group "vg0" successfully created
[root@ansible ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <98.88g 4.00m
/dev/sdc1 vg0 lvm2 a-- 2.00g 2.00g
[root@ansible ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- <98.88g 4.00m
vg0 1 0 0 wz--n- 2.00g 2.00g

四.创建LV—>格式化LV—>挂载LV

[root@ansible ~]# lvcreate -L 1G -n lv1 vg0
Logical volume "lv1" created.
[root@ansible ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- <98.88g 4.00m
vg0 1 1 0 wz--n- 2.00g 1.00g
[root@ansible ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- 91.00g
swap centos -wi-ao---- <7.88g
lv1 vg0 -wi-a----- 1.00g
[root@ansible ~]# lvdisplay
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID wvwsde-7Zct-zWvd-nBEF-xKvf-9DJm-M43N2s
LV Write Access read/write
LV Creation host, time localhost, 2021-10-26 20:57:47 +0800
LV Status available
# open 1
LV Size 91.00 GiB
Current LE 23296
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0

--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID WxndH6-NN0H-wBRo-a0Fl-6W9V-M1Ic-BJZUpg
LV Write Access read/write
LV Creation host, time localhost, 2021-10-26 20:57:48 +0800
LV Status available
# open 2
LV Size <7.88 GiB
Current LE 2016
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1

--- Logical volume ---
LV Path /dev/vg0/lv1
LV Name lv1
VG Name vg0
LV UUID R1I6G9-ZpmC-XaEF-x82h-What-dfBh-4oV1BZ
LV Write Access read/write
LV Creation host, time ansible, 2021-10-31 19:23:27 +0800
LV Status available
# open 0
LV Size 1.00 GiB
Current LE 1
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2

使用xfs文件系统对LV进行格式化​

[root@ansible ~]# mkfs.xfs /dev/vg0/lv1 
meta-data=/dev/vg0/lv1 isize=512 agcount=4, agsize=65536 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=262144, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

将lv1挂载到/test目录下

[root@ansible ~]# mkdir /test
[root@ansible ~]# mount /dev/vg0/lv1 /test/
[root@ansible ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 8.7M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 91G 2.0G 90G 3% /
/dev/sdb 10G 33M 10G 1% /data
/dev/sda1 1014M 171M 844M 17% /boot
tmpfs 799M 0 799M 0% /run/user/0
/dev/mapper/vg0-lv1 1014M 33M 982M 4% /test

加入/etc/fstab

/dev/mapper/vg0-lv1    /test                    xfs     defaults        0 0

五.LV扩容

[root@ansible ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- <98.88g 4.00m
vg0 1 1 0 wz--n- 2.00g 1.00g
[root@ansible ~]# lvextend -L +1G /dev/vg0/lv1
Size of logical volume vg0/lv1 changed from 1.00 GiB (1 extents) to 2.00 GiB (2 extents).
Logical volume vg0/lv1 successfully resized.
[root@ansible ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- <98.88g 4.00m
vg0 1 1 0 wz--n- 2.00g 0
[root@ansible ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- 91.00g
swap centos -wi-ao---- <7.88g
lv1 vg0 -wi-ao---- 2.00g
[root@ansible ~]# df -TH
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 4.2G 0 4.2G 0% /dev
tmpfs tmpfs 4.2G 0 4.2G 0% /dev/shm
tmpfs tmpfs 4.2G 9.1M 4.2G 1% /run
tmpfs tmpfs 4.2G 0 4.2G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 98G 2.1G 96G 3% /
/dev/sdb xfs 11G 34M 11G 1% /data
/dev/sda1 xfs 1.1G 179M 885M 17% /boot
tmpfs tmpfs 837M 0 837M 0% /run/user/0
/dev/mapper/vg0-lv1 xfs 1.1G 34M 1.1G 4% /test
[root@ansible ~]# xfs_growfs /dev/vg0/lv1
meta-data=/dev/mapper/vg0-lv1 isize=512 agcount=4, agsize=65536 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=262144, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 262144 to 524288
[root@ansible ~]# df -TH
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 4.2G 0 4.2G 0% /dev
tmpfs tmpfs 4.2G 0 4.2G 0% /dev/shm
tmpfs tmpfs 4.2G 9.1M 4.2G 1% /run
tmpfs tmpfs 4.2G 0 4.2G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 98G 2.1G 96G 3% /
/dev/sdb xfs 11G 34M 11G 1% /data
/dev/sda1 xfs 1.1G 179M 885M 17% /boot
tmpfs tmpfs 837M 0 837M 0% /run/user/0
/dev/mapper/vg0-lv1 xfs 2.2G 34M 2.2G 2% /test

六.VG扩容

[root@ansible ~]# pvcreate /dev/sdd
Physical volume "/dev/sdd" successfully created.
[root@ansible ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <98.88g 4.00m
/dev/sdc1 vg0 lvm2 a-- 2.00g 0
/dev/sdd lvm2 --- 5.00g 5.00g
[root@ansible ~]# vgextend vg0 /dev/sdd
Volume group "vg0" successfully extended
[root@ansible ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- <98.88g 4.00m
vg0 2 1 0 wz--n- 6.00g 4.00g

版权声明:本文为博主原创文章,未经博主允许不得转载。

LINUX

以上是关于Centos 7.9 下创建LVM流程的主要内容,如果未能解决你的问题,请参考以下文章

CentOS 7.9 LVM卷组改名

Centos7下创建LVM流程

CentOS下LVM的使用

centos 7.9下安装go1.16.4

centos 7.9下安装go1.16.4

CentOS 7.9: NFS服务搭建与配置