Skip to content

Instantly share code, notes, and snippets.

@tonylambiris
Last active January 14, 2018 04:18
Show Gist options
  • Select an option

  • Save tonylambiris/2c4f12e298f1182d9e65220ebfd6fafd to your computer and use it in GitHub Desktop.

Select an option

Save tonylambiris/2c4f12e298f1182d9e65220ebfd6fafd to your computer and use it in GitHub Desktop.
gdisk output for resizing an ntfs partition

Basic steps:

  • Find out recommended minimum size for Windows partition
  • Resize Windows partition to 1.5x the recommended minimum
  • Recreate Windows partition in gdisk
  • Finalize Windows partition resizing

IMPORTANT: In this example I allocate an additional megabyte when recreating the Windows partition in gdisk (search for +50146M)

root@archiso ~ # ntfsresize -m /dev/sda3
ntfsresize v2017.3.23 (libntfs-3g)
Minsize (in MB): 33430

root@archiso ~ # echo $(( (( 33430 / 2 )) + 33430 ))
50145

root@archiso ~ # ntfsresize --size 50145M /dev/sda3
ntfsresize v2017.3.23 (libntfs-3g)
Device name        : /dev/sda3
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 50209997312 bytes (50210 MB)
Current device size: 254857445376 bytes (254858 MB)
New volume size    : 50144997888 bytes (50145 MB)
Checking filesystem consistency ...
100.00 percent completed
Accounting clusters ...
Space in use       : 33430 MB (66.6%)
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/sda3'.
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.

root@archiso ~ # gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.3

The protective MBR's 0xEE partition is oversized! Auto-repairing.

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): p
Disk /dev/sda: 500118192 sectors, 238.5 GiB
Model: HFS256G39TND-N21
Sector size (logical/physical): 512/4096 bytes
Disk identifier (GUID): 49E90B31-8741-4CCB-B166-60890BE2B0A5
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 500118158
Partitions will be aligned on 2048-sector boundaries
Total free space is 14957 sectors (7.3 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          206847   100.0 MiB   EF00  EFI system partition
   2          206848          239615   16.0 MiB    0C01  Microsoft reserved ...
   3          239616       498008063   237.4 GiB   0700  Basic data partition
   4       498008064       500105215   1024.0 MiB  2700  Basic data partition

Command (? for help): d
Partition number (1-4): 3

Command (? for help): n
Partition number (3-128, default 3): 
First sector (34-500118158, default = 239616) or {+-}size{KMGTP}: 
Last sector (239616-498008063, default = 498008063) or {+-}size{KMGTP}: +50146M
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 0700
Changed type of partition to 'Microsoft basic data'

Command (? for help): n
Partition number (5-128, default 5): 
First sector (34-500118158, default = 102938624) or {+-}size{KMGTP}: 
Last sector (102938624-498008063, default = 498008063) or {+-}size{KMGTP}: 
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 8e00
Changed type of partition to 'Linux LVM'

Command (? for help): p
Disk /dev/sda: 500118192 sectors, 238.5 GiB
Model: HFS256G39TND-N21
Sector size (logical/physical): 512/4096 bytes
Disk identifier (GUID): 49E90B31-8741-4CCB-B166-60890BE2B0A5
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 500118158
Partitions will be aligned on 2048-sector boundaries
Total free space is 14957 sectors (7.3 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          206847   100.0 MiB   EF00  EFI system partition
   2          206848          239615   16.0 MiB    0C01  Microsoft reserved ...
   3          239616       102938623   49.0 GiB    0700  Microsoft basic data
   4       498008064       500105215   1024.0 MiB  2700  Basic data partition
   5       102938624       498008063   188.4 GiB   8E00  Linux LVM

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sda.
The operation has completed successfully.

root@archiso ~ # ntfsresize -v /dev/sda3 -f
ntfsresize v2017.3.23 (libntfs-3g)
Device name        : /dev/sda3
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 50144997888 bytes (50145 MB)
Current device size: 52581892096 bytes (52582 MB)
New volume size    : 52581888512 bytes (52582 MB)
Checking for bad sectors ...
Checking filesystem consistency ...
100.00 percent completed
Accounting clusters ...
Space in use       : 33430 MB (66.7%)
Collecting resizing constraints ...
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/sda3'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment