Chapter 7. Preparing and Maintaining Disks

Understanding Disk Preparation

Both floppy disks and audiocassette tapes use magnetic media to store information, but they're different in other ways. You cannot just drop a blank disk into a drive and use the disk in the same way that you can use a blank tape to record.

Why? The disk's recorded areas (sectors) can be accessed in any order, randomly. The tape, however, is sequential. As it plays, the tape recorder doesn't jump around from place to place—unless, of course, it is being operated by a teenager.

To implement random access on a disk, you first must lay down information that can be used to find small sections of the disk quickly. In some ways, this process is like drawing the lines on a sheet of notebook paper to show where the writing should be done. This preparation process is called formatting. The DOS FORMAT command performs this process for disks; you do nothing more than enter the command. FORMAT analyzes a disk for defects, generates a root directory, sets up a storage table, and makes other technical modifications.

When you format a disk, DOS creates data-storage divisions on the disk's surface. As you learned in Chapter 6, “Understanding Disks and Disk Drives,” these divisions are concentric circles called Figure 7.1). DOS decides what type of drive you have and then positions the tracks accordingly.

Anatomy of a floppy disk.

Figure 7.1. Anatomy of a floppy disk.

You probably already know that with computers, items that are numbered often begin with 0 rather than 1. It's the same way with tracks on the disk; they're numbered beginning with track 0. DOS uses this first track (track 0) to record vital information about the disk's format. Later, by checking this information on track 0, DOS quickly can determine how to work with the disk.

As you can see in Figure 7.1, each track is divided into segments called sectors, which are the smallest divisions of a disk. When you issue the FORMAT command, DOS creates a special disk table called the file allocation table (FAT). The FAT, which is always located on track 0, monitors every sector on a disk as groups of clusters. DOS stores data in the clusters and uses the track and cluster numbers to retrieve the data.

A cluster is the smallest unit of storage that DOS allocates for file storage at one time, unless you are using DoubleSpace or a similar file-compression utility. DoubleSpace drives have storage allocated in smaller units, but this doesn't affect the way DOS views the disk. DOS hands data to be written to DoubleSpace in the standard way.

In the preceding chapter, you learned about cylinders. A cylinder is formed by stacking tracks on top of one another. A cylinder on a floppy disk, for example, is made by stacking two tracks: the front and back of the disk. The two read/write heads in the floppy drive are positioned over two tracks. Tracks are broken up into sectors, so the read/write heads are positioned over two sectors.

DOS does not write one file on the front sector and one file on the back sector because doing so creates a situation in which the read/write heads have to move around too much, slowing operations. To prevent this problem, DOS looks at the two sectors under the floppy drive's heads as a single unit—a cluster. Therefore, if you write a file containing only six bytes onto a floppy disk, DOS reserves a cluster (two 512-byte sectors) for the file to reside in.

On hard disks, the number of sectors in a cluster also is equal to the number of read/write heads. Therefore, a disk with four platters would group eight sectors into a cluster, so writing a six-byte file would actually take 4KB of free space.

At first, all this unused space might seem wasted, but look at any disk and see how many files are only six bytes long. Data files are seldom static because information constantly is being added or removed. Chances are that the file won't remain six bytes long. Also, when you think that most files are thousands or hundreds of thousands of bytes long, a few unused sectors represent a very small percentage of total used disk space.

All DOS commands use tracks and clusters as road maps that enable them to carry out their operations. When a disk is formatted, DOS creates a FAT and root directory that are suited to the capacity of the disk.

Preparing Floppy Disks with the FORMAT Command

The FORMAT command prepares disks for use. All disks to be used by DOS must be formatted by DOS to be treated as valid DOS disks. Both floppies and hard disks must be formatted before they can be used. If you try to use a disk that has not been formatted, DOS reports a General failure, which sounds cataclysmic. All it really means is that the disk you are trying to read does not have valid format information. If the disk you are trying to read has been formatted and you know that it has been formatted, a problem exists. If that drive is your C: drive, you do have a cataclysmic experience to endure. Most of the time, however, a General failure just means that somebody has handed you an unformatted disk.

Caution

When you issue the FORMAT command with its required parameters, DOS presents you with a prompt, requiring that you answer a question before the command actually begins its work. In the case of a floppy, DOS prompts you to insert the proper disk into the drive. On a hard disk, DOS reminds you that you are about to wipe out everything on the disk.

In either case, the tendency of experienced users is just to hit the key and go. Don't! Take a deep breath and read the prompt. You might have accidentally specified C: when you really meant B:. Take a moment to be sure; the data you save might be your own.

Reformatting an old disk also can be an efficient way to delete the contents without the hassle of dealing with individual files and directories. Before DOS 5.0, reformatting a disk in effect erased the data stored on the disk and left you with no way of getting it back. Starting with DOS 5.0, however, the FORMAT command first determines whether the disk contains data. If the disk contains data, FORMAT saves a copy of the boot sector, FAT, and root directory in a safe place on the disk. Then UNFORMAT can find the information if you need to unformat the disk. You can unformat a disk only if you have not created or copied other files onto the disk.

In DOS 5.0 (or later), the FORMAT command clears the disk's FAT and the first character of each filename in the root directory but does not erase any data. The program also scans the entire disk for bad sectors. FORMAT then saves the first letter of each filename in a safe place on the disk.

Caution

FORMAT is a DOS command that can quickly wipe out the contents of a disk. This command is safer than it used to be, but before you use it, make sure that you are familiar with its syntax and the way it works. FORMAT issues warning messages onscreen and prompts you for verification before formatting a hard disk. Take care when you use FORMAT, read the screen prompts, and, most importantly, keep good backups of your data.

Also, the FORMAT command cannot format a disk that has been write-protected. If the command fails for this reason, determine what the disk contains before simply unprotecting the disk and proceeding with the format.

Formatting Floppy Disks

Most disks you buy today come preformatted. If not, then they must first be formatted by DOS before using them. Some commands, such as DISKCOPY and BACKUP, stop and format disks if they're given unformatted disks to work with, but few DOS commands are so accommodating.

The syntax for the FORMAT command is as follows:

FORMAT d: /Q /V:label /F:size /S /B /C /U /1 /4 /8 /N:sectors /T:tracks

