JkDefrag v3.27

Free (released under the GNU General Public License) disk defragment and optimize utility for Windows 2000/2003/XP/Vista/X64. Completely automatic and very easy to use, fast, low overhead, with several optimization strategies, and can handle floppies and USB disks/sticks. Included are a Windows version, a commandline version (for scheduling by the task scheduler or for use from administrator scripts), a screensaver version, a DLL library (for use from programming languages), and versions for Windows X64.

 *  Download JkDefrag v3.27 (405kb) for Windows 2000/2003/XP/Vista
 *  Download JkDefrag64 v3.27 (395kb) for Windows X64


Free GNU software
Tip: For translated versions see the "Contributed by other people" chapter.

If you are a programmer you might be interested in the sources. Included is a DLL library (released under the GNU Lesser General Public License) containing all the defragger subroutines, which you can call from just about any programming language (for example Delphi and Visual Basic).

 *  Download JkDefrag v3.27 sources (324kb) for Microsoft Visual C++ 2005

JkDefrag Forum


I have set up a forum for JkDefrag, a place where you can ask questions, give feedback about features you would like, share your experiences, share code that uses the defragger library, and other things about JkDefrag.

 *  Jump to JkDefrag forum

Install


There is no "setup" or "install" and no configuration file. All you have to do is download the zip and unpack. It contains the following 3 programs:

