How do I programmatically mount an APFS encrypted device?

How do I programmatically mount an APFS encrypted device?

If it is a normal device, Can be mounted using DADiskMount of Disk Arbitration Framework.

However, in the case of APFS encryption, it will not be mounted even if DADiskMount is used in the same way.

I think it requires a password to mount.

Please tell me if there is a way to programmatically mount the APFS encrypted device.

The language I'm currently using is Objective-C.

Your best option here is to user the "diskutil" command line tool (see man page for more details). Note that you can use diskutil to unlock the volume without mounting, at which point I believe you can then DADiskMount to complete the mount.

-Kevin Elliott

DTS Engineer, CoreOS/Hardware

You use diskutil apfs unlockVolume or decryptVolume, right?

Thank you very much.

A password is required to unlock, I don't want to have a password in advance in the program, so I would like to take a method to have the user input when unlocking.

Just like when mounting with Disk Utility

  • Display a screen that asks the user to enter the password
  • Use what is registered in the keychain

Is there a way to do that?

For keychains, use -recoverykeychain, but I'm in trouble because I don't know what to specify in the parameter file.

How do I programmatically mount an APFS encrypted device?
 
 
Q