This syntax shows all the switches available with the FORMAT command, but you normally use only a few of them at a time. (All the FORMAT switches are discussed in the section “Using FORMAT's Switches,” later in this chapter.)

You use the simplest version of the FORMAT command when you are formatting a floppy disk that has the maximum capacity of which the drive is capable, as in the following example:

FORMAT A:

This command formats a nonbootable disk in the A: drive. If you are formatting a 360KB disk in a drive whose maximum capacity is 360KB, or if you are formatting a 1.2MB floppy in a high-density drive, fine. If, however, you are formatting a 360KB disk in a 1.2MB drive, you have to give the FORMAT command that information. To tell the FORMAT command the desired format size of the disk, use the /F switch. The /F switch is followed by a colon (:) and the size of the disk to be formatted, as in the following line:

FORMAT A: /F:360

This command formats a double-density 5 1/4-inch disk in a high-density drive. Similarly, the following formats a double-density 3 1/2-inch disk in a high-density drive:

FORMAT A: /F:720

Remember, if you are formatting a high-density disk in a high-density drive, you do not have to give FORMAT the /F switch. Table 7.1 provides the valid values you can enter as part of the /F switch.

Table 7.1. Acceptable /F Switch Settings for Floppy Disks of Various Capacities

Size Can Be Entered As (Select One)
160KB 160 160K 160KB    
180KB 180 180K 180KB    
320KB 320 320K 320KB    
360KB 360 360K 360KB    
720KB 720 720K 720KB    
1.20MB 1200 1200K 1200KB 1.2 1.2M 1.2MB
1.44MB 1440 1440K 1440KB 1.44 1.44M 1.44MB
2.88MB 2880 2880K 2880KB 2.88 2.88M 2.88MB

You cannot arbitrarily decide to format a double-density disk as a high-density disk. If you try to format a 720KB disk as a high-density 1.44MB disk, DOS tells you how to proceed, as shown here:

D: >FORMAT B: /F:1440
Insert new diskette for drive B:
and press ENTER when ready...

Checking existing disk format.
Existing format differs from that specified.
This disk cannot be unformatted.
Proceed with Format (Y/N)?y
Formatting 1.44M
Invalid media or Track 0 bad - disk unusable.
Format terminated.
Format another (Y/N)?

As you can see, DOS asks whether you want to format another disk. Just make sure it is a disk with a capacity matching the /F switch's value.

Similarly, you cannot format a 2.88MB disk if your floppy drive doesn't support it, even if you have a 2.88MB disk in hand. If you attempt this action, you see the following messages:

D: >FORMAT B: /F:2880
Insert new diskette for drive B:
and press ENTER when ready...

Checking existing disk format.
Existing format differs from that specified.
This disk cannot be unformatted.
Proceed with Format (Y/N)?y
Formatting 2.88M
Parameters not supported by drive.

Other switches can be added to the command line to provide other formatting services. You can use the following command line, for example, to format a bootable 720KB disk in a 1.44MB drive:

FORMAT B: /F:720 /S

When you add the /S (System) switch, FORMAT creates a bootable disk.

FORMAT's Other Tasks

The primary task of the FORMAT command is to divide the disk into logical storage sectors, but this task is not the command's only purpose. FORMAT gives each disk a unique serial number and prompts you for a volume label (name) for the disk. As the formatting proceeds, FORMAT continually updates what percentage of the disk has been formatted.

Assume for the moment that you have issued the command in the preceding section to format a 720KB bootable disk. The following lines show the FORMAT dialog from start to finish:

C: >FORMAT B: /F:720 /S
Insert new diskette for drive B:
and press ENTER when ready...

Checking existing disk format.
Formatting 720K
Format complete.
System transferred

Volume label (11 characters, ENTER for none)? bootable

      730,112 bytes total disk space
      199,680 bytes used by system
      530,432 bytes available on disk
        1,024 bytes in each allocation unit.
          518 allocation units available on disk.

Volume Serial Number is 1F44-0EE0

Format another (Y/N)?

When you press Enter to begin formatting, FORMAT first displays a two-line prompt, telling you to enter a disk in drive B. Always make sure that this is what you intend. Next, FORMAT must perform several steps.

The first of these steps is to check the disk format and preserve the FAT and directory structures in case you need to use the UNFORMAT command. Formatting then begins, and FORMAT ticks off the percentage of completion until the format is finished. You are told that the format is complete and nominally error free. If you use the /S switch, the boot sector is prepared, and the DOS system files are transferred to the disk.

You then are prompted to provide a volume label. Most users simply press Enter to bypass this option, but you can use the volume label to your advantage in creating a cataloging system for your disks. You might want to name floppy disks according to categories such as budget, correspondence, backups, and so on.

When you press Enter to leave the Volume label prompt, FORMAT displays some relevant numbers about the disk. The first line shows the total capacity of the disk. If you create a bootable disk, the second line shows the amount of space taken up by the DOS system files. You also are shown the amount of remaining free space on the disk.

Caution

As you can tell by examining the information provided by FORMAT, the DOS system files take up almost 200KB of space on a newly formatted disk. Don't use the /S switch carelessly. This switch is intended only for the disks with which you plan to start the computer. Making disks bootable unnecessarily is a major waste of space.

FORMAT then provides you with numerical data on what it calls allocation units. In this context, saying allocation units is just a fancy way of saying clusters. Each sector is 512 bytes, and a floppy disk has two read/write heads; therefore, a cluster is 1,024 bytes in length. The second line tells you that 518 clusters are available. Multiply 518 and 1,024, and you get 530,432, exactly the amount of free space shown by FORMAT.

Note

As reliable as floppy disks are, they sometimes have flaws. If you hear an unusual grinding or churning noise while formatting a disk, the disk is probably damaged or has an excessive number of flaws. Any bad sectors found by FORMAT are reported as part of the numerical data.

Depending on the number of flaws that are found, you might want to reformat the disk, throw it away, or use it only for noncritical storage.

The last thing the FORMAT routine does is to assign a serial number to the disk. The purpose of a serial number is to enable programs to determine whether you have switched disks. The serial number, which is assigned automatically during formatting, uses the time and date of the format to create a hexadecimal number to be used as the serial number. No two disks from the same machine should ever have the same serial number, assuming that the system clock is properly set.

Finally, FORMAT offers to process another disk. By choosing this option, you can format more than one disk at a time. If you answer yes to the prompt by pressing Y and then Enter, FORMAT prompts you to place another disk in the drive. Any subsequently formatted disks will have the same attributes as the command-line parameters you entered to start the command. Only the serial numbers will be different.

Using FORMAT's Switches

The FORMAT command responds to several switches that modify its behavior. Table 7.2 provides a list of the available switches in the FORMAT syntax. Detailed information also is available in Appendix F,“Command Reference.”

Table 7.2. Commonly Used FORMAT Switches

Switch Action
/B Allocates space on the formatted disk for system files by creating hidden files of the same name and size on track 0. Used to create disks that can be made bootable with DOS 4.01 and earlier versions.
/F:size Specifies the size of the floppy disk to be formatted (such as 160, 180, 320, 360, 720, 1.2, 1.44, and 2.88). You can specify kilobytes or megabytes if you prefer, but doing so is not necessary because DOS understands all the parameters shown here.
/Q Performs a quick format on a previously formatted disk. This switch effectively and quickly erases the contents of a disk so that it can be used again.
/S Copies the system files and COMMAND.COM to the formatted disk, creating a bootable disk.
/U Performs an unconditional format so that the disk cannot be unformatted with UNFORMAT.
/N:sectors Enables you to specify the number of sectors per track (between 1 and 99). This switch now is obsolete and has been replaced with the /F:size switch.
/T:tracks Specifies the number of tracks per disk side (between 1 and 999). This switch now is obsolete and has been replaced with the /F:size switch.
/V:label Enables you to specify the volume label without waiting for a prompt.
/C Retests a block previously marked as bad.
/1 Creates single-sided disks. This switch now is obsolete.
/4 Provides a shortcut for formatting a 5 1/4-inch 360KB floppy disk in a high-density drive. This switch does the same thing as specifying /F:360.
/8 Creates disks that are compatible with early versions of DOS that used 8 sectors per track rather than the 9 or 15 used today. This switch now is obsolete.

The following sections describe some of the ways in which you can use the FORMAT command's switches.

Performing a Quick Format (/Q)

One way to clear all data from a disk is to format the disk. Because the formatting procedure can be relatively slow, the Quick Format feature was introduced.

Using a Quick Format saves you the hassle of changing the attributes of read-only files so that they can be deleted. A Quick Format also gets rid of directories without the laborious process of deleting all subordinate files and directories.

To clear data from a disk, type the command FORMAT /Q and then press Enter. If FORMAT cannot give a disk a Quick Format, a prompt appears, asking whether you want to do a regular format.

Performing an Unconditional Format (/U)

Unless you use the /U switch, the FORMAT command performs a safe format of previously formatted disks. FORMAT first determines whether a disk has been formatted. If the disk has been formatted, FORMAT clears the FAT, boot record, and root directory but does not erase any data. FORMAT then scans the entire disk for bad sectors and saves a copy of the FAT, boot record, and root directory to a MIRROR image file where the UNFORMAT command can find them. If the disk has not been formatted previously, FORMAT overwrites every data byte with the hexadecimal value F6.

If you want DOS to overwrite all data on a previously formatted floppy disk (a procedure called unconditional formatting), use the /U switch. The following command, for example, unconditionally formats a disk in drive A:

FORMAT A: /U

Adding System Files (/S)

If you want to use a disk to start your computer, the disk must contain hidden DOS system files as well as the command processor (COMMAND.COM). One way to install these system files on a disk is to use the /S switch during the formatting procedure. The /S switch reduces the disk's available storage capacity by about 185KB.

→ For details on the /S switch, see Chapter 2, “Starting DOS,” p. 23.

Caution

Don't use the /S switch with FORMAT unless you plan to create a disk from which you can boot. Having at least one bootable system disk as a backup is important in case the disk that contains your working copy of DOS fails or your hard drive develops errors.

Preparing the Hard Disk

Quite apart from the normal formatting that must be done to any DOS disk, hard disks require a little bit of extra work to get them ready for use. DOS provides the FDISK command to prepare a hard disk to be formatted.

The following sections explain how DOS divides and formats a hard disk. If you are relatively inexperienced, be sure to heed all warnings and read all explanations carefully. You are moving into potentially dangerous territory when you start playing around with FDISK.

However, if you are determined to experiment with FDISK, make sure that you have a good backup of everything on the disk.

Caution

Many computer dealers preinstall DOS, Windows, and other programs you purchase. In all cases, you should have copies of these programs on their original floppy disks, or more common nowadays, CD-ROM. Without such disks, you do not have a legal copy of the program. If your dealer has installed an application, such as a word processing program, do not format the hard disk unless you also have a copy of the program on CD-ROM or floppy disks. If you reformat your hard disk, all programs and data will be erased.

Dividing a Hard Disk with FDISK

Before you can format a hard disk, you must partition it—that is, divide the hard disk logically into one or more areas called partitions. A partition is simply a section of the storage area of a hard disk. Many operating systems, including DOS, can use disk partitions, and most systems have some utility program that creates and manages partitions. In DOS, that utility program is the external command FDISK.

Note

Many computer dealers use FDISK on a system's hard disk before delivering the system to the user. In addition, FDISK is executed automatically by the DOS 6.22 Setup command during installation. If your hard disk contains files, it has already been partitioned with FDISK and formatted. If you have any questions about your hard disk's preparation, consult your dealer.

Most hard disk users choose a DOS partition size that encompasses the entire hard disk. In other words, the one physical hard disk appears to DOS to be one logical hard disk. In this day of rapid growth in the size of the ordinary hard disk, you might want to rethink the idea of making a single volume out of a disk that might span many thousands of megabytes. You might find it more manageable to have several partitions of smaller sizes.

DOS uses a partition table to store information on how the space on a hard disk is arranged. FDISK is the command that manipulates the information in the table.

Some PC users want to have both DOS and another operating system on their hard disk. Different operating systems use file systems that might not be compatible with DOS. Some operating systems, for example, can use file systems that are compatible with DOS-OS/2 and Windows NT. Some operating systems that have DOS-compatible file structures can use multiboot routines that give the user the opportunity to select which operating system to boot. The incompatibility comes into play only when you are using totally foreign operating systems that must reside in different partitions. FDISK, however, only can create DOS partitions and reserve spaces on the disk; another operating system's equivalent utility can be used to prepare the partition for its own file scheme.

The partition table can be arranged so that DOS uses one partitioned section while another operating system, such as Unix, uses the other partitioned section. Through separation, each operating system sees its partition as its own hard disk. Only one of these partitions, however, can be bootable. To use a partition with another operating system, you have to boot from a floppy when using the other operating system.

Fortunately, DOS installations that require a second operating system are rare. The rest of this chapter pertains to the 99.9% of installations in which DOS is the only operating system in use.

As you probably remember from an earlier chapter, DOS looks at disk drives as logical devices. A byproduct of this arrangement is the fact that you can use FDISK to carve up a single large hard disk into smaller, more manageable volumes. Each volume has its own drive letter and, for all practical purposes, becomes a separate hard disk.

Note

Although making a large hard disk into a single logical drive might seem tempting, doing so might create some disadvantages. If your hard drive is especially large, any command that scans the entire drive, such as DIR or CHKDSK, might take an inordinately long time to complete execution. Files might become harder to find due to their sheer numbers. Unless you work with very large data files, you might prefer to limit your logical drives to 120MB or smaller.

The FDISK command has no parameters. To start this utility, you simply type FDISK and press Enter.

In DOS 3.3 and later versions, you can use FDISK to create more than one DOS partition. After you create a primary DOS partition (or boot disk) with FDISK, you can create an extended DOS partition, which you can divide into one or more logical drives.

After you have created your partitions, you must use the FORMAT command to format all DOS partitions and logical drives before you can use them.

Caution

You can use the FDISK command to delete an existing partition from the disk partition table. If you delete an existing partition, you lose all data in the files contained in that partition. Be sure that you have backed up or copied any data from a partition that you want to delete. FDISK is not a command to experiment with unless your hard disk contains no data.

There are two types of partitions: the primary partition, from which the computer can boot, and an extended partition, which you can divide into logical drives. The primary DOS partition is normally assigned the drive name C. The extended partition can be used to create drives D, E, F, and so on.

After you partition the hard disk, DOS treats the logical drives as separate drives and creates a file system for each when the drive is formatted. Figure 7.2 shows the opening screen that appears when you run FDISK.

FDISK partitions your hard disk so that DOS can use it efficiently.

Figure 7.2. FDISK partitions your hard disk so that DOS can use it efficiently.

As you can see, the Create option is the offered default; the number for this option appears within the brackets following the Enter choice prompt. You won't destroy the data on your disk if you accidentally choose this option; FDISK will simply beep and inform you that you have already created partitions.

Caution

The third choice enables you to delete partitions. Unless something is wrong with your system or you are deliberately reconfiguring a drive, leave this one alone! Deleting partitions results in data loss.

To see how your hard disk is partitioned, press 4 to select Display Partition Information and then press Enter. FDISK presents a screen similar to the one shown in Figure 7.3. The information shown by your computer, of course, will be different.

Partition information as displayed by FDISK.

Figure 7.3. Partition information as displayed by FDISK.

Figure 7.3 shows the FDISK display output for the hard disk that was used in writing this chapter. Note that this disk has two partitions, both dedicated to DOS format. The first acts as the C: drive. The A under status indicates that it is the active partition and that it can be used for booting. This drive—drive C—is 32MB in size, uses the standard DOS FAT 16-bit architecture, and takes up only 10% of the hard disk's available space.

Figure 7.3 also shows that an extended partition of 289MB takes up the rest of the drive. As the bottom of the FDISK display indicates, this partition is used to create logical drives. To see what logical drives have been created in the extended partition, you only have to press Enter because Y, the default value, is already displayed. To return to the main FDISK screen, press Esc. Figure 7.4 shows the makeup of the extended DOS partition.

Extended partitions can be used to carve the hard disk into logical drives.

Figure 7.4. Extended partitions can be used to carve the hard disk into logical drives.

The logical drive information shown in Figure 7.4 indicates that the 289MB contained in the partition is divided into five logical drives, D: through H:. The size of each of the logical drives is shown and marked as having the standard DOS file allocation table. The Usage column indicates the relative sizes in relation to the partition, not the disk as a whole. Sharp-eyed readers will notice that the usage numbers add up to only 99%; FDISK rounds off fractional percentages.

By examining the information in Figures 7.3 and 7.4, you can tell that the drive has 321MB of usable capacity broken into six drive letters, C: through H:. The rationale behind these settings and the relative sizes of the drives is as follows.

Drive C takes the biggest pounding. Because it is the boot drive, almost every commercial software package you install tries to make changes or install drivers on the C: drive. C: also is the traditional home of the DOS directory in which DOS's external command program files are written and of directories used to store utility programs such as Norton Utilities and PC Tools. Plus, C: usually houses a TEMP directory, where many software packages look for disk resources to use as a scratch pad. Windows Print Manager, for example, uses the TEMP directory to spool printing jobs into a file so that it can send data to the printer in the background. The drive is just large enough to accommodate all these uses and provide space to install software for testing, yet it's small enough to back up easily. Unproven software sometimes eats the disk it's installed on, so easy restoration of backup files is a key factor in the size of the C: drive.

Drive D on the hard disk is the Windows drive. Windows software tends to be large, as is Windows itself. When you use DoubleSpace, the 100MB of reported space becomes closer to 200MB—almost enough to do the job. Drives E and F store applications and the overflow from drive D. On drives E and F, you find word processors, programming editors, communications programs, and so on. Drive G is given over to graphics programs and files. Drive H is a programming disk where source code to programs is written. Source code is the term used for the files that contain programming language statements compiled into working EXE and COM files.

As you can see, the partitions of this hard disk have been thought out in advance. Utilizing disk space effectively is the first step in optimizing DOS's efficiency. Before you partition a hard disk, analyze the ways in which you use a computer. If you do desktop publishing, use Windows; if you do database work on large files, you might want to partition the disk into fewer drives with larger capacities. One key point to keep in mind is that partitions should be small enough to enable you to make backups easily.

Checking Partition Status

You can check the status of your partition table by using the FDISK command's /STATUS switch as follows:

FDISK /STATUS

FDISK shows a table of your hard disk's partition information without starting the FDISK program (see Figure 7.5).

Displaying disk partition information.

Figure 7.5. Displaying disk partition information.

Caution

The next section of this chapter contains specific information about creating partitions with FDISK. Performing the steps given in the example will destroy the data on your hard disk. Do not practice these steps unless you have reliable backups of all the data on all the drives of your hard disk. If you can, practice first on a hard disk that is not currently loaded with data.

Partitioning a Drive

The steps required for partitioning a hard disk for the first time and those required for repartitioning a drive to change the structures of the logical drives are very similar.

If you are repartitioning an existing hard disk structure, make sure that you have a rock-solid backup of all the files on the disk. If you plan to change the sizes of logical drives, back up individual directories rather than perform a whole-drive backup.

The actions shown in this section should be performed only by experienced users of DOS. Not knowing what you are doing can cost you all the files on your hard disk. After you have your backups safely stored away and have a bootable floppy containing FDISK and FORMAT, follow these steps to repartition your hard disk:

  1. Plan the partitions. Decide how you want the partitioning to be done. Create a chart on paper and apportion the available disk space among the partitions you want to create.

  2. Start FDISK. If you are repartitioning a drive that is currently partitioned, choose to delete existing partitions from the main FDISK menu. After the existing partitions have been deleted, the drive will be unusable until you repartition and reformat.

  3. Create the primary partition. Select Create DOS Partition from the FDISK main screen. If the drive does not have any existing partitions, a menu appears. Choose 1 to create the partition to act as drive C. By default, FDISK offers the entire disk capacity for the primary partition. If you want to break the hard drive into multiple logical drives, answer N to the confirmation prompt and press Enter.

    FDISK enables you to enter capacities for partitions as megabytes or as a percentage. Choose one method or the other, and then assign the amount of space you want C: to have and return to the main FDISK menu.

  4. Make the primary partition the active partition. Choose Set Active Partition from the FDISK main menu to make C: the active partition to be made bootable.

  5. Create the extended partition. Again, choose Create from the main menu, but this time choose to Create Extended DOS partition. Again, FDISK offers to make the remaining disk space the size of the partition. If you want just C: and D:, accept the default. If you want to create more than one logical drive, reject the default and follow the prompts to specify the size of the partition to be used for D:.

  6. Create logical drives. If you finish creating a partition and disk sectors still are not assigned to a partition, FDISK loops around to create another logical drive. It offers to use all remaining space for the logical drive. If you want to break the remaining space into more than one drive, answer N to reject the default and enter a value manually. When you create the last logical drive, accept the default to make sure that no usable cylinders are left out of the partition table.

  7. Format each logical drive. After you have set up the partitions the way you want them, exit FDISK and save the partition table. Reboot the computer using your bootable floppy and then format each of the logical drives you have created. Remember to format C: using the /S switch to make it bootable.

  8. Reboot and check the drives. After you have formatted each of the logical drives, reboot the computer from the hard disk and run directories of all the logical drives to make sure that they were created the way you intended and that they are recognized as valid DOS drives.

  9. Install files. If you are repartitioning a drive or installing a new hard disk on an existing system, restore all the backups you made, including the DOS files on the boot drive and the files in the DOS directory.

    If you are installing a new system, install DOS and then begin installing any software packages that have to reside on the hard disk of the computer.

  10. Test, test, test. Before you pronounce the job finished, reboot from the hard disk, test all the software that you installed, and make sure that all configuration files, drivers, and so on are actually written at the locations specified by entries in CONFIG.SYS and AUTOEXEC.BAT.

Formatting a Hard Disk

Simply stated, you format a hard disk or logical drive just like you format a floppy disk.

Assume that the hard disk (or logical disk) you are going to format is drive C. (If you are formatting another drive, use its drive letter in place of C in the example.) If your drive is not the primary DOS partition, you don't have to use the /S switch; DOS boots only from the primary DOS partition. To format drive C, follow these steps:

  1. Insert your working copy of the DOS Startup disk—or any bootable disk that contains FORMAT.COM—into drive A.

  2. Switch to that drive by typing A: and pressing Enter.

  3. Type the following command and press Enter:

    FORMAT C:/S
    

    FORMAT issues the following warning message and confirmation prompt:

    WARNING, ALL DATA ON NON-REMOVABLE DISK
    DRIVE C: WILL BE LOST!
    Proceed with Format (Y/N)?
    

    This prompt is extremely important. When the prompt appears onscreen, examine it carefully to confirm the disk-drive name (letter) before you press Y. If you make a habit of pressing Y in response to the confirmation prompts of less dangerous commands, you might make a serious mistake with this final FORMAT confirmation prompt.

  4. If the specified drive is the one you want to format, press Y; if not, press N to terminate FORMAT. If you press Y, FORMAT updates the display with progress reports on the formatting operation. Depending on the size of the disk that is being formatted, the process can take from just a few minutes to more than half an hour. The greater a disk's capacity, the longer the process takes.

All the normal Format complete and System transferred messages that you see when formatting floppies also are presented when you are formatting a hard disk.

Disk Commands

Several useful DOS commands can help you prepare and maintain disks. The following sections are devoted to these commands.

Naming Disks with LABEL

The external command LABEL adds, modifies, or changes a disk's volume label. In DOS, a volume label is a name given to a physical or logical disk.

If a disk's volume label is blank (if you or another user pressed Enter when FORMAT or LABEL prompted for the label), you can use the LABEL command to add a volume label or change the current volume label.

DOS displays the volume label when you issue commands such as VOL, CHKDSK, DIR, and TREE. Giving each disk—physical or logical—a volume label is a good idea. A disk with a unique volume label is easier to identify than one that doesn't have a label.

The syntax for the LABEL command is as follows:

LABEL d:label

d: is the name of the drive that holds the disk you want to label.

label, the optional label text that you supply as the new volume label, can include up to 11 characters. DOS immediately updates the specified or default drive's label with no warning prompt. If you do not supply the label parameter, LABEL automatically goes into an interactive mode that prompts you for a new label.

Keep in mind this special restriction: You cannot use the LABEL command in a networked drive.

Examining Volume Labels with VOL

The internal command VOL is convenient when you want to view a disk's volume label or verify that a label exists. VOL accesses the disk's volume label from the root directory and then displays the label that was created during the disk's formatting or modified by a subsequent LABEL command.

You can use VOL freely because it is a display-only command; it does not change any files or the label name.

The syntax of the VOL command is simple:

VOL d:

d: is the optional name of the drive whose volume label you want to see. If you omit a value for d:, DOS displays the label for the default drive.

Using SYS to Transfer the DOS System

All DOS disks have a DOS file system, but only disks with the DOS system files and COMMAND.COM can be used to start the computer. The external command SYS transfers (copies) the hidden system files necessary to make a disk bootable.

As you learned earlier in this chapter, you can make a disk bootable by using the /S switch with the FORMAT command. You can use the SYS command when you need to make an already formatted disk bootable. The disk must have room for the system files that SYS intends to transfer, and those system files must be compatible with your version of DOS.

To use SYS successfully, observe the following rules:

  • The destination disk must be formatted.

  • The destination disk must contain sufficient free space for the two hidden system files and COMMAND.COM (just more than 133KB for DOS 6.22 system files; more than 197KB if you use DoubleSpace), it must already contain earlier versions of the system files, or it must have been formatted with the /B switch.

  • You cannot use SYS in a networked drive. If you want to use SYS in a networked drive, you must log off the network or pause your drive. (For the exact restrictions, consult your system's network documentation.)

  • You must include the destination-drive parameter in the SYS command. SYS does not transfer a copy of the system to the current drive; the destination must be a different drive.

The syntax for the SYS command is as follows:

SYS ds: dd:

dd: is the target, or destination, drive for the system files. You must specify a drive name (letter) for drive dd:. The drive specified by ds: is the drive used for the source of the system files.

Suppose that you are using DOS 6.22 with a hard disk and have an empty disk that you want to make bootable for use with another computer. To do so, follow these steps:

  1. Insert the formatted disk (the one you want to transfer system files onto) into drive A.

  2. Type the following command:

    SYS C: A:
    

SYS replies with the message System transferred. The system files now are on the disk in drive A. Now you can use this disk to boot your computer.

Note

The C: in step 2 is optional, depending on whether drive C is current. If you are logged on to drive C, C: is already the default source for the system files; therefore, you don't have to add it to the command line.

Getting the Most Speed from Your Hard Disk

Your hard disk just might be the most important component of your computer. Many aspects of your computer's performance are strongly influenced by the characteristics of your disk. These characteristics include the following:

  • Speed—. The speed of your hard disk influences the speed of your system. Even if your computer's processor is super fast, a slow disk can make your computer perform like a snail.

  • Space—. The amount of space on your disk determines what you can do with your computer. No matter how fast and powerful your processor is, if you have only 20MB of space on your disk, you cannot run much Windows software.

The most dramatic way to increase your computer's performance is to purchase a larger, faster hard disk. As an alternative to buying another hard disk, you often can increase your computer's performance simply by making the best use of your current hard disk. In the following sections, you learn how to get the most speed and most space from your hard disk. The safety issue is covered thoroughly in Chapter 9, “Protecting Your Data.”

The programs you use on your computer frequently must access data on disk. The speed at which your computer can retrieve that information is one of the most significant factors that determine how fast the computer operates. You can buy faster disk drives (which are expensive), or you can use DOS, which provides several techniques you can use to increase the speed at which your programs access information without actually increasing the speed of your disk. The following sections explain those techniques.

Using a Disk Cache (SMARTDrive)

Perhaps the most significant way to enhance the performance of your hard disk is to use a disk-caching program. Disk caching takes advantage of the fact that during the course of normal work, most users access the same programs and data repeatedly within a short period. You might list the contents of a file, edit the file, and then print it; or you might run the same program several times in a row. Even if you don't access programs or data repeatedly, the programs you use probably do.

If you have a disk-caching program installed, that program allocates some of your memory for temporary data storage on disk. When you access data, the disk-caching program saves that data in its memory area, on the assumption that you are likely to use the same data—or related data stored with it—in the near future (within a few seconds, perhaps). If you (or your program) do try to read the same data again soon, the disk-caching program intercepts the disk access and gives the program the data stored in memory. You (or your program) receive the data immediately because DOS doesn't actually read the data from disk; instead, the disk-caching program finds the data in its cache buffer. If your program never requests the same information again, the caching program eventually realizes that you are not likely to use that data soon and deletes the data from memory.

The disk-caching program that comes with DOS is named SMARTDRV.EXE, or simply SMARTDrive. SMARTDrive builds its buffer area in XMS or EMS memory, using very little conventional memory. When DOS reads information from the disk, it places that information in the cache and sends specifically requested information to the program that requested it. SMARTDrive, however, reads more information than the program requests and stores this information in memory. If the program later requests information that is already in memory, the cache can supply the information faster than DOS can if DOS has to read the disk again.

SMARTDrive eliminates redundant disk writing by putting information on disk only when the data differs from data already stored. The program also accumulates information, writing out data only when a certain amount has accumulated. Write-caching operations decrease the amount of time that your programs spend writing to disk, but write caching also forces you to shut down your computer by issuing a special SMARTDrive command (explained later in this section) or by making sure you return to the DOS prompt.

Caution

You might not want to use write caching in an area with unreliable electrical power. If the power fails while SMARTDrive is accumulating data, you lose the data that it has not yet written to disk. This risk of data loss is of little concern if you own an uninterruptible power supply (UPS), which keeps your computer running during a power failure. There is no equivalent danger in the case of read caching.

A disk-caching program such as SMARTDrive remembers which sections of the disk you have used most frequently. When the cache must be recycled, the program retains the data in the most frequently used areas and discards the data in the less frequently used areas. In a random disk-access operation in which program and data files are scattered uniformly across the disk, the cache method of recycling the least frequently used area is more efficient than the buffer method of recycling the oldest area. A cache tends to keep in memory the most heavily used areas of the disk.

To start SMARTDrive, enter a command with the following syntax in your AUTOEXEC.BAT file:

SMARTDRV drive+ | drive-... /E:elementsize initcachesize wincachesize
   /B:buffersize /C /R /F /N /L /Q /S /U /V /X

The SMARTDRV command is followed by the drives for which you want caching used. This notation takes the form of a drive letter, followed optionally by a plus (+) or minus (–) sign, as in the following examples:

C Specifies that drive C will be cached for reads but not for writes
C+ Specifies that drive C will be cached for reads and writes
C– Specifies that drive C will not be cached

If you don't specify any drive letters in your SMARTDRV command, floppy disk drives are read cached but not write cached, and hard disks are read cached and write cached. If you are using the version of SMARTDrive supplied with DOS 6.22, you also can cache your CD-ROM drives. Other kinds of drives—such as network drives and compressed drives—are not cached.

As an alternative to specifying every drive you want read cached but not write cached, you can use the /X switch. SMARTDrive then enables only read caching; write caching for all drives is automatically disabled. The /X switch is used automatically when you install DOS 6.22 (unless you were using SMARTDrive with different switches in an existing AUTOEXEC.BAT file).

The /E:elementsize parameter specifies the number of bytes that SMARTDrive reads or writes at a time: 1,024; 2,048; 4,096; or 8,192 (the default value). The larger the value, the more conventional memory SMARTDrive uses, but the fewer disk accesses you are likely to need.

The initcachesize parameter is a number that specifies the size (in kilobytes) of the cache when SMARTDrive starts. The larger the cache, the more likely that SMARTDrive can find information required by programs in the cache. The larger the cache, however, the more memory SMARTDrive requires. If you do not specify initcachesize, SMARTDrive selects a value based on the amount of memory in your system.

The wincachesize parameter specifies the size (in kilobytes) to which DOS can reduce the cache when you start Windows so that Windows can use the memory for other purposes. The philosophy behind this parameter is that if SMARTDrive uses too much of your memory, Windows runs too slowly. Therefore, even though SMARTDrive becomes less efficient by giving up some of its memory, Windows can run faster. When you exit Windows, SMARTDrive recovers the memory it gave up for Windows. Table 7.3 shows the default values for initcachesize and wincachesize.

Table 7.3. Default SMARTDrive Memory Values

Size of Extended Memory Default Value for initcachesizeDefault Value for wincachesize
Up to 1MB All XMS Zero (no caching)
Up to 2MB 1MB 256KB
Up to 4MB 1MB 512KB
Up to 6MB 2MB 1MB
6MB or more 2MB 2MB

The /B:buffersize parameter tells SMARTDrive how much additional information to read when DOS executes a disk read. Because programs often read sequentially through files, SMARTDrive anticipates that the next data request will be for the area following the current area. The default size of the read-ahead buffer is 16KB; this value can be any multiple of elementsize. The larger the value of buffersize, the more conventional memory SMARTDrive uses.

The /L switch prevents SMARTDrive from loading into your upper memory area (UMA). This option might be useful if other programs need to use the UMA.

Normally, the DOS 6.22 version of SMARTDrive enables read caching for CD-ROM drives. If you do not want this feature enabled, you can use the /U switch.

The /Q switch tells SMARTDrive to be “quiet” while installing itself rather than displaying the usual status messages. This is the opposite of the /V switch, which turns on “verbose” mode and shows the status messages.

You also can run SMARTDrive as a command from the DOS prompt. Several special switches that provide important features are available from the command line. The first is the /S switch. You determine the status of SMARTDrive by using this switch. Following is an example of typical output:

Microsoft SMARTDrive Disk Cache version 5.0
Copyright 1991,1993 Microsoft Corp.

Room for    256 elements of   8,192 bytes each
There have been   3,251 cache hits
    and    524 cache misses

Cache size:  2,097,152 bytes
Cache size while running Windows:  2,097,152 bytes

            Disk Caching Status
drive   read cache   write cache   buffering
----------------------
  A:       yes           no           no
  B:       yes           no           no
  C:       yes           yes          no
  D        yes           yes          no
  I*       yes           yes          no

* DoubleSpace drive cached via host drive.
Write behind data will be committed before command prompt returns.


For help, type "Smartdrv /?".

Perhaps the most interesting information in this output is the speed that SMARTDrive achieves. In the preceding example (which was generated after a session with a word processing program), for 3,251 disk accesses, SMARTDrive already had the data in its cache. For only 524 attempted disk accesses did SMARTDrive actually have to access the disk. In other words, because of SMARTDrive, the computer didn't have to perform 80% of attempted disk accesses.

The /C switch is important if you use write caching. Remember that write caching causes SMARTDrive to accumulate data that is destined for the disk until a certain amount accumulates. If you are getting ready to turn off your computer, you must tell SMARTDrive that no more data is to be written to disk and instruct the program to finish writing whatever data it has accumulated. You can perform this operation (called flushing in technical circles) by typing the following command:

SMARTDRV /C

You do not need to execute this command if you are rebooting by pressing Ctrl+Alt+Del. But if you have enabled write caching, be sure to use this command when you reset or turn off your computer.

If you are using DOS 6.22, the precaution of using the /C switch is not necessary. Instead, SMARTDrive automatically flushes the write buffer to disk whenever you return to the DOS prompt. This assumes, of course, that you have not disabled the feature by using the /N switch. (Typically, you should disable this feature only if you are doing extensive batch file operations and don't want the continual buffer flushing to degrade the performance of your batch files.) If you turn off this feature by using the /N switch, you can turn it on later by using the /F switch.

Using FASTOPEN

Another way to improve hard disk performance is to use the FASTOPEN program. FASTOPEN is not a device driver per se, but an executable program that you can include in AUTOEXEC.BAT. You also can load the program through CONFIG.SYS by using the special INSTALL command.

→ For more information on using the INSTALL command, seeUsing the INSTALL Command,” p. 466.

You can use FASTOPEN only with hard drives. FASTOPEN caches directory information, holding in memory the locations of frequently used files and directories.

A directory is a type of file that you cannot access through regular means. DOS reads and writes directories in a manner similar to the way it handles other files. Part of the directory entry for a file or subdirectory holds the starting point for the file in the file allocation table. Because DOS typically holds the FAT in the disk buffers, FASTOPEN was developed to hold directory entries in memory.

FASTOPEN is not a complex command, but you must do a little work before you can use it effectively. The syntax for FASTOPEN is as follows:

FASTOPEN.EXE d: = n /X

The d: parameter is the name of the first hard drive that you want FASTOPEN to track. (You can specify up to 24 hard disks or hard disk partitions at one time.) The /X switch, which is similar to the /X switches of other commands, enables FASTOPEN information to reside in EMS. By default, FASTOPEN uses conventional memory.

The n parameter is the number of directory entries that FASTOPEN is to cache. Each file or subdirectory requires one directory entry. You can enter a value ranging from 10 to 999. If you do not specify a value for n, DOS uses a default value of 48.

You can use FASTOPEN on as many disks as you want. Be aware, however, that the total number of directory entries or fragmented entries FASTOPEN can handle is 999. If you issue the command for several disk drives, the sum of the n values cannot exceed 999. The practical limit of n is between 100 and 200 per disk. If you specify a value much higher, DOS wades through the internal directory entries more slowly than it reads information from disk. Additionally, each directory entry stored in memory takes 48 bytes. Considering this trade-off of speed and memory, the 100-to-200-disk limit yields adequate performance.

Using too small a number for n also can be a disadvantage. When directory entries are recycled, FASTOPEN discards the least recently used entry when it needs space for a new entry. If the n value is too small, DOS discards entries that it still might need. The objective is to have enough entries in memory so that FASTOPEN operates efficiently, but not so many entries that FASTOPEN wastes time wading through directory entries.

To load FASTOPEN as part of your regular configuration, use the INSTALL command in your CONFIG.SYS file as follows:

INSTALL = FASTOPEN.EXE C:

To load FASTOPEN into upper memory, use LOADHIGH in AUTOEXEC.BAT. The following command, for example, loads FASTOPEN into upper memory and tracks filenames and directories on drive C:

LOADHIGH C: DOS FASTOPEN C:

Note

Keep in mind the following points regarding the use of FASTOPEN:

  • Do not use FASTOPEN if you are using Windows.

  • Do not run a disk-defragmenting program, such as DEFRAG, while FASTOPEN is running.

Using a RAM Disk

Another way to speed disk operation doesn't involve a disk at all. A RAM disk is a device driver that uses a portion of your computer's memory to emulate a disk drive. You use a RAM drive as you use any other disk drive. Because this “imitation,” or virtual, disk is located in RAM, a RAM disk is extremely fast compared with a real disk drive. You must, however, give up a significant amount of memory to create a useful RAM disk. Worse, you cannot store anything in that disk permanently; the contents of the RAM disk disappear when you turn off or reboot your computer.

As a general rule, a disk-caching program such as SMARTDrive provides better overall performance gains than a RAM disk. You generally use RAM disks to enhance the performance of one or two specific programs that read and write to the disk frequently or that use overlays. A disk cache, on the other hand, improves the performance of all programs that read and write to disk.

Tip

If your computer's memory resources are limited, give more consideration to a disk cache rather than to a RAM disk.

The RAM disk driver that comes with DOS is named RAMDRIVE.SYS. To install RAMDRIVE and create a virtual disk, include RAMDRIVE.SYS as a device driver in CONFIG.SYS. The syntax for including RAMDRIVE.SYS is as follows:

DEVICE = RAMDRIVE.SYS disksize sectorsize entries /E /A

The disksize parameter indicates the size of the RAM disk (in kilobytes). This number can range from 16 to 32,767 (equivalent to 32MB). The default value is 64.

The sectorsize parameter represents the size of the sectors used in the virtual disk. You can specify one of three sector sizes: 128, 256, or 512 (the default) bytes. Normally, you do not change this parameter; if you do, however, you also must specify the disksize parameter.

The entries parameter determines the maximum number of directory entries permitted in the RAM disk's root directory. This parameter can be a value ranging from 2 to 1,024. The default value is 64. You normally don't need to change this parameter. If you do specify the entries parameter, you also must enter the disksize and sectorsize parameters. Set the number of directories based on the size of the RAM disk and the number of files you are storing.

By default, DOS creates a RAM disk in conventional memory. You can, however, include the /E switch to cause the RAM disk to be created in XMS memory. Even with this switch, however, RAMDRIVE uses some conventional memory, so you might want to try loading the RAMDRIVE.SYS device driver into upper memory. The following command creates a 1,024KB RAM disk in XMS memory and loads the device driver into upper memory:

DEVICEHIGH=C: DOS RAMDRIVE.SYS 1024 /E

Caution

If you want your RAM disk to use extended memory, it must follow the CONFIG.SYS commands that load HIMEM.SYS or a different memory manager.

The /A switch creates the RAM disk in EMS memory. To use this switch, you must load an expanded memory manager (such as EMM386.EXE) before loading RAMDRIVE.SYS. You cannot use the /A and /E switches for the same RAM disk. You can create different RAM disks, however, some using EMS memory and others using XMS memory. Given a choice, use XMS memory.

After you insert the DEVICE=RAMDRIVE.SYS command into CONFIG.SYS and reboot your computer, DOS displays a message similar to the following during initialization of your computer:

Microsoft RAMDrive version 3.07 virtual disk D:
  Disk size: 64k
  Sector size: 512 bytes
  Allocation unit: 1 sectors
  Directory entries: 64

Most importantly, this message tells you that this RAM disk is accessed as drive D. The message also shows the disk size, sector size, allocation-unit (cluster) size, and maximum number of root directory entries.

The amount of RAM in your computer, the programs you use, and the convenience of a RAM disk help determine what size RAM disk you use and even whether you need to use a RAM disk at all.

Tip

One excellent way to use a RAM disk is to assign the TEMP environment variable to this virtual drive. Certain programs use an environment variable named TEMP to determine where to create various temporary files. These temporary files usually are written and read frequently during the operation of the program; their temporary nature makes them good candidates for storage in a RAM disk.

To assign TEMP to a RAM disk, you first have to determine a name for the virtual disk and then use the SET command (see the “Command Reference”). Assign the TEMP variable to a subdirectory rather than to the RAM disk's root directory to avoid the 64-filename limit. Assuming that the RAM disk becomes drive D, use the following commands in AUTOEXEC.BAT to create a directory on the virtual disk and to cause temporary files to be written to that directory:

MD D: TEMPDATA
SET TEMP = D: TEMPDATA

Some programs use an environment variable named TMP instead of TEMP for the same purpose. In such a case, substitute TMP for TEMP in the preceding command.

Caution

Because RAM disks are memory-based devices, you lose their contents when you reboot or turn off your PC. To prevent data loss, you must copy the contents of a RAM disk to a conventional disk file before rebooting or turning off the power. If you (or your program) are creating or modifying RAM disk files, copy the files to an actual disk regularly in case a power failure occurs.

Defragmenting Your Disk

If all you ever did with your hard disk was add files, the space available on your disk would be used very efficiently. DOS would add one file and then another to your disk, with each file being stored entirely within a contiguous area, followed by another contiguous file, an arrangement that enables DOS to access your files very efficiently.

Nobody, however, only adds new files to a disk. As you use your disk, you add new files, delete existing files, and add new data to existing files. Over time, data becomes scattered over the disk, and even the data within a single file might reside in chunks throughout the disk. This scattering of data is called fragmentation. The following sections discuss fragmentation in detail.

Understanding the Effects of Fragmentation

The more fragmented your disk, the slower your computer runs. Suppose that a third of your hard disk is currently full and that all the used space is at the front of the disk so that you have no fragmentation. Whenever you request data from the disk, the disk heads do not have to move very far and can access your data quickly.

If the same data is spread across the disk, however, the disk heads might have to move across the entire disk to access data. The longer movement requires more time, and you might notice the difference. Moreover, the disk might require more time to access each individual file. When you run a program (at least, a program that doesn't use overlays), DOS must read the program from disk into memory. That operation is much faster if the entire program is in successive locations on the disk and much slower if the disk heads must move to widely separated locations on the disk.

Fragmentation, which is almost inevitable, tends to increase the longer you use your disk. Programs that defragment your disk—that is, move all the data to the beginning of the disk and store each file's data in the same place—have long been available from third-party software vendors. The following section discusses DOS's built-in defragmentation program.

Understanding the Basic Operation of DEFRAG

DOS 6.0 was the first version of DOS to come with a defragmentation program, called DEFRAG. You execute DEFRAG by typing the following at the DOS prompt:

DEFRAG

A dialog box appears, asking which drive you want to defragment (see Figure 7.6).

The DEFRAG disk selection dialog box.

Figure 7.6. The DEFRAG disk selection dialog box.

Select a drive by clicking a drive letter. Alternatively, use the arrow keys to move to the desired drive and then press Enter. DEFRAG scans the selected drive and displays a map of the used and unused portions. You need not understand the map to use DEFRAG effectively, but if you're interested in understanding DEFRAG's analysis of your disk, study the legend at the bottom-right corner of the screen; it explains the symbols in the disk map.

After displaying the map, DEFRAG suggests one of the following courses of action:

  • Do Nothing—. If the disk is not fragmented, DEFRAG tells you that you don't need to perform any operation.

  • Defragment Files Only—. If most of the data in the used area of the disk is stored together but the individual files are scattered throughout that area, DEFRAG recommends that you defragment the files. After DEFRAG completes this operation, the same area of the disk is in use, but the data in that area is rearranged so that the data for each file is stored together. DEFRAG usually recommends this operation for disks that are mostly full.

  • Full Optimization—. If the used area of the disk is scattered across the disk, DEFRAG recommends that you perform a full optimization, meaning that you defragment the entire disk. DEFRAG rearranges the used areas on the disk so that all the used portion of the disk is at the beginning of the disk and the data for each file is stored contiguously.

Figure 7.7 shows a typical recommendation from DEFRAG.

Viewing the DEFRAG command's analysis and recommendation.

Figure 7.7. Viewing the DEFRAG command's analysis and recommendation.

If you choose Optimize, DEFRAG reorganizes your disk using the suggested method. Be prepared to wait. Although DEFRAG does its work quickly, it still might take a long time on a large, heavily fragmented disk.

When DEFRAG suggests a particular type of defragmentation, you do not have to accept its recommendation. When it recommends that only the files be defragmented, for example, it is telling you that the extra efficiency you gain by performing a disk defragmentation is not worth the time required by DEFRAG. However, you might be willing to allow DEFRAG the extra time to perform the more complete disk defragmentation.

As Figure 7.7 shows, when DEFRAG makes a recommendation, you can click Configure to select various options that control how DEFRAG works. When you click Configure, DEFRAG presents the Optimize menu, which includes more operations than just configuration; the first item tells DEFRAG to begin the defragmentation procedure. Table 7.4 lists the functions available in the Optimize menu.

Table 7.4. The DEFRAG Optimize (Configuration) Menu

Selection Meaning
Begin Optimization Begins optimization of your hard disk, using any configuration options you have selected
Drive Enables you to choose the drive you want to optimize
Optimization Method Enables you to choose full optimization or file only (might leave empty space between files)
File Sort Enables you to choose how files are sorted within directories, if at all
Map Legend Displays a legend of the symbols DEFRAG uses to show disk usage
About Defrag Displays information about the DEFRAG program
Exit Exits DEFRAG

If you want to change the type of defragmentation that DEFRAG performs, choose Optimization Method. This option presents a dialog box in which you can specify whether DEFRAG defragments only files or completely defragments the disk. After you make a selection, you can choose Begin Optimization from the Optimize menu; DEFRAG then performs the optimization you selected.

Normally, DOS doesn't store filenames in a directory in any particular order. As you create and delete files, DOS removes old names and inserts new names wherever empty space occurs. The result is that when you use DIR to list the contents of a directory, often the files appear to be listed in random order. You can overcome this disorganized appearance by using the sorting switches available with the DIR command or by using some application programs, such as WordPerfect, which sort a directory each time they display it. This is not a permanent solution, however. The directory information is still stored on disk in a disorganized manner.

While DEFRAG reorganizes your disk, you can tell it to organize the names of the files within the directories in one of five ways:

  • Unsorted—. This option, which is the default, tells DEFRAG to leave the names in their current order.

  • Name—. DEFRAG organizes the directory alphabetically by filename. This option is probably the one you will find most useful.

  • Extension—. DEFRAG organizes the directory by extension name; for example, all the COM files appear together, all the EXE files appear together, and so on.

  • Date & Time—. DEFRAG sorts the directory by the date and time the files were last modified. This option enables you to tell at a glance which files have and have not been modified recently.

  • Size—. DEFRAG organizes files by the amount of disk space they consume.

You also can specify that the sort be in ascending or descending order—that is, that values get larger or smaller as the directory listing proceeds. Usually, you want an ascending sort for names so that the list starts with the beginning of the alphabet and proceeds through the end of the alphabet. If you're sorting by size, however, you might want a descending sort so that the biggest files are listed first and the smallest files last.

You can specify how DEFRAG sorts directories from the DEFRAG Optimize menu by choosing File Sort. Figure 7.8 shows the File Sort menu. Alternatively, you can provide command-line arguments, discussed in the next section, to specify file sort type.

The DEFRAG File Sort menu.

Figure 7.8. The DEFRAG File Sort menu.

When you use DEFRAG, you usually start it simply by typing DEFRAG. Like most DOS commands, however, DEFRAG has a number of startup options available. The complete syntax for DEFRAG is as follows:

DEFRAG d: /F /U /S:order /B /SKIPHIGH /LCD /BW /G0 /H

Normally, DEFRAG asks which drive you want to defragment. If you specify the d: parameter, DEFRAG uses it as the drive you want to defragment.

Typically, DEFRAG recommends the type of defragmentation you need to perform. The /F parameter tells DEFRAG to defragment the disk (leaving no empty spaces between files); the /U parameter tells DEFRAG to defragment files (possibly leaving empty space between files). If you specify one of these parameters, DEFRAG does not make a recommendation, but it immediately carries out the type of defragmentation you specify.

You can control whether DEFRAG sorts directory entries by using the /S switch. /S is optionally followed by a colon and one or more characters that specify how you want the entries sorted within each directory. Valid letters are listed in the following:

N Alphabetical order by name
E Alphabetical order by extension
D By date and time, with the oldest dates (that is, files that were last modified farthest in the past) listed first
S By size, with the smallest files listed first

The following command, for example, defragments drive C and sorts files in alphabetical order by name:

DEFRAG C: /SN

You also can place a minus sign (–) after a sort letter to specify a descending sort instead of ascending. Consider these two commands:

DEFRAG C: /SS

DEFRAG C: /SS-

The first (without the minus sign) lists the smallest files first; the second (with the minus sign) lists the largest files first.

The /B switch tells DEFRAG to reboot your computer after the defragmentation process is complete.

The /SKIPHIGH switch tells DEFRAG to load itself into conventional memory. Otherwise, DEFRAG uses upper memory, if available.

The /LCD switch uses a color scheme that is likely to be more readable if you are using a laptop or notebook computer with an LCD screen.

The /BW switch tells DEFRAG to use a black-and-white color scheme, which is likely to be more pleasing if you have a monochrome monitor.

The /G0 switch disables the mouse and graphics character set. Use this switch if DEFRAG displays strange characters on your monitor.

Normally, DEFRAG does not reorganize hidden files. You can use the /H switch to tell DEFRAG to move hidden files.

Note

When you use DEFRAG, keep in mind the following restrictions:

  • You cannot use DEFRAG to defragment drives over a network.

  • You cannot run DEFRAG from Windows.

  • Disk statistics reported by DEFRAG and CHKDSK or SCANDISK differ slightly. When listing the number of directories, for example, DEFRAG counts the root directory, but CHKDSK does not.

Getting the Most Space from Your Hard Disk

Since the introduction of PCs in 1981, the amount of disk storage space available to the average user has increased steadily. The original PCs used cassette tapes for mass storage and offered, as an option, floppy disks with only 160KB of storage space. Today, many PCs are sold with hard disks that are thousands of times larger, usually 10GB and higher. It is important to discuss other options, though, because many older PCs that are still running are quite capable of running DOS, but they have only 100MB to 500MB hard drives. Upgrading these machines is not cost effective, so other ways to increase space are needed.

A decade ago, few software vendors wrote software that required several megabytes of disk storage because they knew that few of their potential customers' systems had that kind of storage capability. Now vendors rarely think twice about releasing software that requires more than 40MB of disk storage; they expect that most people have that much space to spare. Some newer programs, especially games, can require up to 400MB of space to load completely.

Although you cannot increase the physical capacity of your disk without buying a larger disk, you might be able to increase the amount of data you can store on your disk by using the techniques discussed in the next couple of sections. First, you learn about manual methods of freeing disk space; then you learn about DoubleSpace, which provides full-time disk compression.

The two most popular methods of freeing disk space are to delete files you no longer need and to compress computer files. You also can archive files that you no longer need on floppy disks or tape backups.

Deleting Unnecessary Files

Much of the software available today is very complex, offering many features that you probably will never use. As a result, many of the files copied to your hard disk when you install a software program are files that you never open. You might be able to find and delete some of these files, thereby freeing some of your hard disk space.

Tip

Some programs, such as Microsoft Word for Windows, ask which features you expect to use and install only the files that are appropriate for you. If you later change your mind, you can install the missing pieces then.

Caution

Be sure to use the installation routine for programs such as Word to remove files. Never delete program files directly, unless you are sure there will be no adverse harm to the program.

When you install DOS, dozens of programs are installed on your hard disk. If you are short on disk space, you might want to browse through these programs and delete the ones that are not important to you. Consider the following examples:

  • DOS includes many files that enable it to work with foreign-language character sets, including German, Swedish, and French. If you expect to use your computer only in the United States, you can delete these files to free disk space.

  • Some DOS utilities might duplicate functions that are available in other programs installed in your system. If you use a backup program (such as Norton Backup or FastBack), for example, you can delete the DOS backup program, MSBACKUP.

→ To determine which files supplied with DOS you can safely remove, see Appendix F,“Command Reference,” p. 583.

Another side effect of upgrading your version of DOS is that the old DOS files (from the previous version) are stored in a directory that begins with the letters OLD_DOS. After the upgrade is complete and you are sure that you want to continue using the new version of DOS, you can safely delete this directory and everything within it. The program DELOLDDOS, provided with DOS, can take care of this deletion for you.

Using File Compression

If you examine the file that contains the text for this chapter, you find that many words—such as DOS and the—are repeated frequently. Most data includes such repetition—patterns that occur over and over within a file, whether the file contains text, customer data, or machine instructions.

Many programmers have written programs that analyze these patterns and squeeze a file's data into a smaller space by converting the data into a kind of shorthand notation. (PKZip and LHArc are examples of such programs.) This process is known as compression. In special cases, the compressed data might require as little as 10% of the original space, although 50% is more typical.

If you are interested in acquiring a good compression program, check out an online download site, such as http://www.downloads.com or http://www.zdnet.com. File compression software is used extensively in telecommunications because the smaller files transfer faster and with less cost.

Archiving Files

Over time, you probably use your computer to perform many different tasks and complete a multitude of projects. When you complete a project, a good plan of action is to compress the files using compression software discussed in the preceding section.

You can move compressed files easily to high-density floppy disks or to a backup tape. You then can store these disks or tapes for long periods of time in case you need the information again.

Take a look at your hard drive and the dates of the data files contained on it. You might find that you have many files that you have not accessed for a long time. Such files are prime candidates for archiving.

Projects

The following two projects will walk you through using the CHKDSK and SCANDISK utilities. These utilities are very important in analyzing hard drives and determining whether there might be a problem. CHKDSK can be used on uncompressed drives, whereas SCANDISK is required to check compressed drives.

Analyzing a Disk with CHKDSK

The external command CHKDSK analyzes a floppy or hard disk. CHKDSK checks a disk's FAT, directories, and—if you want—the fragmentation of the files on the disk.

CHKDSK is DOS's self-test command. It makes sure that the internal tables that keep files in control are in order.

Although the technical details of how CHKDSK performs its analysis are beyond the interest of most casual DOS users, the better you understand CHKDSK, the more comfortable you will be when the command uncovers problems. Just because you don't understand exactly how CHKDSK works doesn't mean that you must avoid using it.

CHKDSK checks for the following problems in the FAT:

  • Unlinked cluster chains (lost clusters)

  • Multiply linked clusters (cross-linked files)

  • Invalid next-cluster-in-chain values (invalid cluster numbers)

  • Defective sectors where the FAT is stored

CHKDSK checks for the following problems in the directory system:

  • Invalid cluster numbers (out of range)

  • Invalid file attributes in entries (attribute values that DOS does not recognize)

  • Damage to subdirectory entries (CHKDSK cannot process them)

  • Damage to a directory's integrity (its files cannot be accessed)

Note

CHKDSK is meant to work with normal DOS volumes; it does not work with DoubleSpace disk volumes. If you want to analyze both DOS and DoubleSpace volumes, use the SCANDISK command, which is discussed later in this chapter.

Optionally, CHKDSK repairs problems in the FAT that are caused by lost clusters, and it writes the contents of the lost clusters to files. CHKDSK also can display all files and their paths. (Paths are discussed in Chapter 5, “Understanding Files and Directories.”)

Note

Running CHKDSK periodically on your hard disk and on important floppies is good practice. Because the FAT and hierarchical directory system work together to track filenames and locations, a problem in the FAT or one of the directories is always serious. In all likelihood, CHKDSK can find and correct most problems in a disk's internal bookkeeping tables.

The CHKDSK command uses the following syntax:

CHKDSK filespec /F/V

The optional filespec parameter is the drive, path, and filename of the file to be analyzed for fragmentation. If you don't include a filespec, CHKDSK does not check for fragmentation.

/F is the optional fix switch, which instructs CHKDSK to repair any problems it encounters.

/V is the verbose switch, which instructs CHKDSK to provide filenames onscreen as it analyzes the files.

When the process is complete, CHKDSK displays a screen report of its findings. This report summarizes disk and system memory usage. Figures 7.9 and 7.10 show typical CHKDSK reports.

A typical report produced by CHKDSK with no parameters.

Figure 7.9. A typical report produced by CHKDSK with no parameters.

The report produced when CHKDSK is issued with a path.

Figure 7.10. The report produced when CHKDSK is issued with a path.

Note

Take advantage of the CHKDSK command's capability to make a “dry run” of its checking routines. You can use this feature to assess reported problems. Before issuing CHKDSK with the /F switch, for example, issue the command without the switch. CHKDSK without /F prompts you if the command finds a problem (as though you had used the /F switch). After you have assessed the findings of CHKDSK and have taken remedial actions, you can issue CHKDSK with the /F switch so that the command can fix the problems it finds.

DOS stores every file as a chain of clusters. Each cluster is a group of sectors; clusters are also referred to as allocation units. Each entry in the disk's directory points to the entry in the FAT that contains the list of clusters allocated to a file.

Caution

Use CHKDSK /F only when you are running at the DOS prompt. You do not want to have other programs running because CHKDSK expects the DOS file system to be dormant while CHKDSK does its work. If you are shelled out to a DOS prompt from within an application or are running a DOS session under Windows, CHKDSK can damage your files.

CHKDSK processes each directory, starting at the root and following each subdirectory. It checks the cluster chain by using the directory entry's FAT pointer and then compares the size of the file (in bytes) with the size of the FAT's allocation (in clusters). CHKDSK expects to find enough chained clusters in the FAT to accommodate the file, but not more than are necessary. If CHKDSK finds too many clusters, it displays the following message:

Allocation error,
size adjusted

The file is truncated—excess clusters are deallocated—if you use the /F switch.

CHKDSK makes sure that each of the FAT's clusters is allocated only once. In rare circumstances—for example, if power problems or hardware failures occur—DOS can give the same cluster to two different files. By checking each cluster chain for cross-linked files, CHKDSK can report mixed-up files. Each time you see that the message filename is cross-linked on cluster nnnnn, copy the file reported in filename to another disk. When CHKDSK reports another file with the same message, copy the second file to another disk also. Chances are that the contents of the two files are mixed up, but you have a better chance of recovering the files if you save them to another disk before CHKDSK “fixes” the problem.

CHKDSK expects every cluster in the FAT to be available for allocation, part of a legitimate directory-based cluster chain, or a marked bad cluster. If CHKDSK encounters any clusters or cluster chains that are not pointed to by a directory entry, CHKDSK issues the message lost clusters in XXX chains. CHKDSK then asks the following:

Convert lost chains to files (Y/N)?

This message appears even if you didn't use the /F switch.

If you used the /F switch and you press Y, CHKDSK turns each cluster chain into a file in the root directory. Each file that is created has the name FILEnnnn.CHK. (nnnn is a number, starting with 0000, that increments by 1 for each file created by CHKDSK.) If you did not use the /F switch and you press Y, nothing happens. CHKDSK, however, does tell you what it would have done had you used the /F switch.

Note

You can use the TYPE command to examine the contents of a text file, and you might be able to use the DOS EDIT command to put the text back into its original file. The TYPE or EDIT commands don't do you any good, however, for a binary (program or data) file. If the problem is with a program file, you might have to use the DOS COMP or FC command to compare your disk's binary files with their counterparts from your master disks.

Of course, the disk does not physically lose any sectors. A lost cluster report does not indicate that the clusters are bad; lost clusters indicate only that DOS made a bookkeeping error in the FAT, which makes some clusters appear to DOS to be lost. The clusters are not tied to a directory entry, but they're marked as being in use.

The lost cluster problem is most likely to occur when a program you are running crashes because of an error while files are being manipulated.

Remember that CHKDSK reports problems found during operation, but it does not repair the problems unless you include the /F switch in the command line. Running CHKDSK at least once a week is a good idea. Run CHKDSK daily during periods of extreme file activity.

Analyzing a Disk with the SCANDISK Utility

You might already know a bit about DoubleSpace, which was introduced with DOS 6.0. DoubleSpace enables you to virtually double the amount of information that can be stored on your disk. To accomplish this compression, however, information must be stored in a nonstandard manner. This means that CHKDSK cannot provide correct information about a disk volume that uses DoubleSpace.

Beginning with DOS 6.2, however, there is a solution: the SCANDISK command. This command works with either regular or DoubleSpace disk volumes, and it provides greater functionality than did the older CHKDSK command. In fact, whenever you use CHKDSK, you see this message at the bottom of any display:

Instead of using CHKDSK, try using SCANDISK.  SCANDISK can reliably detect
and fix a much wider range of disk problems.  For more information, type
HELP SCANDISK from the command prompt.

SCANDISK can detect and resolve all the problems that can be handled by CHKDSK. In addition, it can detect and correct the following problems:

  • MS-DOS boot sector errors

  • Defective clusters

  • Problems in a DoubleSpace volume header

  • Structure problems in the file structures of a DoubleSpace volume

  • Errors in the DoubleSpace compression structure

  • Errors in DoubleSpace volume signatures

The SCANDISK command has two possible syntaxes. If you want it to check a file or group of files, use the following syntax:

SCANDISK /FRAGMENT filespec

If you want SCANDISK to analyze an entire drive, use the following syntax:

SCANDISK switches d:

In this syntax, d: is the drive you want to check; if you do not supply a drive, SCANDISK assumes that you want to check the current drive. Many more switches can be used with SCANDISK than with CHKDSK. These switches are detailed in Table 7.5.

Table 7.5. Possible Switches for Use with SCANDISK

Switch Meaning
/ALL Checks all local drives.
/AUTOFIX Fixes any problems that are encountered without asking first.
/CHECKONLY Analyzes the disk but does not fix any problems.
/CUSTOM Uses the SCANDISK settings contained in the file SCANDISK.INI.
/FRAGMENT Checks a file for fragmentation. You must specify the full filename after the switch.
/MONO Forces display settings for a monochrome monitor.
/NOSAVE Doesn't save lost cluster chains into files; simply frees them (used only with /AUTOFIX).
/NOSUMMARY Indicates that SCANDISK should not stop at summary screens (used only with /AUTOFIX or /CHECKONLY).
/SURFACE Performs a surface scan.
/UNDO Undoes previous repairs. You must have an undo disk, and you must specify the drive on the command line.

Caution

Use SCANDISK only at the DOS prompt. SCANDISK does not work properly if you are operating under a multitasking shell such as DESQview, Windows, or the DOS Shell. Exit these programs before you attempt to use SCANDISK.

You might have already noted, from the information in Table 7.5, that you can store your SCANDISK parameters in the file SCANDISK.INI. This file, which is stored in the DOS directory, specifies how you want SCANDISK to operate. For more information on this file, use a text editor to load the file. It contains extensive comments on how you can modify the file to change the behavior of SCANDISK.

As an example of how SCANDISK operates, enter SCANDISK at the DOS prompt. You see a screen similar to the one shown in Figure 7.11.

The SCANDISK screen.

Figure 7.11. The SCANDISK screen.

Each of the five listed areas is in turn analyzed by SCANDISK. The first four areas are processed very quickly. The final area takes more time; therefore, you are prompted before SCANDISK actually performs a surface test. On a 340MB hard drive, for example, a surface scan can take up to 35 minutes to complete. This amount of time is necessary because every sector on the disk is read and analyzed to make sure that it is correct.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.79.206