Product SiteDocumentation Site

5.2. Resizing an NTFS filesystem the command line

This section explains using tools provided by Fedora to resize an NTFS partition. A terminal window from a liveCD can be used.

Disable Windows fast reboot feature!

Newer versions of Windows use a strategy of suspending some system processes to disk to speed startup times. Modifying a filesystem in this state can corrupt or damage the data, so the linux NTFS drivers will not mount it. If the filesystem were to be mounted, the cached view if the files may differ from the changes you made in Fedora, with the most likely result of loosing your changes - or worse.
Before attempting any operation on an NTFS volume from Fedora, make sure you have disabled this feature in Windows.
Procedure 1.  Selecting and resizing a partition.
  1. Show available filesystems:
    # blkid
    /dev/sda1: SEC_TYPE="msdos" UUID="32AE-E651" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="0315942d-8c2c-414f-a560-cfa499494a72" 
    /dev/sda2: UUID="593153ae-2b67-4a5b-9efa-fa3954953abd" TYPE="ext4" PARTUUID="68cadad8-6de2-4ef7-96ff-f58e5114fdcc" 
    /dev/sda3: UUID="P2xKTQ-aQWG-z2Uv-jSw5-kkUK-SN5Q-cNf3PI" TYPE="LVM2_member" PARTUUID="7ba7ed40-b43f-4e71-b83e-51629bf7db47" 
    /dev/sda5: UUID="44B6BAD1B6BAC2AA" TYPE="ntfs" PARTUUID="9c62d1dc-dedd-4d4c-9728-5f2ef69f2b42" 
    
  2. ntfs partitions indicate the existing Windows installation. Examine the partitions on the /dev/sda drive.
    # parted /dev/sda print
    Model: ATA ST9320328CS (scsi)
    Disk /dev/sda: 320GB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    Disk Flags: pmbr_boot
    
    Number  Start   End    Size    File system  Name                          Flags
     1      1049kB  211MB  210MB   fat16        EFI System Partition          boot
     2      211MB   735MB  524MB   ext4
     3      735MB   119GB  118GB
     4      119GB   119GB  134MB                Microsoft reserved partition  msftres
     5      119GB   215GB  96.2GB  ntfs
    
  3. Partition number 5 is a large filesystem, and probably has some free space to share. Check how much of that space is in use.
    # ntfsresize --info /dev/sda5
    ntfsresize v2013.1.13 (libntfs-3g)
    Device name        : /dev/sda5
    NTFS volume version: 3.1
    Cluster size       : 4096 bytes
    Current volume size: 96234107392 bytes (96235 MB)
    Current device size: 96234110976 bytes (96235 MB)
    Checking filesystem consistency ...
    100.00 percent completed
    Accounting clusters ...
    Space in use       : 29222 MB (30.4%)
    Collecting resizing constraints ...
    You might resize at 29221265408 bytes or 29222 MB (freeing 67013 MB).
    Please make a test run using both the -n and -s options before real resizing!
    
  4. Resize the filesystem. Make sure to balance the available space, despite the suggestion from ntfsresize to shrink to the bare minimum. A very full filesystem can cause problems for any operating system.
    # ntfsresize --size 40G /dev/sda5
    ntfsresize v2013.1.13 (libntfs-3g)
    Device name        : /dev/sda5
    NTFS volume version: 3.1
    Cluster size       : 4096 bytes
    Current volume size: 96234107392 bytes (96235 MB)
    Current device size: 96234110976 bytes (96235 MB)
    New volume size    : 39999996416 bytes (40000 MB)
    Checking filesystem consistency ...
    100.00 percent completed
    Accounting clusters ...
    Space in use       : 29222 MB (30.4%)
    Collecting resizing constraints ...
    Needed relocations : 0 (0 MB)
    WARNING: Every sanity check passed and only the dangerous operations left.
    Make sure that important data has been backed up! Power outage or computer
    crash may result major data loss!
    Are you sure you want to proceed (y/[n])? y
    Schedule chkdsk for NTFS consistency check at Windows boot time ...
    Resetting $LogFile ... (this might take a while)
    Updating $BadClust file ...
    Updating $Bitmap file ...
    Updating Boot record ...
    Syncing device ...
    Successfully resized NTFS on device '/dev/sda5'.
    You can go on to shrink the device for example with Linux fdisk.
    IMPORTANT: When recreating the partition, make sure that you
      1)  create it at the same disk sector (use sector as the unit!)
      2)  create it with the same partition type (usually 7, HPFS/NTFS)
      3)  do not make it smaller than the new NTFS filesystem size
      4)  set the bootable flag for the partition if it existed before
    Otherwise you won't be able to access NTFS or can't boot from the disk!
    If you make a mistake and don't have a partition table backup then you
    can recover the partition table by TestDisk or Parted's rescue mode.        
    
