CentOS 7 硬盘扩容

centos的磁盘不够用了,在VM虚拟机中,增加了硬盘大小,但是系统中需要一些命令才能识别那些没有被使用的空间,以下用来记录如何通过一系列的命令。

设置磁盘

  • 查看磁盘分区fdisk -l

查看磁盘分区

  • 增加分区fdisk /dev/sda
    依次输入p、n、p、w
    m:是列出菜单,
    p:是列出分区表,
    n:是增加分区,
    w:是保存并退出

fdisk 命令

  • 重启系统reboot

将新分区扩容到指定目录

  • 首先查看当前的文件系统df -h

文件系统查看

  • 执行扩容命令

    • [root@localhost ~]# lvm
      lvm> pvcreate /dev/sda3
      Physical volume “/dev/sda3” successfully created.
      lvm> vgextend centos /dev/sda3
      Volume group “centos” successfully extended
      lvm> lvextend -L +100GB /dev/mapper/centos-home
      Size of logical volume centos/home changed from <91.12 GiB (23326 extents) to <191.12 GiB (48926 extents).
      Logical volume centos/home successfully resized.
      lvm> pvdisplay
       — Physical volume —
      PV Name               /dev/sda2
      VG Name               centos
      PV Size               <149.00 GiB / not usable 3.00 MiB
      Allocatable           yes (but full)
      PE Size               4.00 MiB
      Total PE              38143
      Free PE               0
      Allocated PE          38143
      PV UUID               heGCYv-HUgZ-Q9HY-2srf-noEq-Myqo-HQBVsN
       
       — Physical volume —
      PV Name               /dev/sda3
      VG Name               centos
      PV Size               100.00 GiB / not usable 4.00 MiB
      Allocatable           yes (but full)
      PE Size               4.00 MiB
      Total PE              25599
      Free PE               0
      Allocated PE          25599
      PV UUID               HRSTiY-XRgV-NAKF-Zv4v-2QUh-6O93-Lkfoiu
       
      lvm> quit
      Exiting.
      [root@localhost ~]# xfs_growfs /dev/mapper/centos-home

    • 确认执行结果

      • df -h
Author: Gavin Zhao
Link: https://www.gavinz.xyz/2021/11/19/centos-7-硬盘扩容/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.