How to auto-run disk repair on OS X after each system crash? How to auto-run disk repair on OS X 10.8+ after each system crash?

Note: I am not looking for a manual solution.
I don't know if OS X already performs some extra checks after hard shutdowns or kernel panics. The verbose startup output looked the same after a normal restart, a hard restart, and a kernel panic:



The OS X volume is verified when starting up in safe mode:



Do you mean repairing the drive, repairing the main OS X volume, or running fsck? http://support.apple.com/kb/ts1417 recommends first starting up in safe mode (which includes repairing the OS X volume), or if that doesn't work, repairing the drive or OS X volume from Disk Utility on the recovery partition. It says that you don't normally need to run fsck with journaled HFS+ volumes.

From the diskutil man page:

repairDisk device
           Repair the partition map layout of a whole disk intended for
           booting or data use on a Macintosh.  The repairs further
           include, but are not limited to, the repair or creation of
           an EFI System Partition, the integrity of any Core Storage
           Physical Volume partitions, and the provisioning of space
           for boot loaders.  Ownership of the affected disk is
           required; it must be a whole disk and must have a partition
           map.

[...]

repairVolume device
           Repair the file system data structures of a volume.  The
           appropriate fsck program is executed and the volume is left
           mounted or unmounted at it was before the command.  Owner-
           ship of the affected disk is required.


You could try saving this as ~/Library/LaunchDaemons/repairdisk.plist, but I don't know how to run it only after unclean reboots (or why it would be needed).

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;repairdisk&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
        &lt;string&gt;bash&lt;/string&gt;
        &lt;string&gt;-c&lt;/string&gt;
        &lt;string&gt;yes | diskutil repairDisk /dev/disk0&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;RunAtLoad&lt;/key&gt;
    &lt;true/&gt;
&lt;/dict&gt;
&lt;/plist&gt;


See diskutil list or df -h for the identifier of the drive.

diskutil repairDisk /dev/disk0 showed a warning like Repairing the partition map might erase disk0s1, proceed? (y/N), where disk0s1 is the EFI partition. But it seemed to do the same operations as repairing the drive from Disk Utility. repairVolume can't be used with the OS X volume after you have started up from it.