Getting "Object Map is Invalid" on startup drive - invalid key order

I'm getting the "error: btn: invalid key order: index nnn is greater than index nnn+1 (should be less than)" when I run firstaid on my startup volume - "Macintosh HD - Data - Data", the underlying volumes don't have an error. I've run firstaid a few times and the "nnn" keeps changing, anywhere from 15 to 109 so far.

System - 2018 MBP 15", 250GB SSD, Ventura 13.4.1. Drive has approx. 80GB free so it's not running out of space.


How do I fix this - is there an aftermarket product that can recover on the fly, or at least without a disk format & reinstall/recover?


TIA

MacBook Pro 15″

Posted on Aug 2, 2023 9:33 PM

Reply
Question marked as Top-ranking reply

Posted on Aug 9, 2023 9:31 AM

You're correct; unfortunately this would likely mean a wipe is necessary to resolve the issue unless a third-party repair app could resolve the issue.


To erase the affected volumes, which host all of your data, complete these steps:


  1. Back up your Mac to preserve your data on a different drive.
  2. Start up in macOS Recovery: Hold down Command-R as you power on or restart your Intel-based Mac. Release the keys when the Apple logo and a progress bar appear.
  3. Provide your administrator password if prompted to continue.
  4. The Recovery app should appear. Choose Disk Utility and Continue.
  5. In Disk Utility, select View -> Show All Devices.


This is where things start to get a bit complex. In macOS Catalina and later, your "startup disk" is actually a volume group consisting of two APFS volumes:


  • The System volume (in your case, "Macintosh HD - Data"), and
  • The Data volume (in your case, "Macintosh HD - Data - Data").


To correctly erase the volume group; both APFS volumes must be deleted, and then a new APFS volume must be created. Disk Utility will do this automatically if you tell it to erase the volume group, but individually erasing each volume won't do this correctly.


Technically, only your Data volume is corrupt and needs to be erased. However, the macOS installer (from what I understand) won't be able to work with only the remaining system volume, since it was part of a volume group. So both volumes need to be deleted, and a new one needs to be made (the volume group needs to be erased).


  1. In Disk Utility, there should be an expandable entry named "Macintosh HD - Data" in the sidebar, with an icon looking like a stack of sheets. Select it.
  2. Choose Erase, then provide these options:
    1. Name: Macintosh HD
    2. Format: APFS
  3. Choose Erase Volume Group. If you only see Erase instead, make sure that Disk Utility is asking to erase the volume group and NOT just the individual volume.
  4. When the erase is complete, quit Disk Utility and install macOS.
  5. After the macOS install is complete, restore from your backup.

Similar questions

10 replies
Question marked as Top-ranking reply

Aug 9, 2023 9:31 AM in response to TopDuck

You're correct; unfortunately this would likely mean a wipe is necessary to resolve the issue unless a third-party repair app could resolve the issue.


To erase the affected volumes, which host all of your data, complete these steps:


  1. Back up your Mac to preserve your data on a different drive.
  2. Start up in macOS Recovery: Hold down Command-R as you power on or restart your Intel-based Mac. Release the keys when the Apple logo and a progress bar appear.
  3. Provide your administrator password if prompted to continue.
  4. The Recovery app should appear. Choose Disk Utility and Continue.
  5. In Disk Utility, select View -> Show All Devices.


This is where things start to get a bit complex. In macOS Catalina and later, your "startup disk" is actually a volume group consisting of two APFS volumes:


  • The System volume (in your case, "Macintosh HD - Data"), and
  • The Data volume (in your case, "Macintosh HD - Data - Data").


To correctly erase the volume group; both APFS volumes must be deleted, and then a new APFS volume must be created. Disk Utility will do this automatically if you tell it to erase the volume group, but individually erasing each volume won't do this correctly.


Technically, only your Data volume is corrupt and needs to be erased. However, the macOS installer (from what I understand) won't be able to work with only the remaining system volume, since it was part of a volume group. So both volumes need to be deleted, and a new one needs to be made (the volume group needs to be erased).


  1. In Disk Utility, there should be an expandable entry named "Macintosh HD - Data" in the sidebar, with an icon looking like a stack of sheets. Select it.
  2. Choose Erase, then provide these options:
    1. Name: Macintosh HD
    2. Format: APFS
  3. Choose Erase Volume Group. If you only see Erase instead, make sure that Disk Utility is asking to erase the volume group and NOT just the individual volume.
  4. When the erase is complete, quit Disk Utility and install macOS.
  5. After the macOS install is complete, restore from your backup.

Aug 3, 2023 10:20 PM in response to TopDuck

Thanks! Glad that you have backups in good condition. Assuming these disk identifiers remain the same (run "diskutil list" again first), run these commands to try to repair your data. Exclude the quotes from all commands.


