openEuler 22.03 LVM逻辑卷管理配置与总结

ops/2024/9/24 14:22:31/

目录

  • 配置
    • 创建逻辑卷并格式化
      • 步骤 1 执行如下命令创建逻辑卷。
      • 步骤 2 执行如下命令格式化LV并挂载。
    • 逻辑卷扩容与缩容
      • 步骤 1 执行如下命令扩展逻辑卷与文件系统。
      • 步骤 2 执行如下步骤缩容文件系统与LV。(此步骤是高危操作,在工作中请谨慎!)
  • 总结
    • 创建逻辑卷
    • 查看逻辑卷
    • 扩容逻辑卷
    • 缩容逻辑卷
    • 删除逻辑卷

配置

创建逻辑卷并格式化

步骤 1 执行如下命令创建逻辑卷。

[root@openEuler ~]# pvcreate /dev/sde5
Physical volume “/dev/sde5” successfully created.

[root@openEuler ~]# pvdisplay
"/dev/sde5" is a new physical volume of "2.00 GiB"--- NEW Physical volume ---PV Name               	/dev/sde5VG NamePV Size               	2.00 GiBAllocatable           	NOPE Size               	0Total PE              	0Free PE               	0Allocated PE          	0PV UUID               wSgzbu-oFkH-rxL7-tt7e-QQA4-RZsX-rC2BSb

在这里插入图片描述

[root@openEuler ~]# vgcreate testvg /dev/sde5Volume group "testvg" successfully created
[root@openEuler ~]# vgdisplay testvg--- Volume group ---VG Name             	testvgSystem IDFormat                	lvm2Metadata Areas        	1Metadata Sequence No  1VG Access             	read/writeVG Status             	resizableMAX LV                	0Cur LV                	0Open LV               	0Max PV                	0Cur PV                	1Act PV                	1VG Size               	<2.00 GiBPE Size               	4.00 MiBTotal PE              	767Alloc PE / Size       	0 / 0Free  PE / Size       	767 / <3.00 GiBVG UUID               	O63DUX-eojV-iUfw-75ib-yeZP-N0xx-JXyOeY

在这里插入图片描述

[root@openEuler ~]# lvcreate -L 1.5G -n testlv testvgLogical volume "testlv" created.
[root@openEuler ~]# lvdisplay /dev/testvg/testlv--- Logical volume ---LV Path                	/dev/testvg/testlvLV Name              	testlvVG Name              	testvgLV UUID                wfSItH-O3cf-9pxa-emMW-BSwI-ZfWQ-uS6vYLLV Write Access        	read/writeLV Creation host, time openEuler, 2020-07-02 09:24:41 +0800LV Status              	available# open                 	0LV Size                	1.50 GiBCurrent LE             	384Segments               1Allocation             	inheritRead ahead sectors     	auto- currently set to     	8192Block device           	253:2

在这里插入图片描述

步骤 2 执行如下命令格式化LV并挂载。

[

root@openEuler ~]# mkfs.ext4 /dev/testvg/testlv
mke2fs 1.45.3 (14-Jul-2019)
Creating filesystem with 524288 4k blocks and 131072 inodes
Filesystem UUID: 59f52483-742c-41bd-b83b-3edb9c315611
Superblock backups stored on blocks:32768, 98304, 163840, 229376, 294912Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
[root@openEuler ~]# mkdir /mnt/testlv
[root@openEuler ~]# mount /dev/testvg/testlv /mnt/testlv/
[root@openEuler ~]# df -h | grep testvg
/dev/mapper/testvg-testlv   1.5G   24K  1.4G   1% /mnt/testlv

在这里插入图片描述

逻辑卷扩容与缩容

步骤 1 执行如下命令扩展逻辑卷与文件系统。

