Unable to mount encrypted TimeMachine backupbundle using DiskImageMounter

Solution 1:

I ended up figuring out a solution. It took several tries and a lot of time, but in the end I was able to recover my files.

TL;DR: Run fsck_hfs as root.

I also think I figured out why this problem occurred in the first place:

  • I tried to plug my backup disk directly directly to another machine.
  • I was originally able to access my backup files, but was no longer able to after I had put my machine to sleep.
  • I think it's the sleep that caused the disk image to get into a bad state.

I believe the reason why my previous attempts failed was due not being root.

$ sudo su
$ chflags -R nouchg lars-mbp.backupbundle
$ hdiutil attach -nomount -noverify -noautofsck lars-mbp.backupbundle  # this prompts me for the bundle encryption password

Running diskutil list, I'm able to the device associated with the HFS volume. Output below is truncated from the real output:

$ diskutil list
/dev/disk5 (external, physical):
   /dev/disk5           GUID_partition_scheme           
   /dev/disk5s1         EFI                             
   /dev/disk5s2         Apple_HFS  

/dev/disk5s2 is the one we want. Then I ran fsck_hfs on the disk:

$ fsck_hfs -drfy /dev/disk5s2
journal_replay(/dev/disk5s2) returned 0
** /dev/rdisk5s2
    Using cacheBlockSize=32K cacheTotalBlock=65536 cacheSize=2097152K.
   Executing fsck_hfs (version hfs-556.60.1).
** Checking Journaled HFS Plus volume.
** Detected a case-sensitive volume.
   The volume name is Time Machine Backups
** Checking extents overflow file.
** Checking catalog file.
** Rebuilding catalog B-tree.
hfs_UNswap_BTNode: invalid node height (1)
** Rechecking volume.
** Checking Journaled HFS Plus volume.
** Detected a case-sensitive volume.
   The volume name is Time Machine Backups
** Checking extents overflow file.
** Checking catalog file.
   Incorrect block count for file shutdown_time
   (It should be 1 instead of 0)
   Incorrect number of thread records
(4, 21684)
    CheckCatalogBTree: dirCount = 480561, dirThread = 480560
   Incorrect number of thread records
(4, 21684)
    CheckCatalogBTree: fileCount = 3833287, fileThread = 3833274
** Checking multi-linked files.
** Checking catalog hierarchy.
   Missing thread record (id = 6297728)
   Invalid directory item count
   (It should be 53 instead of 80)
   Incorrect folder count in a directory (id = 5263039)
   (It should be 1 instead of 12)
** Checking extended attributes file.
   Overlapped extent allocation (id = 6297658, /.Spotlight-V100/Store-V2/3D6A1DA4-ABC0-4E0F-B58E-85DBB4D0546C/live.2.shadowIndexArrays)
    extentType=0x0, startBlock=0x3550cd5, blockCount=0x96, attrName=(null)
    extentType=0x0, startBlock=0x3550cd5, blockCount=0x1, attrName=(null)
   Overlapped extent allocation (id = 6297731)
    extentType=0x0, startBlock=0x3550cd8, blockCount=0x1, attrName=(null)
   Overlapped extent allocation (id = 6297732)
    extentType=0x0, startBlock=0x3550cd9, blockCount=0x1, attrName=(null)
   Overlapped extent allocation (id = 6297744)
    extentType=0x0, startBlock=0x3550cd6, blockCount=0x1, attrName=(null)
   Overlapped extent allocation (id = 6297757)
    extentType=0x0, startBlock=0x3550cd7, blockCount=0x1, attrName=(null)
   Overlapped extent allocation (id = 6297758)
** Checking multi-linked directories.
    privdir_valence=13410, calc_dirlinks=123458, calc_dirinode=13410
** Checking volume bitmap.
   Volume bitmap needs minor repair for orphaned blocks
   Volume bitmap needs repair for under-allocation
** Checking volume information.
   Invalid volume free block count
   (It should be 234391157 instead of 236195590)
    invalid VHB nextCatalogID 
   Volume header needs minor repair
(2, 0)
   Verify Status: VIStat = 0xa800, ABTStat = 0x0000 EBTStat = 0x0000
                  CBTStat = 0x0800 CatStat = 0x00004020
** Repairing volume.
   Look for links to corrupt files in DamagedFiles directory.
GetCatalogRecord: No matching catalog thread record found
   Cannot create links to all corrupt files
