centos7 根目录扩容(xfs无lvm)

现状:
centos 7,/对应分区为xfs格式,且无lvm。
只有一个分区,大小40GB,而整个磁盘大小200GB。

目标:
将剩余磁盘空间都分配给当前分区。基本步骤为先调整分区大小,再调整mount的/的大小。

  • 查看当前/分区文件系统为xfs,大小40GB
[root@hgcndn ~]# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
devtmpfs       devtmpfs  489M     0  489M   0% /dev
tmpfs          tmpfs     496M  8.0K  496M   1% /dev/shm
tmpfs          tmpfs     496M   38M  458M   8% /run
tmpfs          tmpfs     496M     0  496M   0% /sys/fs/cgroup
/dev/sda1      xfs        40G   40G  585M  99% /
tmpfs          tmpfs     100M     0  100M   0% /run/user/1001
vagrant        vboxsf    376G  157G  220G  42% /vagrant
vagrant_data   vboxsf    376G  157G  220G  42% /vagrant_data
tmpfs          tmpfs     100M     0  100M   0% /run/user/1000
  • 查看当前分区信息

    [root@hgcndn ~]# lsblk
    NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda      8:0    0  200G  0 disk
    └─sda1   8:1    0   40G  0 part /
    
    [root@hgcndn ~]# fdisk -l /dev/sda
    
    Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 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: 0x0009ef1a
    
     Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048    83886079    41942016   83  Linux
    
  • 安装需要的工具
yum install cloud-utils-growpart gdisk -y
  • growpart重写分区表,调整分区大小,1为分区号,如果扩容sd2,则为2

    [root@hgcndn ~]# growpart /dev/sda 1
    CHANGED: partition=1 start=2048 old: size=83884032 end=83886080 new: size=419428319 end=419430367
  • 确认分区大小已经调整为200GB

    [root@hgcndn ~]# lsblk
    NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda      8:0    0  200G  0 disk
    └─sda1   8:1    0  200G  0 part /
  • xfs_growfs 扩容 /

    [root@hgcndn ~]# xfs_growfs /
    meta-data=/dev/sda1              isize=512    agcount=4, agsize=2621376 blks
           =                       sectsz=512   attr=2, projid32bit=1
           =                       crc=1        finobt=0 spinodes=0
    data     =                       bsize=4096   blocks=10485504, imaxpct=25
           =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    log      =internal               bsize=4096   blocks=5119, version=2
           =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    data blocks changed from 10485504 to 52428539
  • 确认/扩容为200GB
[root@hgcndn ~]# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
devtmpfs       devtmpfs  489M     0  489M   0% /dev
tmpfs          tmpfs     496M  8.0K  496M   1% /dev/shm
tmpfs          tmpfs     496M   38M  458M   8% /run
tmpfs          tmpfs     496M     0  496M   0% /sys/fs/cgroup
/dev/sda1      xfs       200G   40G  161G  20% /
tmpfs          tmpfs     100M     0  100M   0% /run/user/1001
vagrant        vboxsf    376G  157G  219G  42% /vagrant
vagrant_data   vboxsf    376G  157G  219G  42% /vagrant_data
tmpfs          tmpfs     100M     0  100M   0% /run/user/1000

你可能感兴趣的:(centos扩容)