LVM。。。让我理解就是一个将好多分区磁盘帮到一起的玩意,类似于烙大饼。。。然后再切
新建了一个虚拟机,然后又挂了一个5G的硬盘,然后分出了5块空间,挂载到了虚拟机上。这些步骤很简单
fdisk mkdir mount......不赘述了。。。鸟哥也不赘述我也就不赘述了。继续看重点
这是鸟哥的官方解释,看看,是不是跟我说的一样摊大饼,在切割?买过饼吃的人都应该懂的。。。。
LVM概念
好了。概念讲完了,鸟哥讲了动态分配的实现原理,继续截图
这几个东东的关系,你看明白了么?没看明白不要紧,我给你做大饼吃
首先,将磁盘都做成LVM可识别的格式。就是PV
然后,用VG将这些PV串成一张大饼
最后,就是切大饼 LV。那LV的最基础的组成部分是什么呢?就是PE。PE就是切块的最小单元。
看完我做的大饼,再看上面的图,是否会更理解一下。
也就是说,你要扩充只能扩充VG中未被LV切块的饼,是否能明白,稍微懂点分区的都明白应该。比如你现在空间不够了,需要干嘛,先PV,然后加入到VG,然后再切饼。
LVM硬盘写入,鸟哥说有两种模式
线性模式,写完一张再写另一张
交错模式,文件分成两部分,两张硬盘,交互写入。注:我没看明白为啥当初要设计这种模式的原因
[root@localhost ~]# pvcreate /dev/sdb{1,2,3,4,5} Device /dev/sdb1 excluded by a filter. Physical volume "/dev/sdb2" successfully created. Physical volume "/dev/sdb3" successfully created. Physical volume "/dev/sdb4" successfully created. Physical volume "/dev/sdb5" successfully created.
[root@localhost ~]# pvdisplay /dev/sdb3 WARNING: Device for PV rGAe2U-E01D-o80Z-GG2n-Q3Gt-JnxH-QpdECV not found or rejected by a filter. "/dev/sdb3" is a new physical volume of "954.00 MiB" --- NEW Physical volume --- PV Name /dev/sdb3 VG Name PV Size 954.00 MiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID tiph15-4Jg5-4Yf0-Rdtn-Jj0o-Vmgj-LBpfhu
鸟哥的解释很透彻,截图如下
[root@localhost ~]# vgcreate -s 16M lsqvg /dev/sdb{1,2,3} WARNING: Device for PV rGAe2U-E01D-o80Z-GG2n-Q3Gt-JnxH-QpdECV not found or rejected by a filter. WARNING: Device for PV rGAe2U-E01D-o80Z-GG2n-Q3Gt-JnxH-QpdECV not found or rejected by a filter. Volume group "lsqvg" successfully created [root@localhost ~]# vgscan Reading volume groups from cache. Found volume group "lsqvg" using metadata type lvm2 Found volume group "centos" using metadata type lvm2 [root@localhost ~]# pvscan WARNING: Device for PV rGAe2U-E01D-o80Z-GG2n-Q3Gt-JnxH-QpdECV not found or rejected by a filter. PV /dev/sdb1 VG lsqvg lvm2 [944.00 MiB / 944.00 MiB free] PV /dev/sdb2 VG lsqvg lvm2 [944.00 MiB / 944.00 MiB free] PV /dev/sdb3 VG lsqvg lvm2 [944.00 MiB / 944.00 MiB free] PV /dev/sda2 VG centos lvm2 [19.70 GiB / 8.00 MiB free] PV /dev/sdb4 lvm2 [954.00 MiB] Total: 5 [23.40 GiB] / in use: 4 [<22.47 GiB] / in no VG: 1 [954.00 MiB] [root@localhost ~]# vgdisplay lsqvg --- Volume group --- VG Name lsqvg System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 3 Act PV 3 VG Size <2.77 GiB PE Size 16.00 MiB Total PE 177 Alloc PE / Size 0 / 0 Free PE / Size 177 / <2.77 GiB VG UUID yLBdez-VeIK-2xjQ-bMeT-8IBH-ENt3-Mu9NwE [root@localhost ~]# vgextend lsqvg /dev/sdb4 WARNING: Device for PV rGAe2U-E01D-o80Z-GG2n-Q3Gt-JnxH-QpdECV not found or rejected by a filter. Volume group "lsqvg" successfully extended [root@localhost ~]# vgdisplay lsqvg --- Volume group --- VG Name lsqvg System ID Format lvm2 Metadata Areas 4 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 4 Act PV 4 VG Size <3.69 GiB PE Size 16.00 MiB Total PE 236 Alloc PE / Size 0 / 0 Free PE / Size 236 / <3.69 GiB VG UUID yLBdez-VeIK-2xjQ-bMeT-8IBH-ENt3-Mu9NwE
通过上述加粗,可以看出,如何新增VG。另VG的名字我们是可以自定义的,然后我们定义了每个PE的大小。第一行红色的位置。基本上VG就这么些东东。也不难
PE有了。VG这张大饼也有了。剩下的就是需要对VG这张大饼切分了。通过我们上面的步骤可以看出,就是利用LV
让我们来跟着鸟哥实践一下
[root@localhost ~]# lvcreate -L 2G -n lsqlv lsqvg WARNING: LVM2_member signature detected on /dev/lsqvg/lsqlv at offset 536. Wipe it? [y/n]: y Wiping LVM2_member signature on /dev/lsqvg/lsqlv. Logical volume "lsqlv" created. [root@localhost ~]# lvscan ACTIVE '/dev/lsqvg/lsqlv' [2.00 GiB] inherit ACTIVE '/dev/centos/var' [1.86 GiB] inherit ACTIVE '/dev/centos/swap' [192.00 MiB] inherit ACTIVE '/dev/centos/root' [9.31 GiB] inherit ACTIVE '/dev/centos/home' [8.33 GiB] inherit [root@localhost ~]# lvdisplay /dev/lsqlv Volume group "lsqlv" not found Cannot process volume group lsqlv [root@localhost ~]# lvdisplay /dev/lsqvg/lsqlv --- Logical volume --- LV Path /dev/lsqvg/lsqlv LV Name lsqlv VG Name lsqvg LV UUID I36ZBB-abG3-YZVt-h61R-qAya-ohn0-5GmH2n LV Write Access read/write LV Creation host, time localhost.localdomain, 2019-08-20 11:00:50 +0800 LV Status available # open 0 LV Size 2.00 GiB Current LE 128 Segments 3 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:4
我们跟着鸟哥,创建了一个2G大小的LV。名字就是我自己的名字喽。
然后查看一下。可以看到我们的LV的相关情况,还有其他的LV的情况,就是系统设置的LV的情况
然后单独查看我们自己的LV,可以看到他的大小,名称,等相关信息
OK。LV建立之后,就是格式化,挂载等等了。让我们跟着鸟哥继续往下走
[root@localhost ~]# mkdir /srv/lvm [root@localhost ~]# mount /dev/lsqvg/lsqlv /srv/lvm mount: /dev/mapper/lsqvg-lsqlv 写保护,将以只读方式挂载 mount: 未知的文件系统类型“(null)” [root@localhost ~]# ^C [root@localhost ~]# unmount /srv/lvm bash: unmount: 未找到命令... [root@localhost ~]# umount /srv/lvm umount: /srv/lvm:未挂载 [root@localhost ~]# mkfs.xfs /dev/lsqvg/lsqlv meta-data=/dev/lsqvg/lsqlv isize=512 agcount=4, agsize=131072 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=524288, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@localhost ~]# mount /dev/lsqvg/lsqlv /dev/lvm mount: 挂载点 /dev/lvm 不存在 [root@localhost ~]# mount /dev/lsqvg/lsqlv /srv/lvm [root@localhost ~]# df -Th /srv/lvm 文件系统 类型 容量 已用 可用 已用% 挂载点 /dev/mapper/lsqvg-lsqlv xfs 2.0G 33M 2.0G 2% /srv/lvm
首先创建一个挂载点 /srv/lvm
然后格式化一下,格式化命令mkfs.xfs /dev/lsqvg/lsqlv 然后进行了格式化。加粗的信息就是格式化后的相关信息。
然后利用mount进行挂载,挂载之后。df -Th查看一下相关的信息。可以看到相关情况,表明我们挂载成功。