centos 磁盘管理(lvm模式)

这种磁盘管理方式相对于标准模式的优势在于,它可以动态的改变磁盘大小。
步骤:
1)要有一个物理磁盘或者是多个没有被格式化的分区(physical volume—pv)
2)多个物理卷组合成一个卷组(volume group)
3)重卷组中划分出逻辑卷(logic volume)

下面开始以lvm模式多Linux磁盘进行管理:
首先要先安装lvm包

yum install -y lvm2

安装好了后,开始划分物理卷,我这里采用的是多个为被格式化的标准分区。

[root@weijie ~]# pvcreate /dev/sdb5
[root@weijie ~]# pvdisplay 
  "/dev/sdb2" is a new physical volume of "1.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb2
  VG Name               
  PV Size               1.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               w3EdeD-JV3e-uFXb-eQ4R-eA7P-91aj-3MvjWU
   
  "/dev/sdb5" is a new physical volume of "1.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb5
  VG Name               
  PV Size               1.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               M84fIM-PItt-tDGe-HYzj-5VQw-sjGh-4j0mDb
   
  "/dev/sdb3" is a new physical volume of "2.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb3
  VG Name               
  PV Size               2.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               GWOCoq-I8QU-Yzjt-tx7O-qPTA-idVc-16xpoL

可以看到我这里划分出了3个pv。
下面把这3个pv划分到一个卷组中:

[root@weijie ~]# vgcreate vg1 /dev/sdb3 /dev/sdb2 /dev/sdb5
  Volume group "vg1" successfully created
[root@weijie ~]# ls
anaconda-ks.cfg
[root@weijie ~]# vgdisplay 
  --- Volume group ---
  VG Name               vg1
  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               <3.99 GiB
  PE Size               4.00 MiB
  Total PE              1021
  Alloc PE / Size       0 / 0   
  Free  PE / Size       1021 / <3.99 GiB
  VG UUID               4Oq7ZJ-ijut-5Ecz-6V9M-S0t4-qajD-S01GVy

创建好了vg,并查看。
然后开始划分逻辑卷,之后就可以挂载了:

[root@weijie ~]# lvcreate -L 500M -n lv1 vg1
  Logical volume "lv1" created.

-L 指定逻辑卷的大小
-n 指定逻辑卷的名字

最后对这个逻辑分区进行格式化,挂载。

[root@weijie ~]# mkfs.xfs /dev/vg1/lv1 //格式化这个逻辑卷
meta-data=/dev/vg1/lv1           isize=512    agcount=4, agsize=32000 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=128000, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@weijie ~]# mount /dev/vg1/lv1 /home/lala
[root@weijie ~]# df -h //查看下磁盘挂载情况
Filesystem           Size  Used Avail Use% Mounted on
/dev/sda3             14G  1.8G   13G  13% /
devtmpfs             479M     0  479M   0% /dev
tmpfs                489M     0  489M   0% /dev/shm
tmpfs                489M  6.8M  482M   2% /run
tmpfs                489M     0  489M   0% /sys/fs/cgroup
/dev/mapper/vg1-lv1  497M   26M  472M   6% /home/lala  //可以看到lv1已经被挂载
/dev/sda1            473M  111M  362M  24% /boot
tmpfs                 98M     0   98M   0% /run/user/0

好下面就是体现lvm磁盘管理的优势的地方了。
假如我lv1磁盘空间不够用了,我就需要对它进行扩容,如果是标准分区的话,你需要先分区,然后格式化,然后再挂载,很麻烦。而在lvm模式下,我们只需对逻辑卷(lv1)进行修改就可以了。

[root@weijie ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/vg1/lv1
  LV Name                lv1
  VG Name                vg1
  LV UUID                7EpNbn-BZoq-yZ23-ZMxq-kPaY-aQYx-wQRO5o
  LV Write Access        read/write
  LV Creation host, time weijie, 2020-02-29 14:12:32 +0800
  LV Status              available
  # open                 1
  LV Size                500.00 MiB  //没有扩容前是500M
  Current LE             125
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
  [root@weijie ~]# lvresize -L 800M /dev/vg1/lv1 //我想把lv1扩容到800M
  Size of logical volume vg1/lv1 changed from 500.00 MiB (125 extents) to 800.00 MiB (200 extents).
  Logical volume vg1/lv1 successfully resized.
[root@weijie ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/vg1/lv1
  LV Name                lv1
  VG Name                vg1
  LV UUID                7EpNbn-BZoq-yZ23-ZMxq-kPaY-aQYx-wQRO5o
  LV Write Access        read/write
  LV Creation host, time weijie, 2020-02-29 14:12:32 +0800
  LV Status              available
  # open                 1
  LV Size                800.00 MiB //经过修改后变为800M
  Current LE             200
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

但是!!!!!!!!!!!!

[root@weijie ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/sda3             14G  1.8G   13G  13% /
devtmpfs             479M     0  479M   0% /dev
tmpfs                489M     0  489M   0% /dev/shm
tmpfs                489M  6.7M  482M   2% /run
tmpfs                489M     0  489M   0% /sys/fs/cgroup
/dev/mapper/vg1-lv1  497M   26M  472M   6% /home/lala
/dev/sda1            473M  111M  362M  24% /boot
tmpfs                 98M     0   98M   0% /run/user/0

从这里查看还是只有500M 实际上lv1已经变成了800M 只是没有多磁块信息进行更新。

[root@weijie test]# xfs_growfs /dev/vg1/lv1
meta-data=/dev/mapper/vg1-lv1    isize=512    agcount=4, agsize=32000 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=128000, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 128000 to 204800

这样在线更新后,在查看磁盘分配情况。

[root@weijie test]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/sda3             14G  1.8G   13G  13% /
devtmpfs             479M     0  479M   0% /dev
tmpfs                489M     0  489M   0% /dev/shm
tmpfs                489M  6.7M  482M   2% /run
tmpfs                489M     0  489M   0% /sys/fs/cgroup
/dev/sdb1            2.0G   33M  2.0G   2% /home/lala
/dev/sda1            473M  111M  362M  24% /boot
tmpfs                 98M     0   98M   0% /run/user/0
/dev/mapper/vg1-lv1  797M   26M  772M   4% /test

这里可以看到成功的变成了800M了
你以为这就结束了??不不不,lvm模式的动态扩容不仅可以扩逻辑卷,还可以扩卷组。
我们重新在创建一个物理卷,然后把它划入卷组

  [root@weijie /]# pvcreate /dev/sdb6
  Physical volume "/dev/sdb6" successfully created.
  [root@weijie /]# vgextend  vg1 /dev/sdb6
  Volume group "vg1" successfully extended
  [root@weijie /]# vgdisplay 
  --- Volume group ---
  VG Name               vg1
  System ID             
  Format                lvm2
  Metadata Areas        4
  Metadata Sequence No  7
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               0
  Max PV                0
  Cur PV                4
  Act PV                4
  VG Size               5.98 GiB
  PE Size               4.00 MiB
  Total PE              1532
  Alloc PE / Size       200 / 800.00 MiB
  Free  PE / Size       1332 / 5.20 GiB
  VG UUID               4Oq7ZJ-ijut-5Ecz-6V9M-S0t4-qajD-S01GVy

这里就可以看到卷组已经扩大了

你可能感兴趣的:(centos 磁盘管理(lvm模式))