Unable to resize root filesystem on AWS RHEL EC2

In this blog, we would talk about root partition resizing issue in RHEL EC2 and it’s resolution.

Issue

Extending root partition results in couldn’t find valid file system. Having said that, when you add additional volume to your EBS root device [/dev/sda1] and then extend the filesystem using resize2fs, this issue occurs.

The issue would look like below, when you execute command in EC2 terminal

#resize2fs /dev/xvda
#resize2fs /dev/xvda1
#resize2fs /dev/xvda2 

resize2fs: Device or resource busy while trying to open /dev/xvda

resize2fs: Bad magic number in super-block while trying to open for both /dev/xvda1 & /dev/xvda2

Couldn’t find valid filesystem superblock

What you need to check?

As you know,In RHEL EC2 xvda is your root disk and you would be able to see different partitions on the disk such as xvda1 and xvda2.

1. First verify the number of partitions in your EC2 using below command

#lsblk
#ls -l /dev/xvd*

2. Identify the Filesystem [ext2,ext3,ext4 or XFS] of your Volume. Type below

#file -s /dev/nvme?n* [For Nitro-Based Instance]
#file -s /dev/xvd* [For T2 Instance] 

You most probably would see the below filesystem type for /dev/xvd*

Now if you would run resize2fs on XFS filesystem, this issue would occur

Note: resize2fs best works for ext2,ext3,ext4 filesystem. However, xfsprogs tool works for extending XFS filesystem.

What Next?

Now we would extend the 16 GB root volume partition [xvda2] to 50 GB for XFS filesystem

1. Install xfsprogs package for extending XFS filesystem

#yum install xfsprogs -y

2. If you have added the volume and the volume has a partition and the partition does not reflect the new volume size, then use growpart command. Execute below command on T2 partition

#growpart /dev/xvda 2

3. Type xfs_growfs command to extend the file system of root volume

#xfs_growfs -d /

4. Verify the disk space

#df -h
#lsblk

I hope this blog helps to understand the root partition extend issue and its resolution. Please comment below if you have any questions related to this blog

Leave a Reply

%d bloggers like this: