1. CentOs根目录扩充磁盘空间

  1. 通过虚拟机或者实体机扩充磁盘空间,比如增加50G

    [root@2-7 ~]# fdisk -l
    
    Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x000b2bf1
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     2099199     1048576   83  Linux
    /dev/sda2         2099200   104857599    51379200   8e  Linux LVM
    
    Disk /dev/mapper/centos-root: 47.2 GB, 47240445952 bytes, 92266496 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/centos-swap: 5368 MB, 5368709120 bytes, 10485760 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
  2. 创建新的磁盘分区

    [root@2-7 ~]# fdisk /dev/sda
    Welcome to fdisk (util-linux 2.23.2).
    
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
    
    
    Command (m for help): m
    Command action
       a   toggle a bootable flag
       b   edit bsd disklabel
       c   toggle the dos compatibility flag
       d   delete a partition
       g   create a new empty GPT partition table
       G   create an IRIX (SGI) partition table
       l   list known partition types
       m   print this menu
       n   add a new partition
       o   create a new empty DOS partition table
       p   print the partition table
       q   quit without saving changes
       s   create a new empty Sun disklabel
       t   change a partition's system id
       u   change display/entry units
       v   verify the partition table
       w   write table to disk and exit
       x   extra functionality (experts only)
    
    Command (m for help): n
    Partition type:
       p   primary (2 primary, 0 extended, 2 free)
       e   extended
    Select (default p): p
    Partition number (3,4, default 3):
    First sector (104857600-209715199, default 104857600):
    Using default value 104857600
    Last sector, +sectors or +size{K,M,G} (104857600-209715199, default 209715199):
    Using default value 209715199
    Partition 3 of type Linux and of size 50 GiB is set
    
    Command (m for help): t
    Partition number (1-3, default 3): 3
    Hex code (type L to list all codes): 8e
    Changed type of partition 'Linux' to 'Linux LVM'
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    
    WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
    The kernel still uses the old table. The new table will be used at
    the next reboot or after you run partprobe(8) or kpartx(8)
    Syncing disks.
    
    [root@2-7 ~]# reboot
  3. 查看物理分区(已增加/dev/sda3)及物理卷组(VFree为0)

    [root@2-7 ~]# fdisk -l
    
    Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x000b2bf1
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     2099199     1048576   83  Linux
    /dev/sda2         2099200   104857599    51379200   8e  Linux LVM
    /dev/sda3       104857600   209715199    52428800   8e  Linux LVM
    
    Disk /dev/mapper/centos-root: 47.2 GB, 47240445952 bytes, 92266496 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/centos-swap: 5368 MB, 5368709120 bytes, 10485760 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
    [root@2-7 ~]# vgs
      VG     #PV #LV #SN Attr   VSize   VFree
      centos   1   2   0 wz--n- <49.00g    0
    [root@2-7 ~]# vgdisplay
      --- Volume group ---
      VG Name               centos
      System ID
      Format                lvm2
      Metadata Areas        1
      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                1
      Act PV                1
      VG Size               <49.00 GiB
      PE Size               4.00 MiB
      Total PE              12543
      Alloc PE / Size       12543 / <49.00 GiB
      Free  PE / Size       0 / 0
      VG UUID               VlZxed-BsNy-Xo4H-el5c-BYIP-DVVh-pzcFTr
  4. 创建新的物理卷组

    [root@2-7 ~]# vgextend centos /dev/sda3
      Volume group "centos" successfully extended
  5. 查看物理卷组(VFree增加50G)和逻辑卷(/dev/centos/root的LV Size为44G)

    [root@2-7 ~]# vgs
      VG     #PV #LV #SN Attr   VSize  VFree
      centos   2   2   0 wz--n- 98.99g <50.00g
    [root@2-7 ~]# vgdisplay
      --- Volume group ---
      VG Name               centos
      System ID
      Format                lvm2
      Metadata Areas        2
      Metadata Sequence No  6
      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               98.99 GiB
      PE Size               4.00 MiB
      Total PE              25342
      Alloc PE / Size       12543 / <49.00 GiB
      Free  PE / Size       12799 / <50.00 GiB
      VG UUID               VlZxed-BsNy-Xo4H-el5c-BYIP-DVVh-pzcFTr
    [root@2-7 ~]# lvdisplay
      --- Logical volume ---
      LV Path                /dev/centos/swap
      LV Name                swap
      VG Name                centos
      LV UUID                QyktiL-UteY-Ll0R-lcT8-eHgz-50l0-Gy8Bul
      LV Write Access        read/write
      LV Creation host, time localhost, 2021-09-03 13:19:17 +0800
      LV Status              available
      # open                 2
      LV Size                5.00 GiB
      Current LE             1280
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:1
    
      --- Logical volume ---
      LV Path                /dev/centos/root
      LV Name                root
      VG Name                centos
      LV UUID                3EC7w9-sDQz-hEAQ-EPE1-FsAp-1Aw3-yqPVFP
      LV Write Access        read/write
      LV Creation host, time localhost, 2021-09-03 13:19:17 +0800
      LV Status              available
      # open                 1
      LV Size                <44.00 GiB
      Current LE             11263
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:0
  6. 扩展 LVM 的逻辑卷 centos-root

    [root@2-7 ~]# lvextend /dev/centos/root /dev/sda3
      Size of logical volume centos/root changed from <44.00 GiB (11263 extents) to 93.99 GiB (24062 extents).
      Logical volume centos/root successfully resized.
  7. 查看逻辑卷(dev/centos/root的LV Size已增加到93G)和系统文件(/为44G)

    [root@2-7 ~]# lvdisplay
      --- Logical volume ---
      LV Path                /dev/centos/swap
      LV Name                swap
      VG Name                centos
      LV UUID                QyktiL-UteY-Ll0R-lcT8-eHgz-50l0-Gy8Bul
      LV Write Access        read/write
      LV Creation host, time localhost, 2021-09-03 13:19:17 +0800
      LV Status              available
      # open                 2
      LV Size                5.00 GiB
      Current LE             1280
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:1
    
      --- Logical volume ---
      LV Path                /dev/centos/root
      LV Name                root
      VG Name                centos
      LV UUID                3EC7w9-sDQz-hEAQ-EPE1-FsAp-1Aw3-yqPVFP
      LV Write Access        read/write
      LV Creation host, time localhost, 2021-09-03 13:19:17 +0800
      LV Status              available
      # open                 1
      LV Size                93.99 GiB
      Current LE             24062
      Segments               2
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:0
    [root@2-7 ~]# df -h
    Filesystem                  Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root      44G   43G  1.6G  97% /
    devtmpfs                    9.8G     0  9.8G   0% /dev
    tmpfs                       9.8G   28K  9.8G   1% /dev/shm
    tmpfs                       9.8G  8.6M  9.8G   1% /run
    tmpfs                       9.8G     0  9.8G   0% /sys/fs/cgroup
    /dev/sda1                  1014M  145M  870M  15% /boot
    tmpfs                       2.0G     0  2.0G   0% /run/user/0
  8. 同步文件系统(xfs_growfs或者resize2fs)

    [root@2-7 ~]# xfs_growfs /dev/centos/root
    meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=2883328 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=0 spinodes=0
    data     =                       bsize=4096   blocks=11533312, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    log      =internal               bsize=4096   blocks=5631, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    data blocks changed from 11533312 to 24639488
  9. 查看文件系统大小(/为90G)

    [root@2-7 ~]# df -h
    Filesystem                  Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root      94G   43G   52G  46% /
    devtmpfs                    9.8G     0  9.8G   0% /dev
    tmpfs                       9.8G   28K  9.8G   1% /dev/shm
    tmpfs                       9.8G  8.5M  9.8G   1% /run
    tmpfs                       9.8G     0  9.8G   0% /sys/fs/cgroup
    /dev/sda1                  1014M  145M  870M  15% /boot
    tmpfs                       2.0G     0  2.0G   0% /run/user/0

2. gdisk解决磁盘分区2T限制