How to Extend Standard Partition on Linux

CentOS 7.9
/dev/vda3, /, xfs, 15G -> 16G

  1. Confirm the disk /dev/vda size is increase.
~]# for i in /sys/class/scsi_host/host*/scan; do echo '- - -' > $i; done
~]# echo 1 > /sys/class/block/vda/device/rescan

~]# fdisk -l

Disk /dev/vda: 16.1 GB, 16106127360 bytes, 31457280 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: 0x000c3ae3

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 2099199 1048576 83 Linux
/dev/vda2 2099200 4196351 1048576 82 Linux swap / Solaris
/dev/vda3 4196352 20971519 8387584 83 Linux
  1. Extend the partition.

a) Method 1: Using fdisk to re-create the partition.

~]# fdisk /dev/vda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p

Disk /dev/vda: 16.1 GB, 16106127360 bytes, 31457280 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: 0x000c3ae3

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 2099199 1048576 83 Linux
/dev/vda2 2099200 4196351 1048576 82 Linux swap / Solaris
/dev/vda3 4196352 20971519 8387584 83 Linux

Command (m for help): d
Partition number (1-3, default 3):
Partition 3 is deleted

Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p):
Using default response p
Partition number (3,4, default 3):
First sector (4196352-31457279, default 4196352):
Using default value 4196352
Last sector, +sectors or +size{K,M,G} (4196352-31457279, default 31457279):
Using default value 31457279
Partition 3 of type Linux and of size 13 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

~]# partprobe

b) Method 2: Using growpart to extend the partition.

~]# yum -y install cloud-utils-growpart
~]# growpart -v /dev/vda 3
~]# partprobe

What is growpart utility and how to use it ?

  1. Grow the XFS filesystem.
~]# xfs_growfs /
meta-data=/dev/vda3 isize=512 agcount=4, agsize=524224 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=2096896, 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 2096896 to 3407616

~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 909M 0 909M 0% /dev
tmpfs tmpfs 919M 0 919M 0% /dev/shm
tmpfs tmpfs 919M 8.5M 911M 1% /run
tmpfs tmpfs 919M 0 919M 0% /sys/fs/cgroup
/dev/vda3 xfs 13G 1.3G 12G 10% /
/dev/vda1 xfs 1014M 142M 873M 14% /boot
tmpfs tmpfs 184M 0 184M 0% /run/user/0