hdiutil attach/detach/convert results to "resource temporarily unavailable"

0

Since MacOS 10.13 I have the following problem.

  1. /usr/bin/hdiutil attach "target/MyDrive-tmp.dmg" -mountroot /tmp
/dev/disk3              GUID_partition_scheme           
/dev/disk3s1            Apple_APFS                      
/dev/disk4              EF57347C-0000-11AA-AA11-0030654 
/dev/disk4s1            41504653-0000-11AA-AA11-0030654 /private/tmp/MyDrive
  1. /usr/bin/hdiutil detach -force -debug "/tmp/MyDrive" or diskutil eject "/tmp/MyDrive"
process_detach: entry with "/tmp/MyDrive"
util_verify_dev_entry: entry with "disk4s1".
process_detach_deventry: about to unmount_and_eject disk4s1
unmount_and_eject(disk4s1)
LetDIDriverSettleDown: calling IOServiceWaitQuiet...
DI_kextWaitQuiet: about to call IOServiceWaitQuiet...
DI_kextWaitQuiet: IOServiceWaitQuiet took 0.000005 seconds
LetDiskImageDriverSettleDown: wait took 0.000066 seconds
_unmountCallback: disk4
"disk4" unmounted.
"disk4" ejected.
  1. /usr/bin/hdiutil convert "target/MyDrive-tmp.dmg" -format UDZO -o "target/MyDrive.dmg" -debug
