Build DMG from APFS Recovery volume

Originator:adrian.kubisztal
Number:rdar://33208209 Date Originated:10 July 2017
Status:Closed Resolved:
Product:macOS 10.13 APFS Product Version:10.13
Classification: Reproducible:Yes
 
Area:
Disk Utility

Summary:
I would like to create dmg from APFS Recovery volume. Command:
hdiutil create /Users/admin/Recovery.dmg -srcdevice /dev/disk1s3
Is not working in this case. /dev/disk1s3 is recovery volume.

Steps to Reproduce:
1. Use 10.13 APFS
2. Run terminal
3. sudo hdiutil create /Users/admin/Recovery.dmg -srcdevice /dev/disk1s3 -gid 20 -mode 755 -puppetstrings -format UDZO

Expected Results:
Operation should create Recover.dmg

Observed Results:
hdiutil: create failed - No such file or directory

-verbose:
CDevBackingStore::openDataFork open() failed: Operation not permitted
MESSAGE:Attaching…
Error -1 (Undefined error: 0).
MESSAGE:Finishing…
DIHLDiskImageCreate() returned -1
hdiutil: create: returning -1
hdiutil: create failed - No such file or directory


-debug 
CBSDBackingStore::setPermission: opening /dev/rdisk1s3
CBSDBackingStore::OpenLockFriendly: mapping flags 0x00000000 -> 0x00000014 (locks are MANDATORY)
CBSDBackingStore:OpenLockFriendly: could not open with lock 1
CDevBackingStore::setPermission: CBSDBackingStore could not grant permission.  checking stat results instead.
/dev/rdisk1s3 : crw-r----- 
CDevBackingStore::newWithCFURL: granting read-only access
CDevBackingStore::setURL_Permissions_and_OpenFile: permission granted kDI_PERM_READONLY.
CDevBackingStore::openDataFork open() failed: Operation not permitted
DIBackingStoreNewWithCFURL: instantiator returned 4294967295
DIBackingStoreNewWithCFURL: returning -1
DIResolveURLToBackingStore: unable to resolve to any backing store class. -1. 
DIResolveURLToDiskImage: resolving backing store/file encoding failed. -1.

Version:
10.13 second beta, APFS file system

Notes:
disk1s3 is recovery volume. 
This command is working without any problem on HFS 10.12

Apple Answer:

You cannot create a diskimage from any APFS volume. It has to be created from an APFS container. This is because APFS stores all its metadata for all volumes inside the container and using -srcdevice with a particular volume does not make sense.

The error that we see in this case is the expected behavior.

As an alternative, “-srcfolder <path to mounted recovery volume>” can be used. This just does a file by file copy of the recovery volume contents while creating the new diskimage.

We are now closing this bug report.

If you have questions or comments about the resolution, please update your bug report with that information so we can respond.

Comments

You cannot create a diskimage from any APFS volume. It has to be created from an APFS container. This is because APFS stores all its metadata for all volumes inside the container and using -srcdevice with a particular volume does not make sense.

The error that we see in this case is the expected behavior.

As an alternative, “-srcfolder ” can be used. This just does a file by file copy of the recovery volume contents while creating the new diskimage.

We are now closing this bug report.

If you have questions or comments about the resolution, please update your bug report with that information so we can respond.

By adrian.kubisztal at Aug. 22, 2017, 1:57 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!