Some time ago I wrote an article here exposing the Tune XP tool's supposed magic for defraging the OS boot files. I found what it did and wrote a method for Vista users to do this boot file defrag themselves.
Since I just converted to Win7, I was anxious to see how my method worked with Win7. I am happy to report it works well, and in fact under Win7 it is much more illuminating as to what is happening. Follow along below for details.
First some background info. Win7 and Vista both have an automated process for defragging the boot files. However, under Vista (not sure about Win7 yet) many laptop users never have this automated process kick in. Why? Because the process is designed to start only if the machine is left idle for a period of time. Most laptops are not left idle long enough for the process to trigger, hence the need for a manual way to force the defrag.
Attached to this post is a file named DefragBootFiles.ZIP. (This is EXACTLY the same file that appeared in my post about defragging Vista boot files.) It contains a batch file with two lines:
Code:
Rundll32.exe advapi32.dll,ProcessIdleTasks
defrag -b %SystemDrive%
(If you choose to create your own file DO NOT NAME IT DEFRAG.BAT! If you do it will cause the batch file to loop over and over!)
Open the zip file and move the batch file file to your desktop. Close
ALL running applications.
Then right click on it and
select run as administrator. The first line just tells Win7 that all applications are idle and it can start a background task that is just sitting there waiting for this event to occur. That task analyzes the boot file history that Win7 maintains and creates a file with the optimum order for these files. The second line starts a specialized defrag process that uses that ordering information and puts these boot files into the proper sequence!
When you run the batch file it will popup a command window and looks like it is just sitting there hung on the first line. It's not, trust me. Read on...
If you open Task Manager and view all running processes, the two processes (Defrag and DfrgNTFS) that showed up when we did this under Vista, no longer show up. Instead there is a service that does. In Task Manager if you switch to the Services tab and sort by name you will see defragsvc running. This is a service that is always loaded under Win7 but remains stopped until needed. The line in the batch that forces the idle tasks to start will wake up this service. If you switch to the Performance tab in Task Manager and click the Resource Monitor button, you can then click in the check box to the left of “svchost.exe(defragsvc)" and then open the disk IO segment of the resource monitor. There you can see just the IO that the defragsvc is doing. Also the CPU and DISKIO graphs will then have an additional orange trace just for the stuff the defragsvc is doing. Check this out:
Even cooler, the defrag command in the batch file now has some output. (For those of you who used my batch file under Vista you'll remember that the command window never showed ANYTHING.) If you watch the command window where the batch file is running, when the batch file gets to the second line (and this can take a few minutes as the first line in the batch file takes a while to execute) you will see:
Code:
C:\Windows\system32>defrag -b C:
Microsoft Disk Defragmenter
Copyright (c) 2007 Microsoft Corp.
Invoking boot optimization on (C:)...
Pre-Defragmentation Report:
Volume Information:
Volume size = 49.99 GB
Free space = 21.12 GB
Total fragmented space = 2%
Largest free space size = 4.59 GB
Note: File fragments larger than 64MB are not included in the fragmentation statistics.
When the two lines in the batch file are done the command window will disappear.
Now some IMPORTANT words of caution: Be patient, give it some time. It can take anywhere from a few seconds to an hour even. Just depends on how fragmented your files are. I just ran it and it took about seven minutes. Your disk drive light will show LOTS of activity.
Sit back, have a cup of coffee or whatever.
Just wait until the command window disappears. That cannot be stressed highly enough! DO NOT CLOSE THE COMMAND WINDOW! BE PATIENT! LET IT FINISH! Now reboot and see if it made any difference in boot time.
A couple of additional notes:
First, the defragsvc will continue to show as "running" in the Services tab of Task Manager for a period of time, even after the command window goes away. It will eventually switch back to a "stopped" status all by its self. Second, on a clean install of Win7 you may not see a drastic improvement in boot times. It depends on how many drivers you had to install your self and how many were done by the Win7 install. It is perfectly safe to run this batch whenever you want, but the only time you NEED to run it is after you have updated a driver or an application that loads as a program at boot time or runs as a service (which are always loaded at boot time.)
One more parting warning:
DO NOT CLOSE THE COMMAND WINDOW!
Gary