Expand NTFS Volume from EC2 Linux Instance

blog-banner

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:

  1. While volume is restored from snapshot which holds filesystem and data.
  2. 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.

  1. Identify volume, which needs to be resized. Use lsblk to list all block devices.
    ubuntu@:~$ lsblk 
    
    Find a volume that needs to be resized.

  2. Unmount volume if it is mounted. Use UMOUNT command with value of mountpoint from above step.
    ubuntu@:~$ sudo umount mountpoint
    

  3. 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
    

  4. Change unit to sectors. For More Information, see parted units.
    (parted) unit s
    

  5. 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.
    (parted) print
    

    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.

  6. Delete partition entry that you want to extend.
    (parted) rm partition_num
    

  7. 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%
    

  8. Verify partition table entry. Use print command to list partition details and verify updated detail with previous detail which noted in the step 5.
    (parted) print
    

  9. 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.

  10. Exit from parted.
    (parted) quit
    

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.

  1. 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
    

  2. List block devices using lsblk and verify whether volume size is expanded.
    lsblk
    

Now you are done with volume expansion. Mount your volume and enjoy the expanded size of the volume. 

 
Contact us

For Your Business Requirements

Text to Identify Refresh CAPTCHA
Background Image Close Button

2 - 4 October 2024

Hall: 10, Booth: #B8 Brussels, Belgium