centos7 根目录扩容(xfs无lvm)

现状:
centos 7,/对应分区为xfs格式,且无lvm。
只有一个分区,大小40GB,而整个磁盘大小200GB。
目标:
将剩余磁盘空间都分配给当前分区。基本步骤为先调整分区大小,再调整mount的/的大小。

  • 查看当前/分区文件系统为xfs,大小40GB
[root@hgcndn ~]# df -Th FilesystemTypeSizeUsed Avail Use% Mounted on devtmpfsdevtmpfs489M0489M0% /dev tmpfstmpfs496M8.0K496M1% /dev/shm tmpfstmpfs496M38M458M8% /run tmpfstmpfs496M0496M0% /sys/fs/cgroup /dev/sda1xfs40G40G585M99% / tmpfstmpfs100M0100M0% /run/user/1001 vagrantvboxsf376G157G220G42% /vagrant vagrant_datavboxsf376G157G220G42% /vagrant_data tmpfstmpfs100M0100M0% /run/user/1000

  • 【centos7 根目录扩容(xfs无lvm)】查看当前分区信息
    [root@hgcndn ~]# lsblk NAMEMAJ:MIN RMSIZE RO TYPE MOUNTPOINT sda8:00200G0 disk └─sda18:1040G0 part /[root@hgcndn ~]# fdisk -l /dev/sdaDisk /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 BootStartEndBlocksIdSystem /dev/sda1*2048838860794194201683Linux

  • 安装需要的工具
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 NAMEMAJ:MIN RMSIZE RO TYPE MOUNTPOINT sda8:00200G0 disk └─sda18:10200G0 part /

  • xfs_growfs 扩容 /
    [root@hgcndn ~]# xfs_growfs / meta-data=https://www.it610.com/dev/sda1isize=512agcount=4, agsize=2621376 blks =sectsz=512attr=2, projid32bit=1 =crc=1finobt=0 spinodes=0 data=bsize=4096blocks=10485504, imaxpct=25 =sunit=0swidth=0 blks naming=version 2bsize=4096ascii-ci=0 ftype=1 log=internalbsize=4096blocks=5119, version=2 =sectsz=512sunit=0 blks, lazy-count=1 realtime =noneextsz=4096blocks=0, rtextents=0 data blocks changed from 10485504 to 52428539

  • 确认/扩容为200GB
[root@hgcndn ~]# df -Th FilesystemTypeSizeUsed Avail Use% Mounted on devtmpfsdevtmpfs489M0489M0% /dev tmpfstmpfs496M8.0K496M1% /dev/shm tmpfstmpfs496M38M458M8% /run tmpfstmpfs496M0496M0% /sys/fs/cgroup /dev/sda1xfs200G40G161G20% / tmpfstmpfs100M0100M0% /run/user/1001 vagrantvboxsf376G157G219G42% /vagrant vagrant_datavboxsf376G157G219G42% /vagrant_data tmpfstmpfs100M0100M0% /run/user/1000

    推荐阅读