Recovering broken ecryptfs on SD-card with lollipop This morning my phone froze and I had to hard reset it. Now when I boot and I insert my SD card, I get the following two messages:


Preparing SD card/checking for errors.
A dialog offering to encrypt my SD card. Here I can pick disable or continue, entering my device password.


So far I have only tried continue, with device password - then I have "sd card encryption encrypting sd card" alongside checking for errors. 

So I've started digging. Firstly

$ mount | grep -i extsdcard                    
/dev/block/vold/179:65 /mnt/media_rw/extSdCard exfat rw,dirsync,nosuid,nodev,noexec,noatime,nodiratime,uid=1023,gid=1023,fmask=0007,dmask=0007,allow_utime=0020,codepage=cp437,iocharset=utf8,namecase=0,errors=remount-ro 0 0
/mnt/media_rw/extSdCard /storage/extSdCard sdcardfs rw,seclabel,nosuid,nodev,relatime,uid=1023,gid=1023,derive=unified 0 0
/storage/extSdCard /storage/extSdCard ecryptfs rw,seclabel,nodev,relatime,ecryptfs_sig=094f421508772d43,ecryptfs_cipher=aes,ecryptfs_key_bytes=32,ecryptfs_enable_cc,ecryptfs_passthrough 0 0


So I can see I'm using ecryptfs and the sdcard is formatted exfat (yuck, but never mind). I was suspicious about the state of the exfat filesystem, so I followed the top voted answer from this question. fsck.exfat /dev... returns "no errors" so it is happy. I can browse to the sd card in the shell and see the files, but obviously not their contents, so the exfat filesystem appears intact.

So the problem I have is clearly with the ecryptfs layer. My question is therefore:


Is there a fsck-like tool I can run with some actual output to know what is going on for ecryptfs?
Failing that, can I extract from the device the key used to encrypt the sd card files?
If I just wait, will it fix itself? I guess not...


Ideally I'd like to recover those files, however there's nothing in there that's critical. 

Environment: rooted lollipop samsung s5, stock firmware, custom recovery (twrp), busybox, supersu.
Same phone, same problem (except my phone is not rooted), but it eventually resolved itself.

Posting the exact steps I followed in case it helps anyone else:


On first reboot (when the problem first occurred), the phone said it was preparing the device and then after a few seconds it told me the card was safe to remove (but I had not asked to unmount it). Going to the storage menu I had the same experience as the OP above. It just kept saying 'preparing device' and never finished.
Rebooted the device, same again as #1.
Repeated. Left the 'preparing device / checking for errors' message up for about 20 minutes this time but it still never completed.
Connected to computer, enabled USB debugging. Using adb shell command following the advice of OP I found the SD card mount directory was not accessible and I could not unmount it without root.
Rebooted the phone one last time. On initial boot, phone said 'preparing device' and then said 'SD card is encrypted'. I ignored this notification and was able to use adb shell to view the files and copy them to my PC. All files were readable. I then cleared the notification and all was well.


I don't think anything I did was responsible for fixing the problem, but if you follow the same steps then hopefully the same thing will happen for you.