/diskejectd

OS X launch daemon ejecting user specified disks

Primary LanguageC

diskejectd

If your Mac OS X box has volumes that OS X does not recognise, e.g. Linux volumes partitioned with ext4, you will be bugged with a popup stating "The disk you inserted was not readable by this computer" on every boot.

Unfortunately, OS X doesn't read volume names of some (all?) ext4 volumes, nor does it recognise their UUIDs, which makes it impossible to use /etc/fstab to block the volumes.

This Launch Daemon resolves the problem by blocking disks by their disk name. Disk names have to be specified in <ProgramArguments> of com.diskejectd.plist. It helps you to block/get rid of "the disk you inserted was not readable by this computer" error message in Mac OS X.

Based on original code published at: superuser.com

UPDATE:

Note that this method might work more consistantly rather than using this diskjectd launch daemon:

1) Make sure the disk you want to prevent mounting at boot is mounted.

2) Launch Terminal.

3) Run the following command to print out information about the disk:

     diskutil info /Volumes/<volume that shouldn't be mounted>

4) Locate the line that starts with: Volume UUID:. Select the UUID (Universal Unique Identifier) that follows on the rest of the line. It will be something that looks like FF9DBDC4-F77F-3F72-A6C2-26676F39B7CE. Your value will be different

5) Copy the UUID to the clipboard.

6) Navigate to /etc by typing the following and pressing enter:

     cd /etc

7) Edit (or create) an fstab file by typing the following and pressing enter:

     sudo vifs

8) Enter the following line, substituting the UUID you copied in step 5). (Note: vifs uses the value of the EDITOR environment variable to pick the text editor to use. This article assumes you are using the default value of vim.) In vim, the editor starts in command mode. To add a new line, use the arrow keys to move to the end of the document and press the o key to append a new line and enter edit mode. Then type the following:

    UUID=FF9DBDC4-F77F-3F72-A6C2-26676F39B7CE none hfs rw,noauto

and press the return key.

9) Type escape to return to command mode and then type ZZ (shift key down) to save and exit vifs (or some other method to save and exit if you are using something other than vim).

10) Type the following and press enter to reset the auto mounter:

     sudo automount -vc

11) Quit Terminal

Installation

  1. Get the BSD Disk Name of the disk you want to block with diskutil list, e.g. disk2s2.
  2. Put disk names you want to block in <ProgramArguments> of com.diskejectd.plist. You can put as many disks in there as you like. Here's an example for blocking two disks:
<key>ProgramArguments</key>
<array>
    <string>/usr/local/sbin/diskejectd</string>
    <string>disk2s1</string>
    <string>disk2s2</string>
</array>

Finally, compile and install:

  1. make
  2. sudo make install
  3. sudo make start

Removal

  1. sudo make stop
  2. sudo make uninstall

License

Copyright (c) 2012 Adam Strzelecki

Copyright (c) 2014 Andre Richter

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.