Hack 94. Speed Up Your Hard Disk by Improving Defragging
One of the simplest ways to speed up your PC is by defragmenting your hard disk. Here's how to get the most out of XP's built-in defragmenter and a third-party program that should speed up your hard disk even more.
Perhaps the simplest way to speed up your PC is to use a disk defragmenter, which will help you open applications and files more quickly. As you use applications and files, they get spread out in fragments across your hard disk. The next time you use them, they take longer to open because your hard disk has to find each disparate fragment so that they can be assembled when you open the file. A disk defragmenter stores files and applications contiguous to one another so that they can be fetched much more quickly than if they were spread out across your whole disk.
XP includes a built-in defragmentation program (sometimes called a defragger), which you can run by choosing Control Panel Performance and Maintenance "Rearrange items on your hard disk to make programs run faster." But there are ways you can use it more effectively, and there are third-party programs that do a more effective job of defragmentation as well.
10.8.1. Defragment Boot Files
One of the biggest improvements of XP's defragger over previous Windows versions is that it can perform a boot defragment, placing all boot files contiguous to one another so that you boot faster. The boot defragment option is usually enabled by default, but there's a possibility that it could be disabled, or enabled improperly. You can make sure it's enabled, using a Registry hack. Run the Registry Editor [Hack #83] and go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Dfrg\BootOptimizeFunction. Find the Enable string. If the String value is set to N, change it to Y. If it is Y, leave it as it is, since that means boot defragmentation is enabled. Exit the Registry and reboot. The next time you defragment your disk, the boot files will be defragmented.
10.8.2. Run the Disk Defragmenter from the Command Line
If you prefer the command line to the graphical interface, you can avoid maneuvering through menus and dialog screens to defragment your hard drive. (Using the command line also gives you greater control over the defragmentation process, as you'll see in this hack.) To defragment a hard drive, type defrag C: at a command prompt, where C is the hard drive you want to defragment. When you use the command line, you won't see a visual display of the defragmentation process, and you won't be able to pause it or cancel it.
defrag also works invisibly in the background to make sure your programs load more quickly. It's set up so that every three days, when your computer is otherwise idle, it moves program code to the outside of the disk to make programs load more quickly. You can force it to do that manually, without having to do a full defragment, by using the -b switch, like this:
defrag C: -b
It takes only a few minutes for defrag to do this, in contrast with a full defragmentation, which can easily take more than 20 minutes, depending on how fragmented your system is and the speed of your processor.
You can use several other command-line switches with the defrag command:
Analyzes the drive you want to defragment and shows you a brief analysis report, summarizing the hard-disk size and total fragmentation. It only displays the report, however; it does not defragment the drive.
Analyzes the drive you want to defragment and shows you a comprehensive analysis report, detailing the size of the hard disk, the percentage of free and used space, total fragmentation, and total number of fragments, among other details. It gives the analysis report, defragments the hard disk, and then gives an analysis of the hard disk after defragmentation.
Forces the drive to be defragmented, even if there isn't a certain minimum amount of space. Normally, you can defragment the drive only if your hard disk has at least 15% of its space free.
10.8.3. What to Do If the Disk Defragmenter Won't Defragment Your Drive
There will be times when the Disk Defragmenter won't defragment your drive, or will defragment it only partially. It won't defragment your drive if you don't have at least 15% of the drive's space free. To solve the problem, as explained previously, type defrag C: /F at the command line, where C is your hard drive.
There are also certain files and areas that the Disk Defragmenter won't defragment: the Recycle Bin, the Windows page file, and Bootsect.dos, Safeboot.fs, Saveboot.rsv, Hiberfil.sys, and Memory.dmp. There's not much you can do about it, though it's a good idea to empty the Recycle Bin before defragmenting.
Often, the Disk Defragmenter won't defragment every file on the first pass. Your best bet here is to use brute force: run it again until it defragments the files it missed the first time around. Also, keep in mind that the Disk Defragmenter won't defragment any files that are currently in use, so make sure to close all programs; if some files won't defragment, it might be because they're being used by an open program. Sometimes, programs might seem to be shut down, but in fact might be running in a kind of phantom mode. For example, Outlook sometimes stays running even after you've shut it down. To make sure your programs are completely shut down before running the Disk Defragmenter, run the Task Manager by pressing Ctrl-Alt-Del or right-clicking the taskbar and choosing Task Manager. Check both the Applications and Processes tabs to see if any programs, like Word for Windows (Winword.exe) or Outlook (Outlook.exe), are still running. These two programs sometimes continue running even after you've shut them down.
10.8.4. Get a Better Disk Defragmenter
For most purposes, XP's Disk Defragmenter works fine. But if you're a system administrator who needs to defragment multiple machines or defragment servers, you'll be better off with a better defragmenter. Even single users of XP might want a better disk defragmenter for purposes such as easy scheduling of defragmenting and the ability to defragment files that XP's defragmenter can't handle. Two of the best XP defragmenters are available as try-before-you-buy software:
Figure 10-8. PerfectDisk2000 options