auto mount HFS+ filesystem from disk image (.dmg file)
You can simply add the .dmg file to your Login Items in: System Preferences > Users &amp; Groups > (you) > Login Items

The .dmg file will then automatically be mounted when you login.



Update to address comment: "Is there any API to add item to login items programmatically?"

One programatic way I know of, it can be done with AppleScript:

Example AppleScript code:

tell application "System Events" to ¬
    make new login item with properties ¬
        {name:"Mount DMG", path:"/path/to/filename.dmg", hidden:true}



Change "Mount DMG" and "/path/to/filename.dmg" as appropriate.


It can also be done from Terminal using, using the osascript command, with the same AppleScript command:

osascript -e 'tell application "System Events" to make new login item with properties {name:"Mount DMG", path:"/path/to/filename.dmg", hidden:true}'



Change "Mount DMG" and "/path/to/filename.dmg" as appropriate.