linux/centos7云服务器主盘LVM根目录扩容
    文章作者:恒爱云[恒爱网络] 阅读次数:180 发布时间:2025-4-8


    查看磁盘挂载情况


     fdisk -l 


    添加磁盘分区


    fdisk /dev/sda 输入n创建一个新分区 Command (m for help): n
    p   
    编号默认回车
    起始和结束标号默认回车
    
    
    输入p再次查看已分区信息
    输入t更改分区类型(改为和sda2一样的类型将来合并) Command (m for help): t
    然后再输入8e表示是lvm格式
    Partition number (1-3, default 3): 3 Hex code (type L to list all codes): 8e
    
    Changed type of partition 'Linux' to 'Linux LVM'. 输入p再次查看已分区信息 Device     Boot    Start      End  Sectors Size Id Type
    /dev/sda1  * 2048 2099199 2097152 1G 83 Linux
    /dev/sda2 2099200 62914559 60815360 29G 8e Linux LVM
    /dev/sda3 62914560 83886079 20971520 10G 8e Linux LVM 输入w保存并退出
    .重启虚拟机reboot


    扩容磁盘


    pvdisplay
    回显:
     --- Physical volume ---
      PV Name               /dev/sda2
      VG Name               centos
      PV Size               <29.00 GiB / not usable 3.00 MiB
      Allocatable           yes (but full) PE Size               4.00 MiB
      Total PE 7423 Free PE 0 Allocated PE 7423 PV UUID               eMFIcc-TfvQ-yXpB-14pu-zJ1x-IAlr-WEBvlT 
    创建新物理卷信息 
    pvcreate /dev/sda3 
    Physical volume "/dev/sda3" successfully created. 
    再查看物理卷信息
     pvdisplay
     --- Physical volume ---
      PV Name               /dev/sda2
      VG Name               cl
      PV Size               <29.00 GiB / not usable 3.00 MiB
      Allocatable           yes (but full) PE Size               4.00 MiB
      Total PE 7423 Free PE 0 Allocated PE 7423 PV UUID               eMFIcc-TfvQ-yXpB-14pu-zJ1x-IAlr-WEBvlT "/dev/sda3" is a new physical volume of "10.00 GiB" --- NEW Physical volume ---
      PV Name               /dev/sda3
      VG Name               
      PV Size               10.00 GiB
      Allocatable           NO
      PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID               oqPz9B-TSEF-3cQZ-bJP8-rvAo-Ud5S-hUUgwb 
     
    将/dev/sda3添加导/dev/sda2对应的VG名centos中去 
    vgextend centos /dev/sda3 
    Volume group "centos" successfully extended 
    再次查看物理卷信息
    pvdisplay
     
    查看磁盘信息 # 我们要扩容的磁盘是/dev/mapper/centos-root 
    df -h 
    扩容 
    lvextend -l +100%FREE /dev/mapper/centos-root 
    扩容/dev/mapper/centos-root对应的文件系统/ 
    xfs_growfs / 
    查看磁盘信息(扩容完毕) 
    df -h