linux之lvm学习
硬盘分区如何设定大小,如何规划,再好的规划也有出差错的时候,人算不如天算.
为了让我们脱离那可悲的分区与分区修改工具,请跟我来认识一下LVM-逻辑卷管理(logical volume manager).
首先先把基本术语定义讲一下:
LVM 是linux对磁盘分区进行管理的一种机制.LVM是建立在磁盘与分区之上的一个逻辑层,以提高磁盘管理的灵活性.
在LVM内有三个基本术语PV(Physical Volume 物理卷) VG(Volume Group 卷组) LV(Logical Volume 逻辑卷)
三者的关系为,先建立PV,根据PV组合或扩展形成VG,根据用户需求使用VG卷的总量去建立相应的LV卷(个人理解)
一.创建PV的命令与方法
1.查看磁盘分区情况:
[root@localhost /]# fdisk -l /dev/hdb
Disk /dev/hdb: 21.4 GB, 21474836480 bytes
15 heads, 63 sectors/track, 44384 cylinders
Units = cylinders of 945 * 512 = 483840 bytes
Device Boot Start End Blocks Id System
/dev/hdb1 1 10000 4724968+ 83 Linux
/dev/hdb2 10001 20000 4725000 83 Linux
/dev/hdb3 20001 30000 4725000 83 Linux
/dev/hdb4 30001 44384 6796440 83 Linux
共计4个分区 请大家看ID位置代码:83 system:linux,我们需要更改ID代码为8e 此为LVM卷分区标签
分区系统号更改方法如下:
[root@localhost /]# fdisk /dev/hdb
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
此时系统ID已经更改为LVM,我们再用FDISK命令查看一下磁盘情况
[root@localhost /]# fdisk -l /dev/hdb
Disk /dev/hdb: 21.4 GB, 21474836480 bytes
15 heads, 63 sectors/track, 44384 cylinders
Units = cylinders of 945 * 512 = 483840 bytes
Device Boot Start End Blocks Id System
/dev/hdb1 1 10000 4724968+ 8e Linux LVM
/dev/hdb2 10001 20000 4725000 8e Linux LVM
SYStem类型:Linux LVM,此时我们可以创建PV了,我创建了二个PV,通过pvdisplay命令可以查看创建的PV卷的情况.
[root@localhost /]# pvcreate /dev/hdb1 /dev/hdb2
Physical volume "/dev/hdb1" successfully created
Physical volume "/dev/hdb2" successfully created
查看PV卷详细信息:
[root@localhost /]# pvdisplay
"/dev/hdb1" is a new physical volume of "4.51 GB"
--- NEW Physical volume ---
PV Name /dev/hdb1
VG Name
PV Size 4.51 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID gSv31K-01SU-1Vbm-HF26-MR5W-wgBw-1EeHb0
"/dev/hdb2" is a new physical volume of "4.51 GB"
--- NEW Physical volume ---
PV Name /dev/hdb2
VG Name
PV Size 4.51 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID ODEuTv-iMqs-Wzxq-HMyB-yUw2-Lnwn-5JdlSp
我们此时再回看查看一下磁盘分区的情况.
[root@localhost /]# fdisk -l /dev/hdb
Disk /dev/hdb: 21.4 GB, 21474836480 bytes
15 heads, 63 sectors/track, 44384 cylinders
Units = cylinders of 945 * 512 = 483840 bytes
Device Boot Start End Blocks Id System
/dev/hdb1 1 10000 4724968+ 8e Linux LVM
/dev/hdb2 10001 20000 4725000 8e Linux LVM
/dev/hdb3 20001 30000 4725000 8e Linux LVM
/dev/hdb4 30001 44384 6796440 8e Linux LVM
PV创建完成,相应的命令如下:pvcreate (PV创建) pvdisplay(PV信息查看) pvremove(pv卷删除)
pvremove /dev/hdb1 (删除命令例)