January 28, 2015
Posted by ovidiu at January 28, 2015 01:52 PM
MacOS X Yosemite: How to mount a disk on startup
MacOS X Yosemite removed few capabilities that existed in previous versions of MacOS X. Notably the
StartupItems feature which allowed you to run scripts when the system boots up.
On my machine I want to be able to mount an internal disk as soon as the machine boots up, but before a user logs in. A common solution in the past involved a custom
StartupItems script, but this no longer works on Yosemite.
To solve this problem I created a
LaunchDaemons script. My disk's volume name is
BigDisk and is accessible via
/dev/disk0s2. To mount it on startup I created a file named
/System/Library/LaunchDaemons with the following content:
<?xml version="1.0" encoding="UTF-8"?>
When the machine starts up,
launchd will load the file since we have the
RunAtLoad set to
true. It then finds that
/Volumes/BigDisk does not exist, since the disk is not yet mounted, so it executes the
diskutil command to mount the directory.