DIIsInitialized: returning YES
DIIsInitialized: returning YES
DIBackingStoreNewWithCFURL: entry with
file:///Users/xxxx/Documents/git/Midi%20Automator/Midi%20Automator/target/MyDrive-tmp.dmg
writeable: false
DIBackingStoreInstantiatorProbe: entry
file:///Users/xxxx/Documents/git/Midi%20Automator/Midi%20Automator/target/MyDrive-tmp.dmg
writeable: false
DIBackingStoreInstantiatorProbe: probing interface 0 CBSDBackingStore
CBSDBackingStore::newProbe score 100 for 
file:///Users/xxxx/Documents/git/Midi%20Automator/Midi%20Automator/target/MyDrive-tmp.dmg
DIBackingStoreInstantiatorProbe: interface  0, score      100, CBSDBackingStore
DIBackingStoreInstantiatorProbe: probing interface 1 CBundleBackingStore
CBundleBackingStore::newProbe score -1000 for 
file:///Users/xxxx/Documents/git/Midi%20Automator/Midi%20Automator/target/MyDrive-tmp.dmg
DIBackingStoreInstantiatorProbe: interface  1, score    -1000, 
CBundleBackingStore
DIBackingStoreInstantiatorProbe: probing interface 2 CRAMBackingStore
CRAMBackingStore::probe: scheme "file": not ram: or ramdisk: scheme.
CRAMBackingStore::probe: score -1000 for 
file:///Users/xxxx/Documents/git/Midi%20Automator/Midi%20Automator/target/MyDrive-tmp.dmg
DIBackingStoreInstantiatorProbe: interface  2, score    -1000, CRAMBackingStore
DIBackingStoreInstantiatorProbe: probing interface 3 CCarbonBackingStore
CCarbonBackingStore::newProbe: setting initial rval to +100
CCarbonBackingStore::newProbe score 100 for 
file:///Users/xxxx/Documents/git/Midi%20Automator/Midi%20Automator/target/MyDrive-tmp.dmg
DIBackingStoreInstantiatorProbe: interface  3, score      100, 
CCarbonBackingStore
DIBackingStoreInstantiatorProbe: probing interface 4 CDevBackingStore
CDevBackingStore::newProbe: not /dev/disk or /dev/rdisk (/Users/xxxx/Documents/git/Midi Automator/Midi Automator/target/MyDrive-tmp.dmg).CDevBackingStore::newProbe score -1000 for file:///Users/aguelle/Documents/git/Midi%20Automator/Midi%20Automator/target/MyDrive-tmp.dmg
DIBackingStoreInstantiatorProbe: interface  4, score    -1000, CDevBackingStore
DIBackingStoreInstantiatorProbe: probing interface 5 CCURLBackingStore
CCURLBackingStore::probe: scheme is: file
CCURLBackingStore::probe: not recognized URL scheme.
CCURLBackingStore::probe: score -1000 for 
file:///Users/xxxx/Documents/git/Midi%20Automator/Midi%20Automator/target/MyDrive-tmp.dmg
DIBackingStoreInstantiatorProbe: interface  5, score    -1000, CCURLBackingStore
DIBackingStoreInstantiatorProbe: probing interface 6 CVectoredBackingStore
CVectoredBackingStore::newProbe not "vectored" scheme.
CVectoredBackingStore::newProbe score -1000 for file:///Users/xxxx/Documents/git/Midi%20Automator/Midi%20Automator/target/MyDrive-tmp.dmg
DIBackingStoreInstantiatorProbe: interface  6, score    -1000, 
CVectoredBackingStore
DIBackingStoreInstantiatorProbe: selecting CBSDBackingStore
DIBackingStoreNewWithCFURL: CBSDBackingStore
CBSDBackingStore::setPermission: opening /Users/xxxx/Documents/git/Midi 
Automator/Midi Automator/target/MIDI Automator-tmp.dmg
CBSDBackingStore::OpenLockFriendly: mapping flags 0x00000000 -> 0x00000014 (locks are MANDATORY)
CBSDBackingStore:OpenLockFriendly: could not open with lock 35
DIBackingStoreNewWithCFURL: instantiator returned 35
DIBackingStoreNewWithCFURL: returning 35
DIResolveURLToBackingStore: unable to resolve to any backing store class. 35. 
DIResolveURLToDiskImage: resolving backing store/file encoding failed. 35. 
convert: unable to recognize "target/MyDrive-tmp.dmg":
resource temporarily unavailable.hdiutil: convert: result: 35`
  1. /usr/bin/hdiutil attach "target/MyDrive-tmp.dmg" -mountroot /tmp
  2. Eject MyDrive via mouse click in Finder
  3. /usr/bin/hdiutil convert "target/MyDrive-tmp.dmg" -format UDZO -o "target/MyDrive.dmg"

-> Result: Conversion worked fine

So what is the difference between hdiutil detach, diskutil eject and ejecting from Finder?

Analysis: lsof [device] gives no output as the device is not left after hdiutil detach at least mount shows none.

diskutil info "disk4s1" or diskutil info /tmp/MyDrive:

Device Identifier:        disk4s1
Device Node:              /dev/disk4s1
Whole:                    No
Part of Whole:            disk4
Volume Name:              MyDrive
Mounted:                  Yes
Mount Point:              /private/tmp/MyDrive
Partition Type:           41504653-0000-11AA-AA11-00306543ECAC
File System Personality:  APFS
Type (Bundle):            apfs
Name (User Visible):      APFS
Owners:                   Disabled
OS Can Be Installed:      Yes
Media Type:               Generic
Protocol:                 Disk Image
SMART Status:             Not Supported
Volume UUID:              A3EE0B42-A021-47AA-B424-E494B75049D3
Disk / Partition UUID:    A3EE0B42-A021-47AA-B424-E494B75049D3
Disk Size:                212.5 MB (212471808 Bytes) (exactly 414984 512-Byte-Units)
Device Block Size:        4096 Bytes
Volume Total Space:       212.5 MB (212471808 Bytes) (exactly 414984 512-Byte-Units)
Volume Used Space:        184.7 MB (184709120 Bytes) (exactly 360760 512-Byte-Units) (86.9%)
Volume Available Space:   27.8 MB (27762688 Bytes) (exactly 54224 512-Byte-Units) (13.1%)
Allocation Block Size:    4096 Bytes
Read-Only Media:          No
Read-Only Volume:         No
Device Location:          External
Removable Media:          Removable
Media Removal:            Software-Activated
macos
terminal
macos-high-sierra
asked on Stack Overflow Jan 21, 2018 by Angelo Berlin • edited Oct 25, 2019 by John Clements

2 Answers

2

hdiutil is really for working with disk images just as you are doing. The eject in finder is essentially diskutil eject [device]. hdutil detach is to "detach a disk image and terminate any associated process" (from the man page). Where diskutil is for "manipulating the structure of of local disks" (from the man page). Functionally, hdiutil detach is the same as diskutil eject. How it works though depends on if Disk Arbitration is running.

Disk Arbitration is framework and is in process diskarbitrationd that gets started by launchd and is always on by default. It handles the mounting and unmounting of disks attached via USB, Firewire, Thunderbolt, ect.

According to the man page on hdutil, when Disk Arbitration is running. hdutil detach will use it to unmount any file systems and detach the image. But if diskarbitrationd is not running then it will try and unmount filesystems and detach the image directly with a system call to ioctl. I don't recall for certain if diskutil -eject uses the Disk Arbitration framework but I want to say that it does.

It might be interesting to try and figure out why you getting that error. It typically means that exclusive access was not obtainable. You might experiment with lsof [device] This will show all the ope files and PIDs and lot more for the device, and this can maybe give you clues as to what is giving the [EBUSY] error (Resource Temporarily Unavailable). You can use mount with no argument to list all the devices and mount points if you don't know what device it is. I believe that you can also do lsof [mount/point]. The man page for lsof is your friend, and it is very long.

Another diagnostic is to use the -verbose option with hdiutil. It is available with all verbs. So, /usr/bin/hdiutil -verbose convert "target/MyDrive-tmp.dmg" -format UDZO -o "target/MyDrive.dmg" might provide some enlightenment.

And yet another possible source of clues would to have have an additional Terminal.app window open with the command diskutil activity running when you try the steps that cause the error. This command continuously reports on all Disk Arbitration framework activity. Ctrl-C to stop the process.

You have a workaround that is working for you so maybe looking into why it is giving the error isn't important or interesting to you. Also, if you don't want to use Finder you can always use diskutil eject [device] from the terminal. I have noticed a lot of things that are not quite right since I 'upgraded' to High Sierra and based on blogs around the net, it seems Apple is breaking things in the name of security and their new filesystem. I doubt in this case it is security related but I wouldn't be surprised if they introduced a bug altering commands and frameworks to work with APFS.

answered on Stack Overflow Jan 24, 2018 by C Knight
2

I also observed the problem that on newer OS X versions after hdiutil detach the DMG was still occupied by diskimage-helper and I could not do hdiutil convert due to the error message you got.

My solution simply was to copy the source file first, because that works without problem and then do the convert on the copy. This works without problems for me so far.

answered on Stack Overflow Aug 5, 2019 by Vampire

User contributions licensed under CC BY-SA 3.0