I’ve resized plenty of EC2 disks in my time, but the most recent one was a little different. Most of the disks I resize are on Ubuntu or CentOS, but the most recent one was a Redhat disk. Call me crazy but it’s strangely different.
The disks layout looks like this (using the “lsblk” command):
# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT nvme0n1 259:0 0 50G 0 disk ├─nvme0n1p1 259:1 0 1M 0 part └─nvme0n1p2 259:2 0 50G 0 part /
And here’s the partition details (and type):
# fdisk /dev/nvme0n1 ... Device Boot Start End Blocks Id System /dev/nvme0n1p1 1 104857599 52428799+ ee GPT
The “ee / GPT” isn’t common in my experience. Having said that, most Linux servers I maintain are Ubuntu or CentOS.
Hang on: Where’s the second (the root) disk? The one you see above it not it. And notice the partition type. “ee GPT”. That’s the part that got me. I would normally be “83 Linux”.
At this point we’d go to the AWS console and resize/grow the disk (volume). Then return here and continue on.
Now we confirm the resize:
# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT nvme0n1 259:0 0 75G 0 disk ├─nvme0n1p1 259:1 0 1M 0 part └─nvme0n1p2 259:2 0 50G 0 part /
The above looks good. The disk is now 75G in size but the partition is still the original size (50G).
I decided not to use the normal method I’d use (delete and recreate the partition) because the partitions weren’t listing as I’d expect. So I went with the “growpart” method as documented here “https://aws.amazon.com/premiumsupport/knowledge-center/ebs-volume-size-increase/”. The following command lists a “2” next to the command. It specifies the partition to deal with. I know from the above output that the “/” partition is the second partition.
# growpart /dev/nvme0n1 2 CHANGED: partition=2 start=4096 old: size=104853470 end=104857566 new: size=157282270 end=157286366
Confirm the resized partition:
# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT nvme0n1 259:0 0 75G 0 disk ├─nvme0n1p1 259:1 0 1M 0 part └─nvme0n1p2 259:2 0 75G 0 part /
Confirm the filesystem type so we can use the right growth tool (xfs_grow or resize2fs) – Hint: it’s xfs:
# mount | grep ' / ' /dev/nvme0n1p2 on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
Grow the filesystem over the newly available space:
# xfs_growfs / meta-data=/dev/nvme0n1p2 isize=512 agcount=34, agsize=393216 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=13106683, 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 13106683 to 19660283
Check the disk space allocation details to confirm it was successful:
# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 10G 0 10G 0% /dev tmpfs 10G 4.0K 10G 1% /dev/shm tmpfs 10G 1.1G 8.9G 11% /run tmpfs 10G 0 10G 0% /sys/fs/cgroup /dev/nvme0n1p2 75G 41G 35G 54% / tmpfs 2.0G 64K 2.0G 1% /run/user/0 tmpfs 2.0G 48K 2.0G 1% /run/user/1003 tmpfs 2.0G 0 2.0G 0% /run/user/1001
And we’re done.