Centos 7.9 下创建LVM流程

网友投稿 1285 2022-09-03

Centos 7.9 下创建LVM流程

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 -lDisk /dev/sdc: 5368 MB, 5368709120 bytes, 10485760 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000db7bd Device Boot Start End Blocks Id System/dev/sda1 * 2048 2099199 1048576 83 Linux/dev/sda2 2099200 209469439 103685120 8e Linux LVMDisk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-root: 97.7 GB, 97710505984 bytes, 190840832 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-swap: 8455 MB, 8455716864 bytes, 16515072 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/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 tableBuilding a new DOS disklabel with disk identifier 0xc58168e5.Command (m for help): nPartition type: p primary (0 primary, 0 extended, 4 free) e extendedSelect (default p): pPartition number (1-4, default 1): 1First sector (2048-10485759, default 2048): 5000000Last sector, +sectors or +size{K,M,G} (5000000-10485759, default 10485759): Using default value 10485759Partition 1 of type Linux and of size 2.6 GiB is setCommand (m for help): wqThe 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=0data = bsize=4096 blocks=262144, imaxpct=25 = sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=1log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0

将lv1挂载到/test目录下

[root@ansible ~]# mkdir /test[root@ansible ~]# mount /dev/vg0/lv1 /test/[root@ansible ~]# df -hFilesystem Size Used Avail Use% Mounted ondevtmpfs 3.9G 0 3.9G 0% /devtmpfs 3.9G 0 3.9G 0% /dev/shmtmpfs 3.9G 8.7M 3.9G 1% /runtmpfs 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% /boottmpfs 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 -THFilesystem Type Size Used Avail Use% Mounted ondevtmpfs devtmpfs 4.2G 0 4.2G 0% /devtmpfs tmpfs 4.2G 0 4.2G 0% /dev/shmtmpfs tmpfs 4.2G 9.1M 4.2G 1% /runtmpfs 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% /boottmpfs 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=0data = bsize=4096 blocks=262144, imaxpct=25 = sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=1log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0data blocks changed from 262144 to 524288[root@ansible ~]# df -THFilesystem Type Size Used Avail Use% Mounted ondevtmpfs devtmpfs 4.2G 0 4.2G 0% /devtmpfs tmpfs 4.2G 0 4.2G 0% /dev/shmtmpfs tmpfs 4.2G 9.1M 4.2G 1% /runtmpfs 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% /boottmpfs 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

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:PHP算法——四大基础算法(php常见算法题)
下一篇:Linux下timeout命令
相关文章

 发表评论

暂时没有评论,来抢沙发吧~