AnalogKid

Q: auto mount disk image on boot

If I have a disk image on a direct attached drive, is there a way to get the system to mount it automatically on boot (as opposed to on a user login)?  Can I do it if the image is encrypted?

 

I'm trying to talk TimeMachine Server into backing up to an encrypted sparse disk image rather than consume a whole disk.

Mac mini (Mid 2011), OS X Server

Posted on Dec 3, 2013 9:25 PM

Close

Q: auto mount disk image on boot

  • All replies
  • Helpful answers

  • by Tony T1,Helpful

    Tony T1 Tony T1 Dec 4, 2013 6:16 AM in response to AnalogKid
    Level 6 (9,232 points)
    Mac OS X
    Dec 4, 2013 6:16 AM in response to AnalogKid

    You can use this Applescript

     

    tell application "Finder" to mount volume "afp://Mac-mini.local/Tony"
    do shell script "hdiutil attach -mountpoint /Volumes/Documents/ /Volumes/Tony/Documents/Documents.sparsebundle"
    

     

    and put it in ->System Preferences->Users & Account->[Login Items]

    To launch at boot, use a Launch Agent.  The easy way to do this is to use Lingon

     

    If the image is encrypted, you will be prompted to enter a password

  • by etresoft,Helpful

    etresoft etresoft Dec 4, 2013 7:13 AM in response to AnalogKid
    Level 7 (29,051 points)
    Dec 4, 2013 7:13 AM in response to AnalogKid

    Try playing around with some of the advanced, script-baed mount options in Autofs: http://images.apple.com/business/docs/Autofs.pdf

     

    I can't guarantee it will work (and it probably won't) but it may be your best shot.

  • by twtwtw,Solvedanswer

    twtwtw twtwtw Dec 4, 2013 9:10 AM in response to AnalogKid
    Level 5 (4,935 points)
    Dec 4, 2013 9:10 AM in response to AnalogKid

    You can use a launchdaemon. Save the following file (with proper revisions) in /Library/LaunchDaemons:

     

    <?xml version="1.0" encoding="UTF-8"?>

    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

    <plist version="1.0">

    <dict>

              <key>RunAtLoad</key>

              <true/>

              <key>Label</key>

              <string>system.dmg.mount</string>

              <key>ProgramArguments</key>

              <array>

                        <string>hdiutil</string>

                        <string>-attach</string>

                        <string>/Path/to/dmg file/.dmg</string>

              </array>

    </dict>

    </plist>

     

    working with an encryoted diskimage will need some modifications that I haven't worked through - I'm not sure how Time Machine encrypts things.

     

    I will give the obligatory "I told you so" warning. Trying to coerce Time Machine into doing something that Time Machine isn't set up to do is almost certainly going to send you into migraine territory. Disk space is cheap and you only have one brain; no sense wasting the latter trying to save the former.

  • by AnalogKid,

    AnalogKid AnalogKid Dec 4, 2013 11:45 PM in response to twtwtw
    Level 1 (10 points)
    Dec 4, 2013 11:45 PM in response to twtwtw

    Thanks, that did it.  I think the Applescript solution would have worked to (I didn't try it) but this was cleaner.  Still used Lingon though.  Very happy to see Lingon back to it's former glory.

     

    I also added a "StartInterval" key so that if the drive gets detached, it will reattach.  (launchd supports a "Disabled" key that makes it easy to turn the daemon off, otherwise remounting every 5min would make maintenance a pain).

     

    I gave up on encryption.  hdiutil supports a -stdinpass keyword that should take the password from stdin, which you can pipe out of the keychain using 'security' from the command line, but it dawned on me that the encryption isn't doing much good if I'm automounting the drive continuously.

     

    Eventually I'll create another launch daemon to compact the sparse image on some sort of schedule.

     

    I appreciate the warning on messing with TimeMachine.  I'm trying to use a Drobo for backups and this seemed like a clean way of controlling TimeMachine's growth.  My understanding is that TimeCapsule uses disk images, so hopefully it's supported.