JkDefrag.exe
Windows version. This is what most people will use. No installation or configuration necessary, it's ready to run and will automatically process all the mounted, writable, fixed volumes on your computer
JkDefragCmd.exe
Commandline version. Specially designed to be run automatically in the background, or from administrator scripts. See the "running" chapter below for a list of commandline options, and the "Frequently Asked Questions" on how to run it automatically with the Windows Scheduler.
JkDefragScreenSaver.scr + JkDefragScreenSaver.exe
Screen saver version. Move (or copy) these two files to the "system32" folder on your harddisk (usually "c:\Windows\System32\" or "c:\Winnt\System32\"). It will automatically become visible in the list of screensavers as "JkDefrag screensaver" and can be used just like any other screensaver (right-click somewhere on your desktop and select Properties/Personalize, then select the Screen Saver tab).
Note: on Vista the screensaver only works with User Account Control turned off (see Control Panel, User Accounts, Turn User Account Control on or off).
Note: screensavers do not lengthen the lifespan of CRT and LCD monitors, contrary to popular belief. It is better to let the monitor be turned off by the Windows energy saving settings.
The Windows version of JkDefrag shows a high-detail map of the harddisk, refreshed 3 times per second. Bottom-left of the window is the beginning of the harddisk. The colors used are:
  • Black: empty
  • Green: regular files, unfragmented
  • Dark green: spacehogs, unfragmented
  • Yellow: fragmented
  • Red: unmovable
  • White: busy
  • Pink: MFT reserved zone (NTFS only)
  • Grey: in use by unknown data

Snapshot of JkDefrag in action. The program is completely automatic,
there are no buttons and no pull-down menu's.

Running


JkDefrag is completely automatic.
The commandline options are not needed for normal use.

Default behavior of JkDefrag is to automatically process all the mounted, writable, fixed volumes on your computer. You can change this behaviour with the following commandline options:

For example:     JkDefrag.exe -a 7 -d 2 -q c: d:
 
-a N     Select an action to perform. The number N is a value from 1 to 11, default is 3:
1 = Analyze, do not defragment and do not optimize.
2 = Analyze and defragment, do not optimize.
3 = Analyze, defragment, and fast optimization (default).
5 = Analyze and force together.
6 = Analyze and move to end of disk.
7 = Analyze and sort files by name (folder + filename).
8 = Analyze and sort files by size (smallest first).
9 = Analyze and sort files by last access (newest first).
10 = Analyze and sort files by last change (oldest first).
11 = Analyze and sort files by creation time (oldest first).
-e "mask"     Exclude files and/or directories that match the mask. The items will not be defragged and will not be moved. Use wildcards '*' and '?' in the mask to match a set of files or directories. If the mask contains a space then it must be enclosed in double-quotes. Some examples:
JkDefrag -e *.avi -e *.zip -e *.log
JkDefrag -e D:\MySQL\Data\*
-u "mask"     Files that match a mask will be moved to the SpaceHogs area. The program has a build-in list for all files bigger than 50 megabytes, files not accessed in the last month, archives, files in the recycler bin, service pack files, and some others. Disable this list by specifying the special mask "DisableDefaults". Use wildcards '*' and '?' in the mask to match a set of files or directories. If the mask contains a space then it must be enclosed in double-quotes. Some examples:
JkDefrag -u *.avi -u *.zip -u *.log
JkDefrag -u D:\MySQL\Data\*
-s N     Slow down to N percent (1...100) of normal speed. Default is 100.
-f N     Set the size of the free spaces to N percent (0...100) of the size of the volume. The free spaces are room on disk for temporary files. There are 2 free spaces, between the 3 zones (directories, regular files, space hogs). Default is 1% (per free space).
-d N     Select a debug level, controlling the messages that will be written to the logfile. The number N is a value from 0 to 6, default is 1:
0 = Fatal errors.
1 = Warning messages [default].
2 = General progress messages.
3 = Detailed progress messages.
4 = Detailed file information.
5 = Detailed gap-filling messages.
6 = Detailed gap-finding messages.
-l "filename"     Specify a filename for the logfile. Default is "JkDefrag.log" and "JkDefragCmd.log". Specify empty string "" (two double-quotes) to disable the logfile.
-h     [commandline version only] Show a short help text.
-help     [commandline version only] Show a short help text.
--help     [commandline version only] Show a short help text.
/?     [commandline version only] Show a short help text.
-q     [windows version only] Quit the program when it has finished.
items     The items to be defragmented and optimized, such as a file, directory, disk, mountpoint, or volume, including removable media such as floppies, USB disks, memory sticks, and other volumes that behave like a harddisk. Wildcards '*' and '?' are allowed to select a set of files. If the item contains a space then it must be enclosed in double-quotes. Some examples:
JkDefrag C: D:
JkDefrag f:\*.log D:\MySQL\Data\*

Permissions
JkDefrag needs "full control" permissions to all files and disks that it must defragment/optimize. On a default Windows system the "administrator" userid has full permissions to all files and disks. Users can also run JkDefrag, but then it can only defragment/optimize the files and disks for which the user has "full control". On Windows Vista: right-click the JkDefrag program and select "run as administrator".
Stopping
All versions of JkDefrag can be stopped safely at any time, there is no risk of losing data or corrupting your disk. You can use all the usual ways to stop a Windows program, such as pressing ALT-F4, clicking the 'x' in the top-right corner, via the pull-down menu in the taskbar, or by killing the program via the task manager or another utility. The commandline program can be stopped the same way, plus by pressing CTRL-C, or BREAK. It may take a bit of time for the program to actually stop, JkDefrag will finish the current file in the background.
Fast optimization
This optimization strategy is designed for every day use. It moves a minimum of data on the harddisk and finishes very quickly, but will not fill all the gaps on the disk. The strategy scans for gaps on the disk and fills them with files from above.
Sorted optimization
All the sorting optimizations WILL CREATE FRAGMENTS. This is by design, it is not a bug. For more info see the Frequently Asked Questions.
These sorting optimizations are for incidental use once in a while. They take a lot of running time and data movement because they rewrite all the data on the disk. The strategies vacate a small area on disk and then fill it up again with the files in the selected order.
  • Sort by name: very good for fast program starting. The files used by a particular program will be very close together on disk.
  • Sort by size: placing all the small files together at the begin of the disk will dramatically reduce the average file seek time.
  • Sort by last access: files that have not been accessed in a while are probably unimportant and are best sorted to the back.
  • Sort by last change: placing files together that change a lot (for example databases and logfiles) will speed up regular operation of the system.
  • Sort by creation time: The oldest files on the disk are likely to be important system files, for example used when Windows is booting.
Note: If you want to sort by last access time then first make sure your virus scanner (and other programs that scan all files on disk) do not change that time.
Force together
Intended for partition resizing. All movable files are moved to the beginning of the disk, even if it means fragmenting them to fill gaps that cannot be filled otherwise.
Move to end of disk
Move all the files to the end of the disk, making more room at the beginning of the disk. Intended for big and rarely used files such as logfiles, backup archives, installation files, and such.
Logfile
JkDefrag writes all messages to a logfile called "JkDefrag.log", or "JkDefragCmd.log", or "JkDefragScreenSaver.log", depending on which version you are using. You can inspect the logfile if you want, it's a flat-text file. The logfile is automatically cleared when the program starts, it does not grow to infinity.
Tip: you can use environment variables in the name of the logfile, for example "-l %COMPUTERNAME%.log".

Tip: Cleanup old junk from your harddisk before running JkDefrag, for example with "Start -> Programs -> Accessories -> System Tools -> Disk Cleanup", or with something like the freeware  *  CCleaner program.

Tip: Reboot before running JkDefrag. This will release files that are in use, so they can be defragged.

Tip: Stop your realtime virus scanner before running JkDefrag. Virus scanners check all disk activity, making defragmentation and optimization very slow.

Tip: Move the swapfile to another volume, reboot, defragment, and move the swapfile back. If you don't have a second volume then temporarily make the swapfile small, for example 100Mb.

Tip: If an application (for example a database) prevents certain files from being defragged then stop the application, run JkDefrag for the particular data directory only, and restart the application.

Frequently asked questions


What is "disk fragmentation"?
Imagine a book split into several parts, some pages are over here, other pages in another room on another floor altogether. You will have to walk a lot when you need the book. It may sound silly, but this is exactly what happens to files on your harddisk. Defragmentation will put all the parts (fragments) back together, making your computer a lot faster.

What is "disk optimization"?
Imagine a big library with lot's of books, spread out all over the building and not sorted whatsoever. There is an index telling you exactly where every book is, but you will have to walk a lot when you need several books. This is exactly what happens on your harddisk, the files that belong to an application can be all over the place, anywhere on the harddisk. Optimization will bring all the files together in one place, leaving the rest of the harddisk empty, and will sort the files, for example alphabetically.

How safe is it?
JkDefrag is based on the standard defragmentation API by Microsoft, a system library that is included in Windows 2000, 2003, XP, and Vista. Most defragmenters are based on this API, including commercial defragmenters. JkDefrag is therefore very solid and there is no risk of losing data. You can stop the program at any time, it will finish the current file in the background. If your disks use NTFS then you're even safe when the computer crashes in the middle of defragging. Nevertheless, it's still a good idea to backup before defragmenting, just like with other defragmenters, because the heavy use of the harddisk may trigger a hardware fault (disk crash), and/or overheating (disk, power supply, controller chipset, etc.).

Defragmentation and optimizing will not only make a harddisk faster, but also lengthen it's lifespan. The disk will have less work to do and therefore have less wear and tear. Secondly, the sorting optimization strategies (see the "-a" option) will refresh all the magnetic data on your harddisk. However, defragmenting and optimizing is work, so excessive defragmenting and optimizing can actually cause more wear and tear than it prevents. JkDefrag is therefore set for "fast" optimization by default, intended to be used on a daily basis. The other optimizations should only be used occasionally.

How do I specify an option, or select a single disk (or folder or file)?
Take a look at the GUI wrappers, see the "Contributed by other people" chapter. Personally I find the commandline the easiest way to specify options. Another way is to create a shortcut to "JkDefrag.exe", open the properties of the shortcut, and add the desired commandline options (for example "-a 7") or the name(s) of the disk/folder/file (for example "C:") to the end of the "target" line. For example:
"C:\JkDefrag\JkDefrag.exe" -a 7
"C:\JkDefrag\JkDefrag.exe" D:
Tip: In the same properties window you can select "minimized".
Tip: See the "-q" option to exit automatically when finished.

Where is the Stop button?
All versions of JkDefrag can be stopped safely at any time, there is no risk of losing data or corrupting your disk. You can use all the usual ways to stop a Windows program, such as pressing ALT-F4, clicking the 'x' in the top-right corner, via the pull-down menu in the taskbar, or by killing the program via the task manager or another utility. The commandline program can be stopped the same way, plus by pressing CTRL-C, or BREAK. It may take a bit of time for the program to actually stop, JkDefrag will finish the current file in the background.

What is the best defragmentation/optimization strategy for me?
My advise for all computers is to run JkDefrag once with the "-a 7" optimization (sort by name), and from then on automatically every day with the default "-a 3" fast-optimize option.
Note: The "-a 9" optimization (sort by last access time) only works as expected if you do not use programs that scan all files on disk (such as virus scanners and backup programs), causing Windows to update all the last access times.

How can I run JkDefrag automatically every day?
It's a great idea to run JkDefrag automatically every day by adding it to the Windows scheduler, like this:
  • Start -> Control Panel -> Scheduled Tasks -> Add Scheduled Task
  • The wizard starts, click 'Next'.
  • Use the 'browse' button to select the 'JkDefragCmd.exe' program.
  • Select 'daily', next, select a time, next.
  • Enter a userid/password with administrator privileges, click 'Finish'.
Note: The commandline version of JkDefrag ("jkdefragcmd.exe") will exit automatically when finished. See the "-q" option to do the same for the Windows version.
Tip: See the "Settings" of the scheduled task to run only when the computer is idle.
Tip: To start the task minimized, in the settings of the task change the commandline into "start /min JkDefragCmd.exe".
Tip: Use the windows version of JkDefrag ("jkdefrag.exe") to prevent Windows from switching to power-saving while JkDefrag is running.

How do I use the screensaver?
See the instructions in the "Install" chapter.

How to run JkDefrag at boot-time?
It's very easy to run JkDefrag automatically in the background when the computer starts via the Windows Task Scheduler:
  • Start -> Control Panel -> Scheduled Tasks -> Add Scheduled Task
  • The wizard starts, click 'Next'.
  • Use the 'browse' button to select the 'JkDefragCmd.exe' program.
  • Select 'When my computer starts', click next.
  • Enter a userid/password with administrator privileges, click 'Finish'.
Note: This will not defrag system files such as the pagefile. To do that see the "see also" chapter for a link to Pagedefrag, a free utility by Microsoft Technet (formerly SysInternals).

How to start minimized, or maximized?
Make a shortcut to the "JkDefrag.exe" program, open the properties of the shortcut, find the "run" setting, and select "minimized" or "maximized". To run the commandline-version in a minimized window use "start /min jkdefragcmd.exe".

How much minimum free disk space does JkDefrag require?
JkDefrag does not require a minimum free disk space, unlike many other defraggers. But:
  • Windows reserves some space for expansion of the MFT, default is 12.5% of the volume size. This space is counted by Windows as free space because it can/will be used for regular files when the rest of the volume is full. But JkDefrag cannot use this free space.
  • A file can only be defragmented if there is a gap on disk big enough to hold the entire file. There may be plenty of free space, but what is needed is a single big gap. In these cases JkDefrag will try to reduce the number of fragments in the file by using the biggest gaps available.

Why is my disk not perfectly optimized?
  • There are many files that cannot be moved while Windows is running, because they are in use by an application, or by a service, or by Windows itself. See the "-d" commandline options and the logfile for more information. They can be anywhere on disk and are usually fragmented into microscopically small segments. In other words, the harddisk is not a big block of space where files can be moved at will, but thousands of little blocks bounded by unmovable data.
    A typical harddisk can easily contain tens of thousands of files, all with different sizes. What is the optimum way to organize the files into the blocks? The number of permutations is astronomical, it boggles the mind. JkDefrag doesn't even try to calculate them all. It concerns itself with only one block at a time, trying to fit only files from above the block, and limits itself to 0.5 seconds of calculating time.
    So it's very unlikely, if not impossible, for JkDefrag to perfectly optimize your disk, more's the pity.
  • Gaps are only filled with files from above the gap (fast optimization). If there are no files that fit the gap (all files are bigger) then the gap cannot be filled.
  • Files can only be fully defragged if there is a gap large enough to hold the entire file. If no such gap is available then JkDefrag will try to reduce the number of fragments by moving the file to the largest gaps available.
  • JkDefrag maintains a "free space" area between the directories and the regular files, and between the regular files and the space hogs. This is by design. See the "-f" commandline option to control the size of these free spaces.

Why do the sorting optimizations create fragments?
The sorting optimizations will move all the data to the beginning of the harddisk. But there may be some unmovable files in the way. Instead of leaving gaps (if a file doesn't fit between the last file and the unmovable file), the program will "wrap around" the unmovable files by splitting regular files into fragments. This may seem strange for a defragmenter, but the fragments are aligned and therefore have a very small impact on performance. Gaps however would make all the files above the gaps slower, because they would then be placed at a slightly slower part of the harddisk than they need to be. The fragments look terrible on the screen and in the statistics, but are there to make your harddisk faster!

What speed can I expect?
It is impossible to predict how long a defrag/optimize will take. It depends on things such as the optimization you have chosen, the speed of your harddisk, how big the files are, how much data is on the disk, and more. Assuming a harddisk speed of 40 megabyte per second, then reading 100 gigabyte of data will take 100000 / 40 = 2500 seconds (42 minutes). But JkDefrag has to do a lot more than just read the data, it also has to write the data, and update the MFT/FAT. And it may have to move data out of the way before it can place an item were it want's it to be. JkDefrag will do things as efficiently as possible, with as little data movement as possible, but it will take a long time nonetheless. If you are concerned about speed then use the default "-a 3" (fast optimize) setting. It will produce very good results in a minimum amount of time, especially if you use it every day.

What are SpaceHogs?
SpaceHogs are less important files that take up a lot of space. JkDefrag moves them behind the directories and the regular files, to make those faster. The internal list of SpaceHogs is (you can add more with the "-u" commandline option):
  • Files bigger than 50 megabytes
  • Files not accessed in the last month
  • ?:\Program Files\Installshield Installation Information\*
  • ?:\Archivos de programa\Installshield Installation Information\*
  • ?:\Arquivos de programas\Installshield Installation Information\*
  • ?:\Ohjelmatiedostot\Installshield Installation Information\*
  • ?:\Program\Installshield Installation Information\*
  • ?:\Programas\Installshield Installation Information\*
  • ?:\ProgramFiler\Installshield Installation Information\*
  • ?:\Programme\Installshield Installation Information\*
  • ?:\Programmer\Installshield Installation Information\*
  • ?:\Programmes\Installshield Installation Information\*
  • ?:\Programmi\Installshield Installation Information\*
  • ?:\RECYCLER\*
  • ?:\RECYCLED\*
  • ?:\$RECYCLE.BIN\*
  • ?:\System Volume Information\*
  • ?:\WINDOWS\$*
  • ?:\WINDOWS\I386\*
  • ?:\WINDOWS\ie7updates\*
  • ?:\WINDOWS\Installer\*
  • ?:\WINDOWS\ServicePackFiles\*
  • ?:\WINDOWS\SoftwareDistribution\*
  • ?:\WINDOWS\Downloaded Installations\*
  • ?:\WINDOWS\Ehome\*
  • ?:\WINDOWS\Fonts\*
  • ?:\WINDOWS\Help\*
  • ?:\WINDOWS\IME\*
  • ?:\WINDOWS\Speech\*
  • ?:\WINDOWS\Symbols\*
  • ?:\WINDOWS\system32\dllcache\*
  • ?:\WINNT\$*
  • ?:\WINNT\I386\*
  • ?:\WINNT\ie7updates\*
  • ?:\WINNT\Installer\*
  • ?:\WINNT\ServicePackFiles\*
  • ?:\WINNT\SoftwareDistribution\*
  • ?:\WINNT\Downloaded Installations\*
  • ?:\I386\*
  • *.7z
  • *.arj
  • *.avi
  • *.bak
  • *.bup
  • *.bz2
  • *.cab
  • *.chm
  • *.gz
  • *.ifo
  • *.log
  • *.lzh
  • *.mp3
  • *.msi
  • *.old
  • *.pdf
  • *.rar
  • *.rpm
  • *.tar
  • *.vob
  • *.z
  • *.zip
Note: Some virus scanners and other programs that scan all files on disk, will change the last access time of all items on every run, effectively disabling that particular SpaceHogs criterium. The other criteria still apply, though.

Can I run JkDefrag outside Windows?
JkDefrag is based on the Windows defragmentation library, so Windows must be started. JkDefrag can be run from a bootable Windows CD-rom (such as  *  Bart's Preinstalled Environment (BartPE) or  *  Ultimate Boot CD for Windows ), but cannot be run from a DOS bootable floppy or from Linux.

Can JkDefrag do continuous background defragging?
In my opinion continuous background defragging and optimization is marketing hype and a bad idea. There is considerable overhead (CPU, memory, disk) that may actually make your computer slower instead of faster, and it will wear out and shorten the lifespan of your harddisk. I advise defragging once a day (via the Windows Task Scheduler) at the most.

Can I "hide" the program from users?
See the "How to start minimized, or maximized?" question. Running completely invisible is a bit more difficult. Create a special userid (for example "jkdefrag") with administrator permissions, then add a schedule to the Windows Task Scheduler (see above) and specify that userid when asked for. The task will then run on that userid and not show anything on the user's screen. But I advise against it, I think it will needlessly worry the user when he sees a lot of mysterious disk activity.

Why is JkDefrag so slow in Windows "safe" mode?
The Windows disk cache is off in "safe" mode.

How do I disable Vista's build-in defragger?
  1. Start -> All Programs -> Accessories -> System Tools -> Disk Defragmenter
  2. Click or unclick "Run on a schedule (recommended)" depending if you want this feature enabled or disabled.
  3. Click OK

How do I defragment "c:\pagefile.sys"?
One way is to download and install the free  *  Pagedefrag utility by Microsoft TechNet (formerly Sysinternals), it will automatically defragment the pagefile and some other system files when the system is booting. But even better is to set the pagefile to a fixed size, so it will never get fragmented again. Here are instructions:
  1. Windows Vista: Open the "Control Panel", classic view. Double click "system". Select "Advanced system settings". Click the Performance "Settings" button. Select the "Advanced" tab. Click the Virtual Memory "Change" button.
    Windows 2000: Open the "Control Panel". Double click "system". Select the "advanced" tab. Click the "Performance Settings" button. Click the Virtual Memory "Change" button.
  2. Write down the "Currently Allocated" number.
  3. Windows Vista: Select "no paging file" for all disks.
    Windows 2000: Set the Initial Size and the Maximum Size numbers for all disks to zero.
  4. Reboot.
  5. Run JkDefrag.
  6. Go back to the same panel and setup a pagefile with a "custom size" where both the Initial Size and the Maximum Size are the number you wrote down.
  7. Reboot again. The pagefile should now be a single big unfragmented file that will never get fragmented again.

How do I defragment "C:\hiberfil.sys"?
This huge file is used by the hibernation facility and cannot be defragged on a running system. You can only delete the file, like this:
Windows Vista:
  1. Click Start -> All Programs -> Accessories, right click on "Command Prompt", and then click "Run as Administrator". If User Account Control (UAC) asks you for permission, permit the Command Prompt to run.
  2. Enter "powercfg -h off" (without the quotes).
  3. Reboot. The "hiberfil.sys" file will be automatically deleted.
  4. Repeat point 1
  5. Enter "powercfg -h on" (without the quotes).
  6. Reboot.
Windows XP:
  1. Open the Control Panel
  2. Double-click Power Options
  3. Click the Hibernate tab, de-select the 'Enable hibernate support' check box, and then click Apply.
  4. Reboot. The "hiberfil.sys" file will be automatically deleted.
  5. Go to the Windows Help & Support Center and search for 'enable hibernation'. It should be the first result. The instructions detail some other steps you may need to follow to reactivate the hibernation.

How do I defragment "C:\System Volume Information\...."?
These huge files are used by the System Restore facility and cannot be defragged on a running system. You can cleanup old system restore data with "Start -> Programs -> Accessories -> System Tools -> Disk Cleanup", the "More Options" tab. Or you can turn off System Restore altogether like this:
Windows Vista:
  1. In Control Panel, click "System".
  2. Select "System Protection".
  3. If a disk has a checkmark then remove the checkmark.
Windows XP:
  1. Open the properties of "My Computer".
  2. Select the "System Restore" tab. If you do not see the System Restore tab then you are not logged on to Windows as an Administrator.
  3. Check "Turn off System Restore" or "Turn off System Restore on all drives".

How do I defragment "C:\$Extend\$UsnJrnl:$J:$DATA"?
This huge file is used by Windows to track changes in other files. You can delete it with the following command (Windows will automatically create it again when needed):
fsutil usn deletejournal /d c:

Why use this defragger instead of the standard Windows defragger?
  • Much faster.
  • Totally automatic, extremely easy to use.
  • Optimized for daily use.
  • Data optimization, several strategies.
  • Directories are moved to the beginning of the disk.
  • Reclaims MFT reserved space after disk-full.
  • Maintains free spaces for temporary files.
  • Can defrag very full harddisks.
  • Can defrag very large files.
  • Can defrag individual directories and files.
  • Can be run automatically with the Windows Scheduler.
  • Can be used from the commandline.
  • Can be used as a screen saver.
  • Sources available, can be customized.

Why use this defragger instead of a commercial or shareware defragger?
  • It's free.
  • Totally automatic, extremely easy to use.
  • Optimized for daily use.
  • Several optimization strategies.
  • Directories are moved to the beginning of the disk.
  • Reclaims MFT reserved space after disk-full.
  • Maintains free spaces for temporary files.
  • Can defrag individual directories and files.
  • Can be used from the commandline.
  • Can be used as a screen saver.
  • Sources available, guaranteed to be free of spyware, malware, nagware, and such.

Tip: Package unused files with a packager such as  *  7-zip . The packagefile not only takes less harddisk space, but will also defragment/optimize much faster than the individual files.

Tip: The first partition on a harddisk is significantly faster than other partitions. Try to use other partitions only for "SpaceHog" data (see above "What are SpaceHogs?").

How it works


JkDefrag is based on the standard Defragmentation Interface by Microsoft (the FSCTL_GET_VOLUME_BITMAP, FSCTL_GET_RETRIEVAL_POINTERS, and FSCTL_MOVE_FILE function calls), just like all other defragmentors. It is therefore very solid, there is no risk of losing data or the disk getting scrambled, and you can run it while the computer is in full use.

Phase 1: Analyze
JkDefrag has to scan all the files on the disk to determine if they are fragmented and where they are.
Phase 2: Defragment
All fragmented files are defragmented, simply by moving them to the first gap on the disk that is big enough. If there is no gap big enough then the defragmenter will reduce the number of fragments in the file by moving as much of the file as possible into the largest gaps available.
Phase 3: Optimize
  • On most harddisks the beginning of the harddisk is considerably faster than the end, sometimes by as much as 200 percent! See the link to "HD Tune" in the "See Also" chapter for a nice little free program to measure your disk. The default JkDefrag optimization strategy therefore moves all files to the beginning of the volume. It is intended for daily use and will simply fill gaps with files from above, very quick and with very little data movement.
  • JkDefrag classifies files into 3 zones: directories (zone 1), regular files (zone 2), and space hogs (zone 3). Directories are perhaps the most accessed data on disk, so zone 1 is placed at the beginning of the harddisk. After the directories comes a free area (see below), then zone 2 with regular files, another free area, and then zone 3 with space hogs (less important files that take up a lot of space). The begin and end of the zones is determined automatically, see the "-f" option.
  • A running computer will create and delete temporary files like there is no tomorrow. If the harddisk were completely optimized then the only place for new temporary files would be behind all the other data. Which is rather slow. So JkDefrag maintains a free space of 1% of the total disk space between zone 1 (directories) and zone 2 (regular files), and between zone 2 and zone 3 (space hogs).
  • Sorting the files on your disk can give you even more speed. There are several sorting strategies to choose from (see the "-a" options). These are all very slow and intended for occasional use only.
  • Windows reserves a percentage of the disk for the MFT (Master File Table), but can place normal files there if the rest of the disk is full. The files will remain there, even when there is enough space again. JkDefrag looks for files in the MFT reserved space and moves them to normal diskspace, making the reserved space available again for the MFT.
When the utility is running you will see lot's of messages zipping by showing you exactly what is happening. The messages are also stored in the logfile ("JkDefrag.log" or "JkDefragCmd.log") for later inspection. The logfile may also contain warning messages, for example when a file could not be moved. This is normal, no need to worry. Windows has many system files that cannot be moved while Windows is running.

Known problems


  • The "Prefetch\Layout.ini" file is not yet supported. This means that JkDefrag will undo the boot optimization of the build-in XP and Vista defragger.
  • Files that are encrypted by Windows can be defragmented and optimized, but their $EFS:$LOGGED_UTILITY_STREAM counterpart cannot. The Windows CreateFile() system call refuses to open these files and I have not yet found a workaround.
  • The Microsoft defragmentation API on Vista can defragment and move the MFT, but JkDefrag cannot use this capability yet.
  • The Windows defragmentation API refuses to move directories on FAT32 filesystems. This is a known FAT32 limitation and not a bug in JkDefrag.
  • The Windows defragmentation API on Windows 2000 does not work on disks that were formatted with a clustersize greater than 4KB. This is a known API limitation and not a bug in JkDefrag. There is no risk of losing data, the API simply refuses to move files.
  • A user has reported that his computer freezes when Avira Antivir Professional starts while the JkDefrag screensaver is active.
  • A user has sent me a message that HP advises against defragmentation of the special "recovery" partition on their computers. My defragger uses the standard Microsoft defragmentation API, so I think it is safe to use, but I don't know for sure. I have not found any additional information about this issue anywhere on the internet.
  • JkDefrag makes a special exception for files used by SafeBoot, Acronis OS Selector, and DriveCrypt. The files will never be moved. If you know of any other software that needs a special exception then please let me know.

Contributed by other people


JkDefrag was designed to be fully automatic and is extremely easy to use. Most users can use the program as-is. The GUI wrappers described below can be useful if you have special requirements and are easier to use than the commandline options.

 *  French version
JkDefrag and all the docs translated into French by Sparad0x. Included are a Setup program and the sources, and a special version for U3 flash drives.
 *  German version
JkDefrag and all the docs translated into German by Markus Hörl. Also available is a Setup program and a GUI wrapper.
 *  Spanish version
JkDefrag and all the docs translated into Spanish by Manuel Montero. Also available is a translated version of Emiel Wieldraaijer's GUI.
 *  Italian version
All the docs (not the program itself) translated into Italian by Danilo Angaroni.
 *  Traditional Chinese version
JkDefrag (the program, not the docs) translated into Traditional Chinese by Eddy Guo. Also available is a GUI. Sources included.
 *  JkDefragGui
GUI program by Emiel Wieldraaijer. In English, Dutch, German, French, Spanish, Portuguese, Italian, Romanian, Swedish, Mayar, Polish, Bulgarian, Catalan, Japanese, Slovenian, Russian, and Greek/Hellenic. Includes the "autoit" sources.
 *  JkDefragGui
GUI program by Dirk Paehl. In English. Sources are included.
 *  JkDefragTWGUI
GUI program by Thorsten Willert. Can handle multiple "jobs". In English, although the homepage is in German.
 *  JkDefragStarter
GUI program in German by Thomas Kolb. C++ sources are included.
 *  JkDefrag Installer
Installer (setup) program for JkDefrag by Myriades. Includes the 32 and 64 bits versions, sources, licence. It creates a start menu shortcut for the program, project, logfile, and uninstall.

See also


 *  JkDefrag forum
I have set up a forum for JkDefrag, a place where you can ask questions, give feedback about features you would like, share your experiences, share code that uses the defragger library, and other things about JkDefrag.

 *  HD Tune
Measure your harddisk and discover how much faster it is at the begin than at the end. Can also monitor the temperature of your harddisk and scan for surface errors.

 *  Defragmentation
Wikipedia page about defragmentation.

 *  Pagedefrag by Microsoft TechNet (formerly Sysinternals)
Paging files and registry hives cannot be defragmented on a running system. This sweet little utility will automatically defragment those files when the system is booting. The counterpart of this utility is "Contig", a small defragger for use on a running system, but my defragger is far superior.

 *  DiskView by Microsoft TechNet (formerly Sysinternals)
Small utility that shows which file is using a particular location on the harddisk. Use this if you are wondering which file JkDefrag could not move. The utility takes a while to start up, because it has to analyze all files one by one, but it's a very nice little utility nevertheless.
 *  HDview
Similar utility as DiskView, by Alexander Freudenberg. Much faster and for NTFS only.

 *  ScanDefrag
A very nice utility that will run maintenance programs as early as possible in the Windows startup. My defragger is one of the supported programs, others are for example Microsoft's Disk Cleanup, ScanDisk/Chkdsk, Norton's Disk Doctor, and others.

 *  AutoRuns by Microsoft TechNet (formerly Sysinternals)
Handy utility to discover all the things that are started when windows is booting.