LVM Logical Volume Manager usage

LVM is the Logical Volume Manager (LVM) physical block device
among a plurality of physical devices reorganize the file system, designated as the physical volumes, with one or more physical volumes to create a volume group, physical volume is fixed the size of the physical area (physical Extent, PE) defined, create a logical volume on the physical volume is a physical area (PE) composition, can create a file system on the logical volume. Composed as follows:

LVM Logical Volume Manager usage
Linux Block: Device: block device, i.e. a physical disk or partition
Physical Volumes: physical volume (PV) from the block device has created
Volume Group: volume group (VG), a plurality of physical volumes are combined into coil groups
Logical volumes: Logic volume (lv), the volume group reclassified to be dynamically extended partition

First, create LVM

 1、创建PV,准备一个分区/dev/sdb3,并将分区类型改成lvm,整个磁盘/dev/sdc则不用修改可以直接创建为PV  

LVM Logical Volume Manager usage
LVM Logical Volume Manager usage

2、创建VG0,默认包含/dev/sdb3、/dev/sdc两个PV

LVM Logical Volume Manager usage

3、创建mysql逻辑卷,大小50G 

LVM Logical Volume Manager usage

4、格式化逻辑卷,挂载到新建的/mnt/mysql就可以使用    

LVM Logical Volume Manager usage

如果卷组空间用完了可以添加新PV

LVM Logical Volume Manager usage

Second, the logical volume expansion

扩展逻辑卷可以在挂载状态直接扩展,新扩展的空间是没有文件系统,不会添加到原来逻辑卷上需同步,  
扩展命令也可以用lvextend -l +1000 /dev/vg0/mysql   表示增加1000个PE

LVM Logical Volume Manager usage

新建20G binlog逻辑卷格式化为xfs格式并扩展

LVM Logical Volume Manager usage
LVM Logical Volume Manager usage

xfs_growfs /mnt/binlog   后面加挂载点,用于xfs文件系统同步

LVM Logical Volume Manager usage

lvextend -r -l +500 / dev / vg0 / mysql directly expand and the synchronization file system, the file system format does not distinguish between,

LVM Logical Volume Manager usage

Third, reduce the logical volume (only can reduce ext file system)

LVM Logical Volume Manager usageLVM Logical Volume Manager usage

Fourth, the removal of the logical volume corresponding physical disk

LVM Logical Volume Manager usage

/dev/sdb3对应的pe没有被占用可以直接从卷组中移除  
如果被占用药把对应PV占用pe的空间移动到同卷组中其他空闲空间上 命令pvmove

LVM Logical Volume Manager usage

Five, LVM snapshots

创建快照之前先随便复制一些内容到要做快照的逻辑卷中

LVM Logical Volume Manager usage
LVM Logical Volume Manager usageLVM Logical Volume Manager usage

LVM Logical Volume Manager usage

恢复快照,快照使用一次后会自动消失

LVM Logical Volume Manager usage

Delete logical volumes, volume groups, physical volumes

[root@centos1 ~]#umount /mnt/binlog/
[root@centos1 ~]#umount /mnt/mysql/
[root@centos1 ~]#lvs
  LV     VG  Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  binlog vg0 -wi-ao---- <23.91g                                                    
  mysql  vg0 -wi-ao----  30.00g  

[root@centos1 ~]#lvremove /dev/vg0/binlog 
Do you really want to remove active logical volume vg0/binlog? [y/n]: y
  Logical volume "binlog" successfully removed
[root@centos1 ~]#lvremove /dev/vg0/mysql 
Do you really want to remove active logical volume vg0/mysql? [y/n]: y
  Logical volume "mysql" successfully removed
[root@centos1 ~]#vgremove  vg0
Do you really want to remove volume group "vg0" containing 1 logical volumes? [y/n]: y
Do you really want to remove active logical volume vg0/mysql? [y/n]: y
  Logical volume "mysql" successfully removed
  Volume group "vg0" successfully removed
[root@centos1 ~]#pvremove /dev/sdc
  Labels on physical volume "/dev/sdc" successfully wiped.
[root@centos1 ~]#pvremove /dev/sdd
  Labels on physical volume "/dev/sdd" successfully wiped.

Guess you like

Origin blog.51cto.com/14322729/2403737