[root@openEuler ~]# fdisk /dev/sdd        #新建一个大小同样为3G的LVM分区Welcome to fdisk (util-linux 2.34).
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.
Created a new DOS disklabel with disk identifier 0xc5aa0a0a.Command (m for help): n
Partition typep   primary (0 primary, 0 extended, 4 free)e   extended (container for logical partitions)
Select (default p):Using default response p.
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-20971519, default 20971519): +3GCreated a new partition 1 of type 'Linux' and of size 3 GiB.Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'.Command (m for help): p
Disk /dev/sdd: 10 GiB, 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
Disklabel type: dos
Disk identifier: 0xc5aa0a0aDevice     Boot Start     End Sectors Size Id Type
/dev/sdd1        2048 6293503 6291456   3G 8e Linux LVMCommand (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

在这里插入图片描述

[root@openEuler ~]# pvcreate /dev/sdd1Physical volume "/dev/sdd1" successfully created.
[root@openEuler ~]# vgextend testvg /dev/sdd1		#仅有在PE大小一致时,才可以扩展Volume group "testvg" successfully extended[root@openEuler ~]# vgdisplay testvg--- Volume group ---VG Name               	testvgSystem IDFormat                	lvm2Metadata Areas        	2Metadata Sequence No  3VG Access            	read/writeVG Status             	resizableMAX LV                	0Cur LV                	1Open LV               	1Max PV                	0Cur PV                	2Act PV                	2VG Size               	5.99 GiBPE Size               	4.00 MiBTotal PE              	1534Alloc PE / Size       	512 / 2.00 GiBFree  PE / Size       	1022 / 3.99 GiBVG UUID               	O63DUX-eojV-iUfw-75ib-yeZP-N0xx-JXyOeY

在这里插入图片描述

[root@openEuler ~]# pvsPV         VG        Fmt  Attr PSize  PFree/dev/sda3  openeuler lvm2 a--  9.80g       0/dev/sde5  testvg    lvm2 a--  <2.00g 1020.00m/dev/sdd1  testvg    lvm2 a--  <3.00g   <3.00g
[root@openEuler ~]# vgsVG        #PV #LV #SN Attr   VSize  VFreeopeneuler   1   2   0 wz--n-  9.80g    0testvg      2   1   0 wz--n-  4.99g   3.99g			#此处可以看到已经扩展到了6G
[root@openEuler ~]# lvs /dev/testvg/testlv			#查看testlv信息LV     VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Converttestlv testvg  -wi-ao----    1.50g

在这里插入图片描述

[root@openEuler ~]# lvextend -L +3G /dev/testvg/testlvSize of logical volume testvg/testlv changed from 2.00 GiB (512 extents) to 5.00 GiB (1280 extents).Logical volume testvg/testlv successfully resized.[root@openEuler ~]# lvs /dev/testvg/testlvLV     VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Converttestlv testvg  -wi-ao---- 	 4.50g

在这里插入图片描述

[root@openEuler ~]# resize2fs /dev/testvg/testlv
resize2fs 1.46.4 (18-Aug-2021)
Filesystem at /dev/testvg/testlv is mounted on /mnt/testlv; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/testvg/testlv is now 1179648 (4k) blocks long. 
[root@openEuler ~]# df -h /dev/testvg/testlv
Filesystem                 Size  Used  Avail Use%  Mounted on
/dev/mapper/testvg-testlv   4.4G   24K  4.2G   1%  /mnt/testlv	#可以看到文件系统扩展了

在这里插入图片描述

步骤 2 执行如下步骤缩容文件系统与LV。(此步骤是高危操作,在工作中请谨慎!)

[root@openEuler ~]# umount /mnt/testlv		#卸载文件系统

在这里插入图片描述

[root@openEuler ~]# e2fsck -f /dev/testvg/testlv		#检查文件系统使用情况
e2fsck 1.46.4 (18-Aug-2021)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/testvg/testlv: 11/294912 files (0.0% non-contiguous), 28246/1179648 blocks 

在这里插入图片描述

[root@openEuler ~]# resize2fs /dev/testvg/testlv 2G		#重新指定文件系统逻辑大小
resize2fs /dev/testvg/testlv 2G 
[root@openEuler ~]# lvs /dev/testvg/testlvLV     VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Converttestlv testvg   -wi-a-----   4.50g				#可以看到LV没有缩减

在这里插入图片描述

[root@openEuler ~]# lvchange -a n /dev/testvg/testlv		#将LV修改为不活动状态
[root@openEuler ~]# lvreduce -L 2G /dev/testvg/testlv		#缩减LV大小为2GSize of logical volume testvg/testlv changed from 4.50 GiB (1152 extents) to 2.00 GiB (512 extents).Logical volume testvg/testlv successfully resized.
[root@openEuler ~]# lvchange -a y /dev/testvg/testlv		#修改LV为活动状态
[root@openEuler ~]# lvs /dev/testvg/testlv				#查看LV大小LV     VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Converttestlv testvg  -wi-a-----    2.00g

在这里插入图片描述

[root@openEuler ~]# e2fsck -f  /dev/testvg/testlv		#检查文件系统
e2fsck 1.46.4 (18-Aug-2021)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/testvg/testlv: 11/131072 files (0.0% non-contiguous), 17580/524288 blocks 
[root@openEuler ~]# mount /dev/testvg/testlv /mnt/testlv/		#重新挂载
[root@openEuler ~]# df -h /dev/testvg/testlv					#查看大小
Filesystem                 Size  Used Avail Use% Mounted on
/dev/mapper/testvg-testlv  2.0G  6.0M  1.9G   1% /mnt/testlv

在这里插入图片描述

步骤 3 执行如下步骤删除创建的LVM配置。

[root@openEuler ~]# umount /mnt/testlv
[root@openEuler ~]# lvremove -y /dev/testvg/testlvLogical volume "testlv" successfully removed
[root@openEuler ~]# vgremove testvg		#移除VGVolume group "testvg" successfully removed
[root@openEuler ~]# pvremove /dev/sde5 /dev/sdd1		#移除PVLabels on physical volume "/dev/sde5" successfully wiped.Labels on physical volume "/dev/sdd1" successfully wiped.

在这里插入图片描述

总结

先创建pv,再用一(多)个pv创建vg,使用一个vg的空间创建一(多)个lv

创建逻辑卷

#创建pvpvcreate /dev/LVM类型盘号
#创建vgvgcreate VG名 /dev/LVM类型盘号
#创建lvlvcreate -L LV大小 -n LV名 VG名

查看逻辑卷

#查看详细信息,[]为可选pvdisplay [/dev/LVM类型盘号]vgdisplay [VG名]lvdisplay [/dev/VG名/LV名]#查看汇总信息pvsvgslvs

扩容逻辑卷

#使用pv扩容vg
#使用vgdisplay可以看到Act PV为多个vgextend testvg /dev/其他的LVM类型盘号#扩容lvlvextend -L 扩容大小 /dev/VG名/LV名# 文件系统resizeresize2fs /dev/VG名/LV名

缩容逻辑卷

#设置LV为不活动lvchange -a n /dev/testvg/testlv	#缩减LVlvreduce -L 2G /dev/testvg/testlv#设置LV为活动lvchange -a y /dev/testvg/testlv#检查文件系统e2fsck -f  /dev/testvg/testlv

删除逻辑卷

#删除LVlvremove -y /dev/testvg/testlv#删除VGvgremove testvg#删除PVpvremove /dev/sde5 /dev/sdd1	

http://www.ppmy.cn/ops/36532.html

相关文章

java 语言写一个装饰器模式代码

装饰器模式&#xff08;Decorator Pattern&#xff09;允许你动态地给一个对象添加一些额外的职责。就增加功能来说&#xff0c;装饰器模式相比生成子类更为灵活。下面是一个简单的 Java 装饰器模式的示例代码&#xff1a; 首先&#xff0c;我们定义一个接口 Component&#x…

Java集合简介

单列集合 双列集合

Codigger:Web应用赋能的分布式操作系统让用户卓越体验

Codigger&#xff0c;作为一个分布式操作系统&#xff0c;其独特之处在于其采用的浏览器/服务器&#xff08;Browser/Server&#xff0c;简称B/S&#xff09;架构。这种架构的核心思想是&#xff0c;通过浏览器来进入工作界面&#xff0c;页面交互部分事务逻辑在前端&#xff0…

编译 fdk-aac

文章目录 关于 fdk-aac编译 fdk-aac在 FFMpeg 编译中启用 关于 fdk-aac A standalone library of the Fraunhofer FDK AAC code from Android. github &#xff1a; https://github.com/mstorsjo/fdk-aac代码托管 &#xff1a; https://sourceforge.net/projects/opencore-am…

字节跳动后端或大数据基础知识面试题及参考答案(2万字长文)

目录 Redis的数据类型 Redis数据类型的底层数据结构 三次握手、四次挥手 Redis持久化机制

240503-关于Unity的二三事

240503-关于Unity的二三事 1 常用快捷键 快捷键描述CtrlP播放/停止Ctrl1打开Scene窗口Ctrl2打开Game窗口Ctrl3打开Inspect窗口Ctrl4打开Hierarchy窗口Ctrl5打开Project窗口Ctrl6打开Animation窗口 2 关联VisualStudio2022 3 节约时间&#xff1a;将最新声明的参数移动到最上…

【记录】Latex|解决 ACM-Reference-Format 顺序不符合论文实际引用顺序的问题

参考&#xff1a; Sort References by Order of Appearance with LaTeX/BibTeXOrdering reference in bibTex - StackOverflow 文章目录 问题描述解决方案 省流版解决方案 完整版《用LaTeX/BibTeX按出现顺序排序参考文献》1. 概述2. LaTeX 和 BibTeX3. 使用 LaTeX 进行参考文…

android native开发

framwork 一些重要的流程都是要放到native中做的 原因也很简单&#xff0c;效率&#xff0c;尤其是针对性能优化方面的&#xff0c;更离不开native开发 目前针对native开发也回顾下&#xff0c;总结下经验 1 jni开发有两种&#xff0c;app端一般是静态模式&#xff0c;要有jav…