(In theory, running First Aid on the internal APFS container in Disk Utility should do the same thing, but this command-line method includes a few additional flags that First Aid usually ignores.)


  1. Unmount all volumes in the container: run "diskutil unmount $diskID", where $diskID = "disk3s1", "disk3s2", etc. Use one disk ID in each command.
  2. If FileVault is on, unlock the Data volume with your login password but don't mount it: "diskutil apfs unlock disk3s1 -nomount"
  3. Run fsck (filesystem check, First Aid's backend) on the APFS container and its volumes, and repair all damage found: "fsck_apfs -y -o -T /dev/disk0s2"


If successful, First Aid should no longer report any errors on your volumes.

Aug 2, 2023 9:48 PM in response to TopDuck

Hi TopDuck,


If your Mac was running an older version of macOS, or if this was an external drive formatted as the old Mac format (Mac OS Extended Journaled), I'd recommend DiskWarrior. Unfortunately they don't support APFS yet - the format your Mac currently uses.


Can you please do the following so that I can better understand how your internal drive is set up? macOS includes some disk repair commands in Terminal, but I need to know how the drive is set up before I can provide accurate commands to use.


  1. Start up in macOS Recovery: Hold down Command-R as you power on or restart your Intel-based Mac. Release the keys when the Apple logo and a progress bar appear.
  2. Provide your administrator password if prompted to continue.
  3. The Recovery app should appear. In the top menu bar, select Utilities -> Terminal.
  4. Type "diskutil list" without the quotes and hit Enter (Return).
  5. Please post the full output here.

Aug 5, 2023 11:50 AM in response to Encryptor5000

Ran the commands - output below (trimmed for the 5k text limit), TLDR - didn't work, still has the invalid key order on /dev/rdisk3s1. I'm guessing this means a reformat or at least a wipe and reinstall OS & data?


-bash-3.2# fsck_apfs -y -o -T /dev/disk0s2

** Checking the container superblock.

Checking the checkpoint with transaction ID 9338396.

** Checking the EFI jumpstart record.

** Checking the space manager.

** Checking the space manager free queue trees.

** Checking the object map.

** Checking the encryption key structures.

** Checking volume /dev/rdisk3s1.

** Checking the APFS volume superblock.

The volume Macintosh HD - Data - Data was formatted by diskmanagementd (1412.141.1) and last modified by apfs_kext (2142.120.7).

** Checking the object map.

error: btn: oid (590718), xid (9338352), type (0x40000003), subtype (0xb), flags (0x4) level (1)

error: btn: invalid key order: index 14 is greater than index 15 (should be less than)

index 13 key : b5 8e 06 00 00 00 00 00 6f 40 48 00 00 00 00 00

index 14 key : 40 06 10 00 00 00 00 00 a1 f2 36 00 00 00 00 00

index 15 key : ce a4 06 00 00 00 00 00 59 61 45 00 00 00 00 00

index 16 key : 5b af 06 00 00 00 00 00 38 8c 74 00 00 00 00 00

Object map is invalid.

** The volume /dev/rdisk3s1 was found to be corrupt and cannot be repaired.

** Checking volume /dev/rdisk3s2.

** Checking the APFS volume superblock.

The volume Preboot was formatted by newfs_apfs (748.77.4) and last modified by apfs_kext (2142.120.7).

** Checking the object map.

** Checking the snapshot metadata tree.

** Checking the snapshot metadata.

** Checking the fsroot tree.

** Checking the extent ref tree.

** Verifying volume object map space.

** The volume /dev/rdisk3s2 appears to be OK.

** Checking volume /dev/rdisk3s3.

** Checking the APFS volume superblock.

The volume Recovery was formatted by newfs_apfs (748.77.4) and last modified by apfs_kext (2142.120.7).

** Checking the object map.

** Checking the snapshot metadata tree.

** Checking the snapshot metadata.

** Checking the fsroot tree.

** Checking the extent ref tree.

** Verifying volume object map space.

** The volume /dev/rdisk3s3 appears to be OK.

** Checking volume /dev/rdisk3s4.

** Checking the APFS volume superblock.

The volume VM was formatted by apfs_boot_util (1934.141.2) and last modified by apfs_kext (2142.120.7).

** Checking the object map.

** Checking the snapshot metadata tree.

** Checking the snapshot metadata.

** Checking the fsroot tree.

** Checking the extent ref tree.

** Verifying volume object map space.

** The volume /dev/rdisk3s4 appears to be OK.

** Checking volume /dev/rdisk3s5.

** Checking the APFS volume superblock.

The volume Macintosh HD - Data was formatted by storagekitd (1934.141.2) and last modified by apfs_kext (2142.120.7).

** Checking the object map.

** Checking the snapshot metadata tree.

** Checking the snapshot metadata.

** Checking snapshot 1 of 1 (com.apple.os.update-3379F3DC95CFF07D9D49D5CE34EF1CCB1E66EF7D12A3055A5D1A0D2695C12EDE)

** Checking the fsroot tree.

** Checking the file extent tree.

** Checking the extent ref tree.

** Verifying volume object map space.

** The volume /dev/rdisk3s5 appears to be OK.

** Checking volume /dev/rdisk3s6.

** Checking the APFS volume superblock.

The volume Update was formatted by com.apple.MobileSo (1934.141.2) and last modified by apfs_kext (2142.120.7).

** Checking the object map.

** Checking the snapshot metadata tree.

** Checking the snapshot metadata.

** Checking the fsroot tree.

** Checking the extent ref tree.

** Verifying volume object map space.

** The volume /dev/rdisk3s6 appears to be OK.

** Verifying allocated space.

** The container /dev/disk0s2 could not be verified completely.


Nov 28, 2023 11:28 AM in response to TopDuck

It's been a while but I thought I'd add the final resolution here - I ended up wiping the drive and reinstalling Ventura, and yesterday upgraded to Sonoma. No usability issues, but I'll be posting in the Sonoma forum on the weird duplication of my "Macintosh HD - Data" and Macintosh HD - Data - Data" partitions. I only discovered it because Time Machine complained about a duplicate drive name.

Aug 9, 2023 9:33 AM in response to TopDuck

TopDuck wrote:

On a side note - what does the -D "scavenge disk" do? the man for fsck_apfs seems to be a bit out of date and doesn't describe the -D option at all (or -T).

The "scavenge disk" option in fsck_apfs might have been inspired by DiskWarrior. In DiskWarrior, scavenging implies that the filesystem structures are severely damaged (or bad blocks exist on the drive) and that a deeper scan than normal should be done to see if missing data can be recovered. I presume the same applies to fsck_apfs, although I haven't tried it yet. It could potentially resolve your issue, and should be safe enough to try considering that you already have good backups.

Nov 28, 2023 2:48 PM in response to TopDuck

TopDuck wrote:

It's been a while but I thought I'd add the final resolution here - I ended up wiping the drive and reinstalling Ventura, and yesterday upgraded to Sonoma. No usability issues, but I'll be posting in the Sonoma forum on the weird duplication of my "Macintosh HD - Data" and Macintosh HD - Data - Data" partitions. I only discovered it because Time Machine complained about a duplicate drive name.

Thanks for the update! Found your new thread and posted there.

Aug 3, 2023 1:38 PM in response to Encryptor5000

Here's the output:


/dev/disk0 (internal, physical):

#: TYPE NAME SIZE IDENTIFIER

0: GUID_partition_scheme *251.0 GB disk0

1: EFI EFI 314.6 MB disk0s1

2: Apple_APFS Container disk3 250.7 GB disk0s2


/dev/disk1 (disk image):

#: TYPE NAME SIZE IDENTIFIER

0: GUID_partition_scheme +1.2 GB disk1

1: Apple_APFS Container disk2 1.2 GB disk1s1


/dev/disk2 (synthesized):

#: TYPE NAME SIZE IDENTIFIER

0: APFS Container Scheme - +1.2 GB disk2

Physical Store disk1s1

1: APFS Volume macOS Base System 942.9 MB disk2s1

2: APFS Volume Preboot 81.3 MB disk2s2


/dev/disk3 (synthesized):

#: TYPE NAME SIZE IDENTIFIER

0: APFS Container Scheme - +250.7 GB disk3

Physical Store disk0s2

1: APFS Volume Macintosh HD - Data ... 158.9 GB disk3s1

2: APFS Volume Preboot 1.9 GB disk3s2

3: APFS Volume Recovery 1.7 GB disk3s3

4: APFS Volume VM 24.6 KB disk3s4

5: APFS Volume Macintosh HD - Data 9.1 GB disk3s5


The strange thing is that my MBP is running fine, the only reason I ran First Aid is because Time Machine kept complaining that it couldn't create a snapshot of the drive and thought the privileges might have been screwed up (I recently changed admin logins on the MBP because it stopped allowing me to update software - that's another story). After multiple First Aid runs, including in Recovery Mode, once back in normal operation, Time Machine started working again.


I have moved all of my data onto my NAS, and have good backups, so I'm prepared to nuke the drive and start over if I have to, but I'd rather not if there's a simpler way.


Aug 11, 2023 6:07 AM in response to Encryptor5000

Ok, well I might give this a try in the next day or 2. I’m a bit torn on wiping the drive now because there has been no issue since the Time Machine snapshot issue, which fixed itself. I have swapped drives on other macs in the past and restore doesn’t always get me back to normal, so there might be some extra work on my part - options and credentials don’t always make it through the recovery process. :)

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Getting "Object Map is Invalid" on startup drive - invalid key order

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.