Create a APFS DMG using Apple's Disk Utility application and call it test_apfs.dmg.
One can mount it with:
hdiutil attach -plist ~/Desktop/test_apfs.dmg
which provides the following output:
<?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>system-entities</key>
<array>
<dict>
<key>content-hint</key>
<string>GUID_partition_scheme</string>
<key>dev-entry</key>
<string>/dev/disk2</string>
<key>potentially-mountable</key>
<false/>
<key>unmapped-content-hint</key>
<string>GUID_partition_scheme</string>
</dict>
<dict>
<key>content-hint</key>
<string>Apple_APFS</string>
<key>dev-entry</key>
<string>/dev/disk2s1</string>
<key>potentially-mountable</key>
<false/>
<key>unmapped-content-hint</key>
<string>7C3457EF-0000-11AA-AA11-00306543ECAC</string>
</dict>
<dict>
<key>content-hint</key>
<string>41504653-0000-11AA-AA11-00306543ECAC</string>
<key>dev-entry</key>
<string>/dev/disk3s1</string>
<key>mount-point</key>
<string>/Volumes/Untitled</string>
<key>potentially-mountable</key>
<true/>
<key>unmapped-content-hint</key>
<string>41504653-0000-11AA-AA11-00306543ECAC</string>
<key>volume-kind</key>
<string>apfs</string>
</dict>
<dict>
<key>content-hint</key>
<string>EF57347C-0000-11AA-AA11-00306543ECAC</string>
<key>dev-entry</key>
<string>/dev/disk3</string>
<key>potentially-mountable</key>
<false/>
<key>unmapped-content-hint</key>
<string>EF57347C-0000-11AA-AA11-00306543ECAC</string>
</dict>
</array>
</dict>
</plist>
After I try to detach with:
hdiutil detach /Volumes/Untitled
diskutil list, returns:
/dev/disk2 (disk image):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme +100.0 MB disk2
1: Apple_APFS Container disk3 100.0 MB disk2s1
/dev/disk3 (synthesized):
#: TYPE NAME SIZE IDENTIFIER
0: APFS Container Scheme - +100.0 MB disk3
Physical Store disk2s1
1: APFS Volume Untitled 65.5 KB disk3s1
and going back to Apple's Disk Utility application, I see the Untitled volume listed, but it is grayed out.
I can only really fully eject it if I then do:
hdiutil detach /dev/disk2
So, mounting is one command, fully ejecting is two.
Is this the only / correct way to eject this kind of volume from the command line? What I would like to be able to do is fully eject it with a single command. Is that possible?
Best Answer
Use the following command.
From the man pages for
hdiutil
, the following appears:So the documentation states you may need to unmount filesystems first. I assume this is what the
hdiutil detach /Volumes/Untitled
command did.From the man pages for
diskutil
, the following appears:Here, there is no mention of having to run any other commands first.