Defragment a Disk on a Windows Computer

When your computer writes data into a file on your hard drive, it's not always able to place all of the data together. A section of a file might be written near the beginning of the disc, the rest of that file could be written near the end. This causes programs to run slowly, as the computer spends time retrieving the file fragments from all over the disk.

Defragmenting your disk volume arranges files (and free space) in an orderly manner, reducing the time taken to read a file.[1] There are various tools available to defragment the computer, and one version is included with MS Windows. Here are some methods for defragmenting your Windows computer.

Steps

  1. Note things that you don't need to do. Some older advice may still be in your mind when you set out to defragment; this list shows what you don't need to be concerned about:
    • It used to be recommended to open Windows in "Safe Mode". This is not necessary now.
    • It's not necessary to remove programs you don't use or need. However, as a general housekeeping rule, it's always a good idea to discard what you don't use.
    • You don't need to close all unnecessary programs or cancel any programs scheduled to run.
    • You don't need to delete any temporary files.
  2. If Windows recommends that you defragment your drive, simply follow its prompt and click on "Defragment Disk". Easy!

Windows details

  1. Note that different versions of MS Windows display different levels of detail of the before and after usage of the volume. This table sets out the meanings of the colored areas:
xxx   BLUE areas are sections where the files and directories are contiguous and adjacent.
  WHITE areas are unused.
  RED areas contain pieces (fragments) of files which need to be collected and placed in a location with enough unused space so the resultant file is in one (or as few as possible) pieces.

Windows 7

  1. Note that Windows 7's Defragment feature runs automatically but if you want to control it manually, follow the next steps.
  2. Open the Control Panel.
  3. Open "System and Security".
  4. Click on "Defragment Your Hard Drive".
  5. Select a drive to analyze. For example, the "C:" drive.
  6. Click "Analyze Disk".
    • Note that the time it takes to do the defragmentation is dependent on the size of the volume and the amount of fragmentation (red).
    • While you can continue working while the defragmentation tool is running, the system response will often be very slow. Consider starting up a defrag before you retire for the evening and letting it run overnight.
    • If you need to do work once the defragmentation has begun and you cannot tolerate the poor performance, pause or stop the defragmentation tool. If you stop files that have been defragmented as still consolidated. The advantage of pause is that the tool will continue where it left off when it resumes.
  7. Change the defragmentation schedule as follows. If you want to control the day of the week used for defragmentation, do the following:
    • Click "Configure Schedule".
    • Open the day menu.
    • Select "Day (e.g., Sunday)".
    • Click "OK".
    • Click "Close".

Other Windows

  1. Click "My Computer" on Desktop. Right click on the drive to defrag, for example, "C:" and click on properties and driver properties (dialogue box will appear.)
  2. In driver properties box, Click on the "Tools" tab.
  3. Click on "Defragment Now".

Running again

  1. Consider running again. Re-running the defragmentation tool a second time on the same volume can be helpful as the first run should have resulted in unused space being left in larger chunks than prior to defragging. Running again permits file fragments that were unable to be collected and placed contiguously during the first run to be optimized in the next run.
  2. Check the report. After the tool completes, display the report. The important thing to check are files with many (more than 20) fragments that you use. It doesn't help to defragment files that you never access!
  3. Defragment individual files. If the report shows a file with many fragments (that you use), there is a free tool to make a single file (or files that match a pattern) contiguous, available at http://technet.microsoft.com/en-us/sysinternals/bb897428.aspx. This is a command line utility started from the "Run" or "Command Line" button of the "Start" menu.

From the command line

  1. Run the Disk Defragmenter Program.
  2. Go to "Start", then "Run". Enter "dfrg.msc" in the window. Alternatively, launch it by going to "Start", "Programs" (or "All Programs"), "Accessories", "System Tools", "Disk Defragmenter". A window similar to the one on the right should appear.
  3. Click "Analyze" so you can see what the damage is, and then look at the report. If you want to continue: Make sure that your desired drive is selected ("C:" being the default drive), and click on the Defragment button.
  4. Wait until the process is complete. Sit back and relax as your computer organizes your fragmented files.

Batch Method

Although using batch files to defrag your computer, some actually prefer to see words filled with info than something filled with color.

  1. Make a new txt application. On windows you will edit the txt document with Notepad on default.
  2. Type the code as mentioned below:.
    • Type in "defrag" because you are obviously going to defrag a disk.
    • Type in the drive letter or mount point that you wish to defragment. For example: "defrag c:".
    • Type in parameter "-v" if you want to see extra data.
    • Type in "-a" if you just want the data. Note: -a -v will print out a more detailed data.
  3. Save the file. Rename your file so that the extension is .bat. Your file is now a batch file. Next, click on it.
  4. Wait. It could take anywhere from ten minutes to several hours to defragment a hard disk, depending on the size of the disk, number of files, and how many files are fragmented.

Apple Mac OS X

  1. Relax, you don't need to bother. The BSD core of OS X defragments files on the fly so no defragment process is necessary. The HPFS+ files system does this when a file is read which is fragmented. The file is written back to an alternate area on the volume.


Tips

  • Defragment your disk overnight. If you have not defragmented a volume before, or have accumulated many files since the last time you did, the process will take several hours.
  • The more often that you run the defragmenter, the quicker the process will be.
  • If you can go with a paid software option, "DISKEEPER" is a perfect tool to defragment your hard disks.
  • In really old Windows computers, if the Defragmenter keeps restarting, and you have not already run your computer in Safe Mode, do so.
  • Group files into separate volumes, keeping "your" data on a different volume. This cannot be stressed enough. One of the biggest problems with fragmentation is the web browser which continuously adds and deletes files. Keeping the browser cache on a separate volume prevents it from poisoning the other file areas as well as keeping these files near each other. See volumes.
  • Most Linux file systems are designed to keep fragmentation at minimal and do not need to be defragmented as often.[2] Approach and defragmenters by file system type ext2, ext3, and ext4 .
  • Remember that defragmenting takes the saved portions of all of your files and organizes them to help your computer run more efficiently. Some files (such as system files and boot procedure files) cannot be moved.
  • Perfect Disk and O&O) claim to do a better job.
  • The tool provided with the Operating System does a reasonable job. It does not prioritize file placement according to usage. Commercial Defragmenters (such as Diskeeper

Warnings

  • This process impacts other users sharing your disk volumes.
  • Do not defragment a solid state drive (SSD). They do not need to be defragmented, and defragmenting them will only wear them out faster. Instead, use a TRIM command which has its own purpose.

Related Articles

Sources and Citations

  1. For a more detailed explanation see Wikipedia, https://en.wikipedia.org/wiki/Defragmentation.
  2. Wikipedia, Defragmentation, https://en.wikipedia.org/wiki/Defragmentation