Recently, we faced an issue of EBS volume expansion while we were migrating from Windows instance to Linux Instance. We were trying to attach the volume to Linux Instance which is restored from snapshot holding NTFS file system with lots of data. There was also a need to increase volume size before attaching it to Linux instance.
Expansion of partition in the EBS volume generally required in two scenarios:
While volume is restored from snapshot which holds filesystem and data.
While expanding storage space of an existing volume.
There are two steps to achieve partition expansion in file systems. First, we need to recreate the partition table entry of the volume’s file system and then expand partition in remaining size.
Let's start with re-creating a partition table entry.
There are lots of tools available for manipulating partition table in Linux like parted, GPT fdisk, FIPS, KDE Partition Manager etc. We are going to use “parted” tool for partition recreation. Most of Linux distribution comes with parted tool bundled with them. For more information, refer this link parted.
Below are the steps to recreate the partition table of the volume file system:
Note: Before proceeding further, it is advisable to take a snapshot of your volume. There is a possibility that you might corrupt or lose your data in the following procedures. If you have latest snapshot, you can start over in case of data corruption.
Identify volume, which needs to be resized. Use lsblk to list all block devices.
Find a volume that needs to be resized.
Unmount volume if it is mounted. Use UMOUNT command with value of mountpoint from above step.
ubuntu@:~$ sudo umount mountpoint
Run parted utility on the volume that needs to be resized, not on the partition of that volume. Remember to add the /dev/ prefix to the name that lsblk outputs.
ubuntu@:~$ sudo parted block_device
Change unit to sectors. For More Information, see parted units.
(parted) unit s
List the detail of the partition entries of the volume.
Use print command to list all details of the partition table. For certain type of partition table you might get message to repair partition table. Answer “Ignore” to fixing existing partition table as we are going to create it later.
Note down details from output as it will be needed in next steps, the total size of the disk, the partition table type, the number of the partition, the start point of the partition, and flags. For gpt partition table, partition name and for msdos partition table, partition type and start point is needed to create new partition.
Delete partition entry that you want to extend.
(parted) rm partition_num
Create a new partition which is extended up to your expected size. Here we are going to extend it to the end of the volume.
(parted) mkpart partition_type partition_starting_point 100%
Verify partition table entry. Use print command to list partition details and verify updated detail with previous detail which noted in the step 5.
Check if flag is there or not. In some cases the flag may be lost. If a flag was dropped from the partition when it was expanded, add the flag with the following command, substituting your partition number and the flag name
(parted) set partition_num flag_name on
Once again run print command and verify changes.
Exit from parted.
Now, We have recreated partition table entry in the previous steps. It’s time to resize partition as per our need. As we have ntfs filesystem resize2fs or xfs_growfs will not work here.
We are going to use ntfsresize to extend NTFS file system. ntfsresize is a free unix utility that non-destructively resize the NTFS file system used with any windows OS on a hard-disk partition. No de-fragmentation is required prior to resizing. ntfsresize is included in the ntfsprogs package. For more Information, see ntfsresize.
Below are the steps to resize partition.
Resize partition, use ntfsresize command.
ntfsresize -s size partition_name
Here size is expected size in MB for the new partition.
eg. ntfsresize -s 11000M /dev/xvdf1
List block devices using lsblk and verify whether volume size is expanded.
Now you are done with volume expansion. Mount your volume and enjoy the expanded size of the volume.
For more implementation details or support you may contact us at email@example.com.
For more implementation details or support, you may contact us at firstname.lastname@example.org .