linux--物理卷 ,物理卷组,逻辑卷

物理卷(Physical Volume,PV):指磁盘分区或从逻辑上与磁盘分区具有同样功能的设备(如RAID),是LVM的基本存储逻辑块,但和基本的物理存储介质(如分区、磁盘等)比较,却包含有与LVM相关的管理参数。

卷组(Volume Group,VG):是由一个或多个物理卷所组成的存储池,在卷组上能创建一个或多个逻辑卷。

逻辑卷(Logical Volume,LV):类似于非LVM系统中的硬盘分区,它建立在卷组之上,是一个标准的块设备,在逻辑卷之上可以建立文件系统。

下面通过一张图片来简单介绍一下,这三者的关系:

创建物理卷、卷组、逻辑卷时常用命令:

  • 物理卷常用选项:

1.修改要创建物理卷的设备类型为lvm

[root@server ~]# partprobefdisk /dev/vdb    

修改vdb5的类型为lv(8e)


[root@server ~]# partprobepartprobe      同步分区表

2.pvcreate:创建物理卷

格式:pvcreate /dev/vdb5

3.pvremove:表示是把数据擦除掉;

4.pvdisplay:显示物理卷创建的详细信息;

5.pvmove:把含有数据的PV移到其它物理PV上;

6.设置 PE

新建 lvm 分区,partprobe

pvcreate /dev/vdb6 -ff

pvs

vgcreate vg0 /dev/vdb6 默认PE 为4M

vgremove vg0 删除

vgcreate  -s 16M vg0 /dev/vdb6   设置PE 16M

vgremove vg0

  • 物理卷组常用选项:

1. vgcreate  创建物理卷组

格式:vgcreate vg_name /path       (-s #:表示PE的大小,默认为4MB)

vgcreate  weixingroup /dev/vdb5 物理卷组

2. vgremove:表示把数据擦除掉【注意:先执行物理卷的pvmove命令,然后再使用vgreduce】;

3.vgextend:扩展卷组数据

4.vgreduce:缩减卷组数据,实际是把pv拿掉的过程;

5.vgs:显示创建卷组信息;

6.vgdisplay:显示创建卷组详细信息;

  • 逻辑卷常用选项

1. lvcreate  创建逻辑卷

lvcreate -L 50M  -n weixindate  weixingroup 创建逻辑卷并指定逻辑卷的大小,及属于哪个物理卷组

-n:表示创建逻辑卷的名称;

-L:表示指定LV的空间大小;

2. lvremove:表示把数据擦除掉;

3. lvextend:扩展逻辑卷数据;

-L [+]# /path/to/lv:表示扩展逻辑卷在原来的基础上扩展多少;

4. lvreduce:缩减逻辑卷数据;

–L [-]# /path/to/lv:表示缩减逻辑卷在原来的基础上缩减多少;

5. lvs:显示创建逻辑卷信息

6. lvdisplay:显示创建逻辑卷详细信息

7. mkfs.xfs /dev/weixingroup/weixindate 逻辑卷安装文件系统


8.mount /dev/weixingroup/weixindate /weixindate/ 挂载

注意:/dev/weixingroup/weixindate /dev/mapper/weixingroup-weixindate 指向同一个链接

9. 扩展逻辑卷

watch -n 1 'pvs;echo +++++ ;vgs;echo +++++ ;lvs;echo +++++ ;df -h /weixindate'   在实验之前可用这条命令对pv vg lv 及 /weixindate的基本信息进行监控

lvextend -L 90M /dev/weixingroup/weixindate 拉伸逻辑卷


xfs_growfs /dev/weixingroup/weixindate  拉伸文件系统(只拉伸设备是无法使用的,还需对文件系统进行拉伸长)

当物理卷组不够时

fdisk /dev/vdb
增加新的lv类型的设备
partprobe
pvcreate /dev/vdb6
vgextend weixingroup /dev/vdb6
lvextend -L 150M /dev/weixingroup/weixindate


xfs_growfs /dev/weixingroup/weixindate

10.逻辑卷的缩减(xfs的文件系统不支持缩减,ext4的可以)

缩减逻辑卷应注意:

1、不能在线缩减,得先卸载;

2、确保缩减后的空间大小依然能存储原有的所有数据;

3、在缩减之前应先强行检查文件,以确保文件系统处于一致性状态;

同时也应该注意缩减逻辑卷是先把缩减逻辑边界,然后才缩减物理边界;

umount /weixindate/                                                   卸载
mkfs.ext4 /dev/weixingroup/weixindate                   安装ext4的文件系统

mount /dev/weixingroup/weixindate /weixindate/   挂载
lvextend -L 160M /dev/weixingroup/weixindate      ext4文件系统下,设备的拉伸

resize2fs /dev/weixingroup/weixindate                    ext4文件系统的拉伸

umount /weixindate/  卸载
e2fsck -f /dev/weixingroup/weixindate  扫描
resize2fs /dev/weixingroup/weixindate 50M 压缩文件系统为50M(必须在逻辑卷未挂载的情况下压缩)

mount /dev/weixingroup/weixindate /weixindate/ 挂载
lvreduce -L 50M /dev/weixingroup/weixindate  缩减逻辑卷为50M缩减后物理卷可能会有剩余

取出空余设备/dev/vdb6
vgreduce weixingroup /dev/vdb6 将/dev.vdb6移出物理卷组
pvremove /dev/vdb6 拿出设备
取出有数据的设备/dev/vdb5
pvmove /dev/vdb5 /dev/vdb6 数据迁移


vgreduce weixingroup /dev/vdb5  将/dev.vdb6移出物理卷组

pvremove /dev/vdb5  拿出设备

  • 设备的快照(reset)

lvcreate -L  20M  -n weixin_backup -s /dev/weixingroup/weixindate 创建设备的快照
mount /dev/weixingroup/weixin_backup /weixindate/ 挂载快照
rm -fr file  删除通过快照看到的设备存储的文件

umount /weixindate/ 卸载
lvremove /dev/weixingroup/weixin_backup 删除快照

lvcreate -L  20M  -n weixindate_backup -s /dev/weixingroup/weixindate 创建新的快照
mount /dev/weixingroup/weixindate_backup /weixindate/ 挂载快照
cd /weixindate/
ls 查看挂载点文件,file 依旧存在

  • lvm逻辑卷的删除

umount /weixindate/ 卸载
lvremove /dev/weixingroup/weixindate_backup 删除快照
1> lvremove /dev/weixingroup/weixindate     删除逻辑卷
2> vgremove weixingroup                    删除物理卷组
3> pvremove /dev/vdn{5,6}             删除物理卷
1>2>3> 步骤不能颠倒

fdisk /dev/vdb 删除分区表内设备的信息
partprobe

lvm出现的两个错误解决方法

2.设备在使用时,从分区表里删除设备

执行vgreduce --removemissing weixingroup 命令

2. 自动挂载文件编辑错误

虚拟机起不来
等,输入超级用户密码,编辑/etc/fstab 文件
重启

设置pe
新建lvm分区

pvcreate /dev/vdb5

猜你喜欢

转载自blog.csdn.net/weixin_43273168/article/details/84033819