Consolidating NTFS free space
Posted by jpluimers on 2017/12/29
For shrinking VM disk images, it’s important to consolidate NTFS free space towards the end of the this.
I’ve tried many tools, starting with defrag C: /X
(which tries, but doesn’t give good results) and found out these steps give the best results:
- Perform an Ultradefrag full optimisation,
- Perform a MyDefrag
Consolidate free space
script on the drive.
If shrinking still fails then:
- Try the Ultradefrag at boot time
- Note you have to install the normal version, as you cannot enable boot time defragmentation from the portable version:
- [WayBack] UltraDefrag Handbook: Graphical Interface – 7.0.2
- Settings
- Boot time scan > Enable (F11)
- Enable or disable the boot time processing (disabled for portable editions).
- Boot time scan > Script (F12)
- Open the boot time script (disabled for portable editions).
- Settings
- [WayBack] UltraDefrag Handbook: Boot Time Defragmentation – 7.0.2
- [WayBack] UltraDefrag Handbook: Graphical Interface – 7.0.2
- Note you have to install the normal version, as you cannot enable boot time defragmentation from the portable version:
- Verify what kind of file(s) prevent shrinking: they show up in red after the MyDefrag session:
- Zoom in them (they can initially as small as 1 red pixel) by clicking on or near them, repeating the zoom long enough so you can hover over with the mouse and the lower part of the screen shows a filename like
where you cannot find much information about “$badclus:$bad:$data” but appear to be clusters marked as
bad
on NTFS level using something likechkdsk /B
. - If it was a bad sector like above, then try to resolve it with [WayBack]
ntfsfix
which ships with GParted live boot:- boot a [WayBack] GParted — Live CD/USB/PXE/HD drive,
- run GParted to see the drive path (for instance /dev/sda1)
- start a terminal
- run this command:
ntfsfix -b /dev/sda1
which will give output like this:Mounting volume... OK Processing of $MFT and $MFTMirr completed successfully. Checking the alternate boot sector... OK NTFS volume version is 3.1. Going to un-mark the bad clusters ($BadClus)... OK NTFS partition /dev/sda1 was processed successfully.
- boot back into Windows
- on an administrative command prompt run this for the affected drive letter:
chkdsk D: /B
(reboot if needed)
- Zoom in them (they can initially as small as 1 red pixel) by clicking on or near them, repeating the zoom long enough so you can hover over with the mouse and the lower part of the screen shows a filename like
- Shrink the drive using
diskmgmt.msc
If you still cannot shrink, then try [WayBack] http://ftp.raxco.com/pub/download/pd14.0/pd14.0_pro.exe PerfectDisk by Raxco free trial.
Note:
MyDefrag (formerly named JkDefrag) is not maintained any more but the 4.3.1 version in the WayBack machine still works very well as the underlying defragmentation APIs in Windows haven’t changed.
References:
- [WayBack] UltraDefrag – An Open Source Defragmenter
- [WayBack: MyDefrag v4.3.1]
- [WayBack] MyDefrag – Wikipedia
- [WayBack] Defragmenting Files (Windows)
- [WayBack] The Challenge of Defragmenting an NTFS Partition | Systems Management content from Windows IT Pro
- [WayBack] windows – How do you defragment the MFT on an NTFS disk? – Super User
- [WayBack] hard drive – defrag /x – consolidate free space not really working – Windows Server 2012 – Server Fault
For FAT32:
For GParted / ntfsfix:
- GParted ships with a [WayBack] truckload of file system support including NTFS support (and tools like
ntfsfix
)- I’ve put the [WayBack] GParted — Live CD/USB/PXE/HD on USB via
TuxBoot
as per instructions at [WayBack] GParted Live on USB - Tuxboot helps you to create a bootable Live USB drive for Clonezilla live, DRBL live, Gparted live and tux2live.
- The safest version of GParted to download is the i686 version: it works on all processor architectures. Download from [WayBack] GParted — Download.
- The graphical X environment around GParted often has problems with graphics cards, use the
safe
boot options that uses VGA mode. Not nice, but very effective - You can use GParted to do resizing as well, but if you have a bad sector, then it refuses to do so: [WayBack] [SOLVED]How do I reduce an NTFS system partition with Gparted-live? (Page 1) — Live Media — GParted forum:
- The volume in the Gparted window shows an exclamation mark in a yellow triangle, and info says:Unable to read the contents of this file system!
Because of this some operations may be unavailable.The cause might be a missing software package.
The following list of software packages is required for ntfs file system support: ntfsprogs / ntfs-3g. - This command from the terminal will show you if there are bad sectors:
sudo ntfsresize --info --force --no-progress-bar /path-to-your-ntfs-partition
- When that happens, us the
ntfsfix
above to try and fix it.
- The volume in the Gparted window shows an exclamation mark in a yellow triangle, and info says:Unable to read the contents of this file system!
- I’ve put the [WayBack] GParted — Live CD/USB/PXE/HD on USB via
- [WayBack] partitioning – Removing a bad sector from an NTFS partition. Badblocks gave me an output. now what? – Ask Ubuntu (thanks [WayBack] Mina Michael)
PerfectDisk via:
- [WayBack] ntfs – How do I move the physical location of $MFTMirr, to allow resizing the partition? – Server Fault
- [WayBack] windows – Resizing volume with DiskPart unsuccessful, while there’s enough free space – Server Fault
- WayBack: Tip: How to shrink a volume beyond half its size using DiskPart or Disk Manager regardless of Microsoft’s NTFS restrictions and $MFTMirr | Under My Hat
–jeroen
Leave a Reply