How to extend NTFS partition using Linux command line

This post will be dedicated to detailing how I managed to enlarge my NTFS partition on one of my hard disks, without losing any data! All from the Linux command line without using GParted, or any other live boot utility – namely using fdisk and ntfsresize. Note that the disk I’ll be expanding will not be my primary booting device. If you wish to expand your primary drive then you must use a live boot utility.

1. Backup

Don’t think it won’t happen to you, because it will. It has happened to be countless times and it can quite easily happen to you, despite your popular belief of being a pro. Real professionals backup.

2. Check the backup

Ensure all the data you’ve backed up is present and secure – just in case.

3. fdisk -l

This command lists all the hard disks and partitions on your system. Identify the device and NTFS partition that you want to expand. In my case, I want to expand the /dev/sdc1 partition on the /dev/sdc device.

Here’s a quick rundown of the fdisk -l output.

  1. Total capacity of the device in GB and bytes; as you can see mine is 2000.4GB, or 2000398934016 bytes to be exact.
  2. Total capacity of the device in sectors.
  3. Number of bytes per sector. The majority of filesystems configure disks to be 1 sector == 512 bytes, although this area would confirm otherwise.
    Therefore, multiplying the value in #2 by 512 would give us the long byte value in #1.
  4. Starting and ending sector positions for data in the /dev/sdc1 partition.
    Note the start is 2048, not 0 – the first 2047 sectors are reserved for the partition table and other disk related information.

By knowing the above information, we can conclude that the entire disk has 3907029168 sectors, but only (488376319 subtract 2048) 488374271 sectors are being used, which is 233GB (250047626752 bytes). This means I’m only using 12.5% of /dev/sdc‘s entire capacity, which is actually 2000GB (2000398934016 bytes).

We can calculate the absolute byte value of the available disk space on /dev/sdc by multiplying the disk’s total number of sectors by 512 and subtracting (2048 * 512). The equation looks like this:

(3907029168 * 512) – (2048*512) = 2000397885440
(total sectors * sector size) – (starting sector * sector size) = T

4. umount /dev/sdc

Unmounting the disk will allow you to make changes to the partition’s size safely. If you’re like me and have applications actively using this partition, preventing you from unmounting it due to processes currently hogging it, then remove the line in /etc/fstab and reboot.

5. Deleting the old small partition (not the data)

[user@hostname ~]# fdisk /dev/sdc

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): d
Selected partition 1

Command (m for help): p

Disk /dev/sdc: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x2dbb9f13

   Device Boot      Start         End      Blocks   Id  System

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

Calling ioctl() to re-read partition table.
Syncing disks.

6. Creating the new bigger partition

[user@hostname ~]# fdisk /dev/sdc

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-3907029168, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-3907029168, default 3907029168): 
Using default value 2097151

Command (m for help): p

Disk /dev/sdc: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x2dbb9f13

Device Boot          Start           End         Blocks   Id  System
/dev/sdc1            2048     3907029167     1953513560   83  Linux

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

Calling ioctl() to re-read partition table.

It is very important to note here that there are two significant changes made to your system, other than the obvious larger /dev/sdc1 partition.

You’ll notice that the file system ID and label has changed to “83” and “Linux”. This suggests your partition is a native Linux partition, however if you type the commands df -T and mount, you’ll see that the filesystem type is actually fuseblk, which reportedly is a handler for NTFS partitions in Linux operating systems. Rest assured, the filesystem is still NTFS and your data thus far still resides.

7. ntfsresize –no-action –size numberOfBytes /dev/sdc1

The above command is a dry run, so once you press enter no changes will be applied due to the –no-action option. Removing this option will allow the changes.

Replace numberOfBytes with the value of T calculated at the end of step #3.

If you are satisfied with the output of the dry run, then progress to the next step to remove the –no-action option.

8. ntfsresize –size numberOfBytes /dev/sdc1

Once the command is successfully executed, the device’s partition table is now altered and the partition itself is resized. Remount the device to start using the newly allocated space.

Useful websites

Output of fdisk explained further – http://www.vinidox.com/linux/disk/ouput-of-fdisk-explained/
Large number calculator – https://defuse.ca/big-number-calculator.htm
Byte calculator – http://www.matisse.net/bitcalc/

Leave a Reply

Your email address will not be published. Required fields are marked *