How do I fsck_apfs an encrypted volume?
I'm playing with macOS 10.13 beta but a volume seems to have been corrupted during migration to APFS. I can boot and log in but soon get a "static screen". I launched recovery mode and launched disk utility. When trying to run First Aid I get exit code 65. So I started the terminal:
If I run diskutil apfs list
I see the volume encrypted and locked.
I then tried diskutil apfs unlockVolume /dev/disk1s1
which unlocks AND mounts the volume.
Now fsck_apfs /dev/rdisk1s1
and fsck_apfs /dev/disk1s1
give error: container /dev/rdisk1 is mounted with write access.
How can I try and repair this volume? I suspect that something happened during the initial migrate and the volume is stuck in half APFS, half HFS+ somehow.
Update:
If I go back to "Disk Utility" and unmount the volume there and return to Terminal, then fsck_apfs /dev/disk1s1
gives error: container /dev/rdisk1 is mounted.
I try and unmount the "Image Volume", but diskutil umount /Volumes/Image\ Volume/
gives Volume Recovery on disk1s3 failed to unmount: dissented by PID 0 (kernel)
I had to change the format of the command given in the other answer. The correct command is:
diskutil apfs unlockVolume /dev/disk1 -nomount
Apple got back to my via Bug Reporter, saying diskutil apfs unlockVolume -nomount /dev/disk1
should unlock the volume but not mount it. This worked for me, but unfortunately I still can't run fsck_apfs
without it crashing.