您的位置:首页 > 运维架构 > Linux

Linux lvm逻辑卷创建管理删除

2019-03-17 00:30 253 查看

①PV(Physical Volume) 物理卷
②PE(Physical Extend) 物理拓展
③VG(Volume Group) 卷组
④LV(Logical Volume) 逻辑卷

工作原理:
(1)物理磁盘被格式化为PV,空间被划分为一个个的PE
(2)不同的PV加入到同一个VG中,不同PV的PE全部进入到了VG的PE池内
(3)LV基于PE创建,大小为PE的整数倍,组成LV的PE可能来自不同的物理磁盘
(4)LV现在就直接可以格式化后挂载使用了
(5)LV的扩充缩减实际上就是增加或减少组成该LV的PE数量,其过程不会丢失原始数据

前期准备:
使用空闲磁盘/dev/sdb和/dev/sdc,更改硬盘格式为8e

[root@localhost ~]# fdisk /dev/sdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').

Command (m for help): p

Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x611c6c72

Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
e   extended
p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-391, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-391, default 391): +1G

Command (m for help): p

Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x611c6c72

Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         132     1060258+  83  Linux

Command (m for help): t					更换硬盘格式
Selected partition 1
Hex code (type L to list codes): 8e		改为8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x611c6c72

Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         132     1060258+  8e  Linux LVM

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

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

-------------------------------------------------------分隔符-------------------------------------------------------

[root@localhost ~]# ls /dev/sd*						查看刚创建的分区
/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb  /dev/sdb1  /dev/sdc
[root@localhost ~]# partprobe /dev/sdb				如果没有的话使用该命令更新分区表

LVM命令:

创建========================================
pvcreate /dev/sdb1 /dev/sdc1		创建pv
pvs									查看pv
pvdisplay							查看pv详细信息

vgcreate vg0 /dev/sdb1 /dev/sdc1	创建vg0
vgs									查看vg
vgdisplay							查看vg详细信息

lvcreate -n lv0 -L 200M vg0			创建lv0 大小为200M,从vg0调容量
lvs									查看lv
lvdiaplay							查看lv详细信息
mkfd.ext4 /dev/vg0/lv0				挂载lvm卷
扩展vg======================================
vgextend vg0 /dev/sdc2				/dev/sdc2创建为pv添加到vg0
vgscan								查看vg
缩减vg======================================
pvscan								查看哪些pv没被使用
vgreduce vg0 /dev/sdc2				缩减sdc2
vgdisplay							查看vg详细信息
扩展lv(支持在线扩展,不用卸载)=================
lvextend -L +100M /dev/vg0/lv0		扩展100M给lv0
lvs									查看lv
resize2fs /dev/vg0/lv0				扩展文件系统容量
df -h								查看挂载容量
缩减lv(不支持在线扩展,必须卸载)================
umount /dev/vg0/lv0					卸载lv0
e2fsck -f /dev/vg0/lv0				强制检查文件系统
resize2fs /dev/vg0/lv0 150M			缩减到150M
lvreduce -L 150M /dev/vg0/lv0		缩减到150M
lvs									查看lv
mount /dev/vg0/lv0 /lvmtest			重新挂载lv0

删除:
1.卸载:umount
删除顺序:
1.删lv: lvremove lv完整路径
2.删vg:vgremove vg名
3.删PV:pvremove 设备完整路径 去硬盘

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: