Cryptfs : unmounting /data failed: Device or resource busy I am trying to encrypt my rooted Nexus 5 (running CyanogenMod 13/Marshmallow).
Here is how I am doing:


With the phone running and connected to USB, make sure that /mnt/asec/ is empty
Long-press the power physical button, this makes the Power off dialog pop up
Long-press the "Power off" option of the pop up, confirm that you want to reboot in Safe Mode
Without starting any app, run adb shell on the computer then su to get root then pkill -KILL daemonsu to kill the SuperSU daemon
Settings > Security > Encrypt phone, confirm
The phone reboots, from the computer type adb logcat


Here is what I see:

I ServiceManager: service 'drm.drmManager' died
D libEGL  : loaded /vendor/lib/egl/libEGL_adreno.so
D libEGL  : loaded /vendor/lib/egl/libGLESv1_CM_adreno.so
D libEGL  : loaded /vendor/lib/egl/libGLESv2_adreno.so
I Adreno-EGL: &lt;qeglDrvAPI_eglInitialize:379&gt;: QUALCOMM Build: 09/02/15, 76f806e, Ibddc658e36 
E BootAnimation: couldn't find audio_conf.txt
W BootAnimation: Audio service is not initiated.
D BootAnimation: Use save memory method, maybe small fps in actual.
D BootAnimation: Use save memory method, maybe small fps in actual.
E Cryptfs : unmounting /data failed: Device or resource busy
E Cryptfs : Bad magic for real block device /dev/block/platform/msm_sdcc.1/by-name/metadata
W vold    : type=1400 audit(0.0:19): avc: granted { read } for name="mmcblk0p28" dev="tmpfs" ino=6735 scontext=u:r:vold:s0 tcontext=u:object_r:userdata_block_device:s0 tclass=blk_file
W vold    : type=1400 audit(0.0:20): avc: granted { read open } for name="mmcblk0p28" dev="tmpfs" ino=6735 scontext=u:r:vold:s0 tcontext=u:object_r:userdata_block_device:s0 tclass=blk_file
W vold    : type=1400 audit(0.0:21): avc: granted { ioctl } for path="/dev/block/mmcblk0p28" dev="tmpfs" ino=6735 ioctlcmd=1260 scontext=u:r:vold:s0 tcontext=u:object_r:userdata_block_device:s0 tclass=blk_file
D Cryptfs : Just asked init to shut down class main
W vold    : emulated unmount requires state mounted 
E Cryptfs : unmounting /data failed: Device or resource busy
W SocketClient: write error (Broken pipe)
W SocketClient: Unable to send msg '200 8 -


At that point the CyanogenMod loading screen keeps animating for 10+ hours and probably forever if I don't stop it. Pressing the Power physical button for 5 seconds makes it reboot and start normally this time. Obviously encryption has not been performed.

I tried the whole procedure twice.

What could be causing this Cryptfs : unmounting /data failed: Device or resource busy problem?
As I've found in this bug report, you can watch the current open files by running this command in a second shell:

while true; do lsof | grep /data; sleep 0.2; done


This checks every 0.2s which files are still in use on /data. In my case it was chainfire's SuperSU, which had a logfile opened.

Additionally, I've found out that a 2nd SDCard partition was mounted to /data/sdext2:

mount | grep "/data"


This was due to an app "Link2SD". With this command I was able to figure out, where the mounting happens:

adb shell
# make system partition writable
mount -o remount,rw /system
grep -R "/data/sdext2" /system


I've commented the "mount" commands out and restartet my phone. Now encryption works fine.