该方式同样适用于其它类型的磁盘扩容,前提是你的磁盘格式是LVM

    1. 首先在 Proxmox 5.3 Web页面“调整磁盘大小”,

    1. 登陆到虚拟机
    [root@c720176 ~]# fdisk -l
    
    Disk /dev/sda: 85.9 GB, 85899345920 bytes, 167772160 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: 0x000bbf54
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     2099199     1048576   83  Linux
    /dev/sda2         2099200    20971519     9436160   8e  Linux LVM
    
    Disk /dev/mapper/centos-root: 8585 MB, 8585740288 bytes, 16769024 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: 1073 MB, 1073741824 bytes, 2097152 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@c720176 ~]# fdisk /dev/sda
    p               // 打印分区表
    n               // 新建分区
    p               // 新建主分区
    回车            // 分区号码,保持默认即可
    回车            // 开启扇区位置
    回车            // 结束扇区位置
    p              // 打印分区表
    t              // 修改分区类型
    回车           // 默认选择最后一个分区
    8e             // lvm类型
    p              // 打印分区表
    w              // 写入
    
    // 创建 pv
    [root@c720177 ~]# reboot         // 重启
    [root@c720177 ~]# pvcreate /dev/sda3
    [root@c720177 ~]# vgdisplay 
      --- Volume group ---
      VG Name               centos
      System ID             
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  3
      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               <9.00 GiB
      PE Size               4.00 MiB
      Total PE              2303
      Alloc PE / Size       2303 / <9.00 GiB
      Free  PE / Size       0 / 0   
      VG UUID               tg47CY-frFO-kSKe-AGk5-ygQ9-4yqp-1isPvj
    
    // 扩展vg
    [root@c720177 ~]# vgextend centos /dev/sda3
      Volume group "centos" successfully extended
    [root@c720177 ~]# vgdisplay 
      --- Volume group ---
      VG Name               centos
      System ID             
      Format                lvm2
      Metadata Areas        2
      Metadata Sequence No  4
      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               78.99 GiB
      PE Size               4.00 MiB
      Total PE              20222
      Alloc PE / Size       2303 / <9.00 GiB
      Free  PE / Size       17919 / <70.00 GiB
      VG UUID               tg47CY-frFO-kSKe-AGk5-ygQ9-4yqp-1isPvj
    
    // 扩展 LV
    [root@c720177 ~]# lvdisplay 
      --- Logical volume ---
      LV Path                /dev/centos/swap
      LV Name                swap
      VG Name                centos
      LV UUID                p56QTa-M2Wm-bTgH-oOwk-0AiZ-lBly-NmQST8
      LV Write Access        read/write
      LV Creation host, time localhost, 2019-01-02 21:48:14 +0800
      LV Status              available
      # open                 2
      LV Size                1.00 GiB
      Current LE             256
      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                NdxCMw-ZiFz-C1fz-ECLz-0jXc-z59f-9UpBG0
      LV Write Access        read/write
      LV Creation host, time localhost, 2019-01-02 21:48:15 +0800
      LV Status              available
      # open                 1
      LV Size                <8.00 GiB
      Current LE             2047
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:0
    
    [root@c720177 ~]# lvextend -l +99%FREE /dev/centos/root
      Size of logical volume centos/root changed from <8.00 GiB (2047 extents) to 77.29 GiB (19787 extents).
      Logical volume centos/root successfully resized.
    
    // 重新读取磁盘分区
    [root@c720177 ~]# df -lh
    Filesystem               Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root  8.0G  1.1G  7.0G  14% /
    devtmpfs                 1.9G     0  1.9G   0% /dev
    tmpfs                    1.9G     0  1.9G   0% /dev/shm
    tmpfs                    1.9G  8.5M  1.9G   1% /run
    tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
    /dev/sda1               1014M  142M  873M  14% /boot
    tmpfs                    379M     0  379M   0% /run/user/56361
    
    [root@c720177 ~]# xfs_growfs /dev/centos/root
    meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=524032 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=0 spinodes=0
    data     =                       bsize=4096   blocks=2096128, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    log      =internal               bsize=4096   blocks=2560, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    data blocks changed from 2096128 to 20261888
    
    [root@c720177 ~]# df -lh
    Filesystem               Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root   78G  1.1G   77G   2% /
    devtmpfs                 1.9G     0  1.9G   0% /dev
    tmpfs                    1.9G     0  1.9G   0% /dev/shm
    tmpfs                    1.9G  8.5M  1.9G   1% /run
    tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
    /dev/sda1               1014M  142M  873M  14% /boot
    tmpfs                    379M     0  379M   0% /run/user/56361
    作者:jackzang  创建时间:2023-03-07 15:08
    最后编辑:jackzang  更新时间:2023-03-07 15:08