Classic Computer Magazine Archive COMPUTE! ISSUE 158 / NOVEMBER 1993 / PAGE 54

Defragmenting your hard disk. (utlities that defragment the hard disk) (Column)
by Tony Robert

A badly fragmented hard disk degrades system performance by bogging down file access.

One of the utilities provided with Microsoft's DOS 6 is Defrag. This program helps keep your hard disk in order, resulting in faster file access and an improved success rate should you ever need to undelete a file.

Why is such a utility necessary? What causes the fragmentation that Defrag was created to cure?

The culprit is DOS itself and, more specifically, the way it stores your files.

When you first begin storing files on a newly formatted disk, DOS places the files one after another, starting on the disk's first track. It also keeps information about where each file is stored in the FAT (File Allocation Table). As long as you only add files, your disk will be neatly organized with continuous files stored one after the other.

However, as soon as you delete or make changes to a file, you open the door to fragmentation. DOS stores files in units called clusters, the size of which depends on the size of your disk partition. Let's say you delete a two-cluster file from your disk. DOS updates the FAT to indicate that the two clusters once occupied by that file are now available for other use.

Since DOS stores data as close to the front of the disk as possible, the next time you save a file, DOS will store it in the space left by the deleted file.

But what if the file you're storing is larger than two clusters? DOS fills the two-cluster vacancy with the beginning of the file and stores the remainder in the next available empty spaces on the disk. It keeps track of the various parts of a file through entries in the FAT. When you open a file, DOS checks the FAT to get instructions on where to find all of the file's parts and then reassembles it for you.

DOS's ability to fragment files is a good thing. Otherwise, you could face a situation in which you had 10MB remaining on your hard disk but couldn't store a 2MB file because there were no contiguous spaces larger than 1MB.

On the downside, a badly fragmented hard disk degrades system performance by bogging down file access as the drive head travels all across the disk, rounding up the scattered clusters. File fragmentation also makes it more difficult to recover deleted files using DOS's Undelete command. Undelete normally can recover an unfragmented file in a snap, but if the file is fragmented, it has to do some guesswork to reassemble the file because the road map to the file that was stored in the FAT is no longer available.

Now that we've discussed fragmentation and discovered how it happens, let's look at what to do about it. If you have DOS 6, you can use the Defrag command. If you use an earlier version of DOS, you can get a defragmentation program either separtely or as part of a disk utilities package. (In fact, the defragmentation program that comes with DOS 6 is a version of a program created by Symantec, which produces the Norton Utilities.) Defrag may not have all the bells and whistles of other software, but it gets the job done.

Defrag works on one of two levels. First, it can identify all of the fragmented files on your disk and move them to areas where they will fit contiguously. Or it can rearrange the files on your hard disk so that none is fragmented and all are packaged together at the front of the disk. This latter option essentially rewrites every file on your disk.

Today's defraggers have come a long way since the earliest versions, but because defragmenting involves your entire database, it's wise to take a few precautions: Have a current backup in case something goes wrong, run Chkdsk to make sure your disk has no lost clusters or file allocation errors, and disable any networks and multitasking software such as Windows or task switchers.

DOS 6's Defrag requires a lot of memory. If you receive Insufficient Memory messages, try to free up as much memory as possible by eliminating all TSRs. If memory remains a problem, borrow some memory from your graphics adapter using the following procedure: Add the parameters 1=A000-BFF and NOEMS to the CONFIG.SYS command that loads EMM386, restart the computer, and then run the defragmentation program by typing defrag /g0.

After Defrag has finished its work, remove the parameters you added to the EMM386 line in CONFIG.SYS.

The A000-BFFF memory range is commonly used by video cards to display graphics screens. This procedure borrows that block of memory for use by the operating system. The /g0 switch used when starting Defrag instructs the program to run in text mode rather than graphics mode, avoiding a conflict over that block of memory.

Once you get the hang of using Defrag, you can automate the process by using DOS 6's multiple configuration feature to create a setup that runs Defrag. When you do this, you can use the /b switch on the Defrag command line to cause your system to reboot itself after Defrag has finished doing its work.