美文网首页
LVM,分区扩容

LVM,分区扩容

作者: halfempty | 来源:发表于2021-12-08 17:31 被阅读0次

    1. 概述

    LVM = Logical Volume Manager,直译为 “逻辑卷组管理”,它解决了常规磁盘分区大小无法伸缩的问题

    磁盘 -> PV -> VG -> LV

    • 每个磁盘分区对应一个物理卷组(PV)
    • 多个物理卷组(PV)组成逻辑卷组(VG)
    • 逻辑卷组(VG)划分给多个逻辑卷(LV)
    image.png

    2. 分区扩容

    2.1. 磁盘 -> PV

    # 查看系统磁盘,有/dev/vda 和  /dev/vdb 共2个物理分区
    [root@bd107 ~]# fdisk -l
    
    Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0x00099229
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *        2048     2099199     1048576   83  Linux
    /dev/vda2         2099200    83886079    40893440   8e  Linux LVM
    
    Disk /dev/mapper/cl-root: 536.9 GB, 536870912000 bytes, 1048576000 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    
    
    Disk /dev/mapper/cl-swap: 4160 MB, 4160749568 bytes, 8126464 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    
    
    Disk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    
    # 磁盘转PV
    pvcreate /dev/vdb
    

    2.2. PV -> VG

    # 查看vg命名空间,名称为cl
    [root@bd107 ~]# vgdisplay 
      --- Volume group ---
      VG Name               cl
      System ID             
      Format                lvm2
      Metadata Areas        2
      Metadata Sequence No  5
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                2
      Open LV               2
      Max PV                0
      Cur PV                2
      Act PV                2
      VG Size               538.99 GiB
      PE Size               4.00 MiB
      Total PE              137982
      Alloc PE / Size       128992 / 503.88 GiB
      Free  PE / Size       8990 / 35.12 GiB
      VG UUID               T7Ovhi-Mk5V-Ry9y-s8RV-9ihc-pvgq-am0g0V
    
    # 将2.1步创建的pv加入到cl
    vgextend cl /dev/vdb
    

    2.3. VG -> LV

    # 查看逻辑卷路径,其中根分区路径为/dev/cl/root
    [root@bd107 ~]# lvdisplay 
      --- Logical volume ---
      LV Path                /dev/cl/swap
      LV Name                swap
      VG Name                cl
      LV UUID                QCN8wW-Ic4K-l3SM-LRYF-2t06-K6wM-AQoOlK
      LV Write Access        read/write
      LV Creation host, time 172-31-128-183, 2021-06-07 17:12:59 +0800
      LV Status              available
      # open                 2
      LV Size                3.88 GiB
      Current LE             992
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:1
       
      --- Logical volume ---
      LV Path                /dev/cl/root
      LV Name                root
      VG Name                cl
      LV UUID                WFIxvP-BIkN-CIJt-6UQY-kn6D-iqu1-c4n2HL
      LV Write Access        read/write
      LV Creation host, time 172-31-128-183, 2021-06-07 17:12:59 +0800
      LV Status              available
      # open                 1
      LV Size                500.00 GiB
      Current LE             128000
      Segments               2
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:0
    
    # 扩展根分区大小
    lvextend -l 100%FREE /dev/cl/root /dev/vdb
    

    2.4. 刷新分区

    适用于centos7版本

    xfs_growfs /
    

    相关文章

      网友评论

          本文标题:LVM,分区扩容

          本文链接:https://www.haomeiwen.com/subject/htutfrtx.html