If you need to defragment your drive, then the safest and fastest way to do so is:
1. Get an empty external hard drive and clone your internal drive to the external one.
2. Boot from the external hard drive.
3. Erase the internal hard drive.
4. Restore the external clone to the internal hard drive.
Clone the internal drive to the external drive
1. Open Disk Utility from the Utilities folder.
2. Select the destination volume from the left side list.
3. Click on the Restore tab in the DU main window.
4. Check the box labeled Erase destination.
5. Select the destination volume from the left side list and drag it to the Destination entry field.
6. Select the source volume from the left side list and drag it to the Source entry field.
7. Double-check you got it right, then click on the Restore button.
Destination means the external backup drive. Source means the internal startup drive.
Restart the computer and after the chime press and hold down the OPTION key until the boot manager appears. Select the icon for the external drive and click on the downward pointing arrow button.
After startup do the following:
Erase internal hard drive
1. Open Disk Utility in your Utilities folder.
2. After DU loads select your internal hard drive (this is the entry with the mfgr.'s ID and size) from the left side list. Note the SMART status of the drive in DU's status area. If it does not say "Verified" then the drive is failing or has failed and will need replacing. SMART info will not be reported on external drives. Otherwise, click on the Partition tab in the DU main window.
3. Under the Volume Scheme heading set the number of partitions from the drop down menu to one. Set the format type to Mac OS Extended (Journaled.) Click on the Options button, set the partition scheme to GUID then click on the OK button. Click on the Partition button and wait until the process has completed. Do not quit Disk Utility.
Restore the clone to the internal hard drive
1. Select the destination volume from the left side list.
2. Click on the Restore tab in the DU main window.
3. Check the box labeled Erase destination.
4. Select the destination volume from the left side list and drag it to the Destination entry field.
5. Select the source volume from the left side list and drag it to the Source entry field.
6. Double-check you got it right, then click on the Restore button.
Destination means the internal hard drive. Source means the external startup drive.
Note that the Source and Destination drives are swapped for this last procedure.
Alternatives to the above are using one various defragmentation utilities such as iDefragment or Drive Genius. But these utilities have to move data around on the drive resulting in slower times plus the greater risk of file corruption or disk directory corruption. The above method gives the same result - a fully defragmented drive plus a backup to boot.