Procedure 2. Resizing the partition
  1. To make sure that the partition is recreated accurately, work using sectors as units instead of bytes. The first figure we need is the sector the filesystem starts on.
    # parted /dev/sda unit s print
    Model: ATA ST9320328CS (scsi)
    Disk /dev/sda: 625142448s
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    Disk Flags: pmbr_boot
    
    Number  Start       End         Size        File system  Name                          Flags
     1      2048s       411647s     409600s     fat16        EFI System Partition          boot
     2      411648s     1435647s    1024000s    ext4
     3      1435648s    232122367s  230686720s
     4      232122368s  232384511s  262144s                  Microsoft reserved partition  msftres
     5      232384512s  420341759s  187957248s  ntfs
     6      420341760s  420343807s  2048s                                                  bios_grub
     7      420343808s  421367807s  1024000s    ext4
     8      421367808s  625141759s  203773952s
    
    The partition starts on sector 232384512, and the sector size is 512 bytes
  2. Calculate the size of the filesystem in sectors, and the end of the new partition
    • After resizing, the filesystem is marked as dirty so it will be checked on the next Windows boot. Clear this flag so that we can run further commands.
      #ntfsfix -d /dev/sda5
      Mounting volume... OK
      Processing of $MFT and $MFTMirr completed successfully.
      Checking the alternate boot sector... OK
      NTFS volume version is 3.1.
      NTFS partition /dev/sda5 was processed successfully.   
      
    • Find the cluster size and number of clusters.
      # ntfsinfo -m /dev/sda5|grep Cluster
          Cluster Size: 4096
          Volume Size in Clusters: 9765624
          Compression Block Clusters: 0
          Free Clusters: 2631945 (27.0%)
      
    • Calculate the size in sectors of the new filesystem.
      Equation 1. Filesystem size in sectors
      4096 bytes per cluster × 9765624 total clusters ÷ 512 bytes per sector = 78124992 sectors

    • Find the end of the new partition.
      Equation 2. End sector of new partition
      232384512 start + 78124992 filesystem = 310509504 end sector

      Adding onto the end sector value costs little free space and provides a margin of error. Consider padding the end of your partition for best results.
  3. Use parted to resize the ntfs filesystem on /dev/sda. Using the s after the number ensures parted uses sectors as the unit.
    # parted /dev/sda
    GNU Parted 3.1
    Using /dev/sda
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    (parted)
    (parted) rm 5
    (parted) mkpart
    Partition name?  []? windowsdisk
    File system type?  [ext2]? ntfs                                           
    Start? 232384512s                                                         
    End? 310509504s      
    (parted) quit
    
  4. Check the partition table to confirm the free space is available, and exit parted.
    (parted) print free                                                       
    Model: ATA ST9320328CS (scsi)
    Disk /dev/sda: 320GB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    Disk Flags: pmbr_boot
    
    Number  Start   End     Size    File system  Name                          Flags
            17.4kB  1049kB  1031kB  Free Space
     1      1049kB  211MB   210MB   fat16        EFI System Partition          boot
     2      211MB   735MB   524MB   ext4
     3      735MB   119GB   118GB
     4      119GB   119GB   134MB                Microsoft reserved partition  msftres
     5      119GB   159GB   40.0GB  ntfs
            159GB   215GB   56.2GB  Free Space
     
            (parted) quit