APFS Brand new filesystem corruption

Hi All,


I have just experienced my first APFS corruption. Corruption happened immediately after the creation of a new Volume. Here relevant outputs.

Ideas to fix this? Filed a RDAR: 26844922.


darkstar:~ root# df

Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on

/dev/disk2 133454592 69024720 63917872 52% 854500 4294112779 0% /

devfs 407 407 0 100% 705 0 100% /dev

/dev/disk1 838919560 632771328 206148232 76% 2583443 4292383836 0% /Volumes/Macintosh HD

map -hosts 0 0 0 100% 0 0 100% /net

map auto_home 0 0 0 100% 0 0 100% /home

/dev/disk4s2 116633168 306144 116327024 1% 78 4294967201 0% /Volumes/Untitled



darkstar:~ root# diskutil apfs createContainer disk4s2

Started APFS operation on disk4s2 Untitled

Creating a new empty APFS Container

Unmounting Volumes

Switching disk4s2 to APFS

Creating APFS Container

Created new APFS Container disk4s2

Finished APFS operation on disk4s2 Untitled



darkstar:~ root# diskutil apfs list

======================================================================================================

ENUMERATION OF ALL CURRENT APFS OBJECTS



APFS CONTAINER: REFERENCE: disk4s2 Total Container Size = 59.7 GB (59716182016 Bytes)

| Container Free Space = 59.6 GB (59634237440 Bytes)

|

|--< APFS PHYSICAL STORE: disk4s2

|

======================================================================================================



---------------------------------------------------------------------

APFS OBJECTS BY ITERATING ALL CURRENT DISKS WHILE CHECKING APFS ROLES



APFS PHYSICAL STORE = disk4s2 -> APFS CONTAINER REFERENCE = disk4s2

---------------------------------------------------------------------

darkstar:~ root# diskutil apfs addVolume disk4s2 APFS MyFirstAPFS

Exporting new shared unencrypted APFS Volume "MyFirstAPFS" from APFS Container Reference disk4s2

Started APFS operation

Adding APFS Volume to APFS Container

Creating APFS Volume

Created new APFS Volume disk4s2s1

Mounting APFS Volume

Error: -69842: Couldn't mount disk


darkstar:~ root# diskutil mount /dev/disk4s2s1

Volume on disk4s2s1 failed to mount

If the volume is damaged, try the "readOnly" option

darkstar:~ root# diskutil mount /dev/disk4s2

Volume on disk4s2 failed to mount

If the volume is damaged, try the "readOnly" option

darkstar:~ root# diskutil list


[…]



/dev/disk4s2s1 (external, virtual):

#: TYPE NAME SIZE IDENTIFIER

0: APFS Volume MyFirstAPFS +20.5 KB disk4s2s1





darkstar:~ root# fsck_apfs /dev/disk4s2s1

** Checking volume.

** Checking the container superblock.

** Checking the space manager.

** Checking the object map.

** Checking the APFS volume superblock.

** Checking the object map.

** Checking the fsroot tree.

** Checking the extent ref tree.

** Checking the snapshot metadata tree.

** Checking the snapshots.

fsck_apfs: btree: invalid btn_btree.bt_longest_val (0), given btn_btree.bt_fixed.bt_val_size

Space Verification failed.

** The volume /dev/disk4s2s1 could not be verified completely.

Answers

Check out this discussion.


https://forums.developer.apple.com/message/144600#144600

With the recommendation from mdobro, I've detailed the steps to get a working directory. Seems the trick is the create two volumes, destoy the two, and then create one. No corruption.


R

try mount_apfs instead of mount command


sudo mkdir /volumes/test
sudo mount_apfs disk4s2s1 /volumes/test
chown -R <your user id> /volumes/test


even if you use diskutil apfs to add/delete/addvolume trick, you will have to change the permission(DP1/bug?).