GetCatalogRecord: No matching catalog thread record found
GetCatalogRecord: No matching catalog thread record found
GetCatalogRecord: No matching catalog thread record found
GetCatalogRecord: No matching catalog thread record found
    FixOrphanedFiles: Created thread record for id=6297756 (err=0)
    FixOrphanedFiles: Created thread record for id=6297742 (err=0)
    FixOrphanedFiles: Created thread record for id=6297734 (err=0)
    FixOrphanedFiles: Created thread record for id=6297741 (err=0)
    FixOrphanedFiles: Created thread record for id=6297740 (err=0)
    FixOrphanedFiles: Created thread record for id=6297735 (err=0)
    FixOrphanedFiles: Created thread record for id=6297732 (err=0)
    FixOrphanedFiles: Created thread record for id=6297733 (err=0)
    FixOrphanedFiles: Created thread record for id=6297739 (err=0)
    FixOrphanedFiles: Created thread record for id=6297738 (err=0)
    FixOrphanedFiles: Created thread record for id=6297736 (err=0)
    FixOrphanedFiles: Created thread record for id=6297737 (err=0)
    FixOrphanedFiles: Created thread record for id=6297757 (err=0)
    FixOrphanedFiles: Created thread record for id=6297730 (err=0)
    FixOrphanedFiles: Created thread record for id=6297729 (err=0)
    FixOrphanedFiles: Created thread record for id=6297731 (err=0)
    FixOrphanedFiles: Created thread record for id=6297728 (err=0)
    FixOrphanedFiles: Created thread record for id=6297754 (err=0)
    FixOrphanedFiles: Created thread record for id=6297746 (err=0)
    FixOrphanedFiles: Created thread record for id=6297753 (err=0)
    FixOrphanedFiles: Created thread record for id=6297752 (err=0)
    FixOrphanedFiles: Created thread record for id=6297747 (err=0)
    FixOrphanedFiles: Created thread record for id=6297744 (err=0)
    FixOrphanedFiles: Created thread record for id=6297745 (err=0)
    FixOrphanedFiles: Created thread record for id=6297751 (err=0)
    FixOrphanedFiles: Created thread record for id=6297750 (err=0)
    FixOrphanedFiles: Created thread record for id=6297748 (err=0)
    FixOrphanedFiles: Created thread record for id=6297749 (err=0)
    FixOrphanedFiles: Created thread record for id=6297758 (err=0)
    FixOrphanedFiles: Deleted thread record for id=6297642 (err=0)
    FixOrphanedFiles: Deleted thread record for id=6297649 (err=0)
    FixOrphanedFiles: Deleted thread record for id=6297650 (err=0)
    FixOrphanedFiles: Deleted thread record for id=6297675 (err=0)
    FixOrphanedFiles: Deleted thread record for id=6297676 (err=0)
    FixOrphanedFiles: Deleted thread record for id=6297677 (err=0)
    FixOrphanedFiles: Deleted thread record for id=6297678 (err=0)
    FixOrphanedFiles: Deleted thread record for id=6297679 (err=0)
    FixOrphanedFiles: Deleted thread record for id=6297681 (err=0)
    FixOrphanedFiles: Deleted thread record for id=6297683 (err=0)
    FixOrphanedFiles: Deleted thread record for id=6297684 (err=0)
    FixOrphanedFiles: Deleted thread record for id=6297685 (err=0)
    FixOrphanedFiles: Deleted thread record for id=6297690 (err=0)
    FixOrphanedFiles: Deleted thread record for id=6297691 (err=0)
    FixOrphanedFiles: Deleted thread record for id=6297692 (err=0)
** Rechecking volume.
** Checking Journaled HFS Plus volume.
** Detected a case-sensitive volume.
   The volume name is Time Machine Backups
** Checking extents overflow file.
** Checking catalog file.
** Checking multi-linked files.
** Checking catalog hierarchy.
   Incorrect folder count in a directory (id = 2)
   (It should be 8 instead of 7)
** Checking extended attributes file.
** Checking multi-linked directories.
    privdir_valence=13410, calc_dirlinks=123458, calc_dirinode=13410
** Checking volume bitmap.
** Checking volume information.
** Repairing volume.
** Rechecking volume.
** Checking Journaled HFS Plus volume.
** Detected a case-sensitive volume.
   The volume name is Time Machine Backups
** Checking extents overflow file.
** Checking catalog file.
** Checking multi-linked files.
** Checking catalog hierarchy.
** Checking extended attributes file.
** Checking multi-linked directories.
    privdir_valence=13410, calc_dirlinks=123458, calc_dirinode=13410
** Checking volume bitmap.
** Checking volume information.
** Trimming unused blocks.
** The volume Time Machine Backups was repaired successfully.
    CheckHFS returned 0, fsmodified = 1

This ran for a long time, but afterward I was able to recover all files.

Note: I actually had two different computers' backups on this backup disk, and both were corrupted due to this issue. Fixing the other required running fsck_hfs multiple times. Your results may vary.

Some sources which helped me along the way:

  • https://swissmacuser.ch/hfs-volume-data-recovery-diskutility-could-not-mount-error-49153/
  • Repair Time Machine sparsebundle that will no longer mount