1

I am trying to encrypt my rooted Nexus 5 (running CyanogenMod 13/Marshmallow).
Here is how I am doing:

  1. With the phone running and connected to USB, make sure that /mnt/asec/ is empty
  2. Long-press the power physical button, this makes the Power off dialog pop up
  3. Long-press the "Power off" option of the pop up, confirm that you want to reboot in Safe Mode
  4. Without starting any app, run adb shell on the computer then su to get root then pkill -KILL daemonsu to kill the SuperSU daemon
  5. Settings > Security > Encrypt phone, confirm
  6. 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: <qeglDrvAPI_eglInitialize:379>: 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?

2

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.

1

I've spend all day with the issue of the never ending encryption (LG Nexus 5, Cyanogenmod 13) and somehow figured out to check the logs and eventually came across this question here on Stack Exchange. @mattelacchiatos hint is a good one, but a little bit complicated. TL;DR I was able to fix this by simply booting into safe mode.

For the record, this is the log of the error I had (same as OP):

01-24 00:15:05.132   871  1170 D CryptdConnector: SND -> {1 cryptfs getfield SystemLocale}
01-24 00:17:05.077   871   910 D CryptdConnector: SND -> {2 cryptfs setfield SystemLocale de-DE}
05-26 20:33:36.401   871   910 D CryptdConnector: SND -> {3 cryptfs setfield SystemLocale en-US}
05-26 20:35:05.696   871  1760 D CryptdConnector: SND -> {4 cryptfs setfield PatternVisible 0}
05-26 20:35:05.697   871  1760 D CryptdConnector: SND -> {5 cryptfs setfield PasswordVisible 1}
05-26 20:35:05.706   871  3096 D CryptdConnector: SND -> {6 cryptfs setfield SystemLocale en-US}
05-26 20:35:06.491   871  3095 D CryptdConnector: SND -> {7 cryptfs enablecrypto inplace default}
05-26 20:35:06.495   150   162 E Cryptfs : Bad magic for real block device /dev/block/platform/msm_sdcc.1/by-name/metadata
05-26 20:35:06.498   150   162 D Cryptfs : Just asked init to shut down class main
05-26 20:35:37.010   150   162 E Cryptfs : unmounting /data failed: Device or resource busy
05-26 20:35:37.140   150   162 E Cryptfs : Bad magic for real block device /dev/block/platform/msm_sdcc.1/by-name/metadata
05-26 20:35:37.145   150   162 D Cryptfs : Just asked init to shut down class main
05-26 20:35:57.212   150   162 E Cryptfs : unmounting /data failed: Device or resource busy

What I did, was the following. Since I tried a lot and wiped/flashed the device around a hundred times, I assume it only works on a clean install of cyanogenmod. Also, I read something about issues with Team Win Recovery Mode (TWRP) and how it formats the partitions. So here is what I did:

  1. Flashed the Cyanogenmod recovery image

    sudo fastboot flash recovery /path/to/cm-13.0-20160418-SNAPSHOT-ZNH0EAO2NM-hammerhead-recovery.img
    
  2. Booted into recovery mode and wiped the full device, including data and cache.

  3. Booted into the bootloder, wait in the boot loader menu and flash the TWRP image

    sudo fastboot flash recovery /path/to/twrp-3.0.2-0-hammerhead.img 
    
  4. Still in the bootloader, go into the recovery mode, twrp this time.

  5. Push the cyanogenmod zip to the phone.

    adb push /path/to/cm-13.0-20160418-SNAPSHOT-ZNH0EAO2NM-hammerhead.zip /sdcard
    
  6. Use twrp to install cyanogenmod from the zip. Do not wipe cache or format data! It's tempting since a button pops up, but I read that there might be issues with malformed partitions. Also, do not reboot yet! Just go back.

  7. Reboot into the bootloader. Don't boot cyanogenmod yet. Make sure you are in the boot loader.
  8. Flash the Cyanogenmod recovery image again.

    sudo fastboot flash recovery /path/to/cm-13.0-20160418-SNAPSHOT-ZNH0EAO2NM-hammerhead-recovery.img
    
  9. Now, boot cyanogenmod, set language, date, time, timezone. Don't change any settings yet, don't connect to wifi.

  10. Press the power button until the Shutdown dialog pops up.
  11. Long press the shut down option until a confirmation dialog comes, which askes you to confirm rebooting into safe mode.
  12. Confirm and reboot into safe mode.
  13. Go to settings and security, hit encrypt phone and confirm encryption, again.
  14. Wait a few minutes. On a clean install, it should not take more than 5-10 minutes on a Nexus 5.
  15. It will reboot into normal mode as soon as it finished. Confirm in security settings the phone is encrypted.

Here's the adb logcat to confirm it worked out:

05-26 21:17:20.694   799   897 D CryptdConnector: SND -> {1 cryptfs getfield SystemLocale}
05-26 21:17:33.095   799  1055 D CryptdConnector: SND -> {2 cryptfs getpw}
05-26 21:17:33.096   149   160 D VoldCryptCmdListener: cryptfs getpw
05-26 21:17:33.097   799  1055 D CryptdConnector: SND -> {3 cryptfs clearpw}
05-26 21:17:33.098   149   160 D VoldCryptCmdListener: cryptfs clearpw
05-26 21:18:42.691   799   981 D CryptdConnector: SND -> {4 cryptfs setfield PatternVisible 0}
05-26 21:18:42.692   799  1637 D CryptdConnector: SND -> {5 cryptfs setfield PasswordVisible 1}
05-26 21:18:42.701   799  1055 D CryptdConnector: SND -> {6 cryptfs setfield SystemLocale en-US}
05-26 21:18:43.476   799   981 D CryptdConnector: SND -> {7 cryptfs enablecrypto inplace default}
05-26 21:18:43.480   149   160 E Cryptfs : Bad magic for real block device /dev/block/platform/msm_sdcc.1/by-name/metadata
05-26 21:18:43.484   149   160 D Cryptfs : Just asked init to shut down class main
05-26 21:18:44.950   149   160 D Cryptfs : unmounting /data succeeded
05-26 21:18:44.951   149   160 I Cryptfs : keymaster module name is Keymaster QCOM HAL
05-26 21:18:44.951   149   160 I Cryptfs : keymaster version is 3
05-26 21:18:44.951   149   160 I Cryptfs : Found keymaster0 module, using keymaster0 API.
05-26 21:18:44.954   149   160 I Cryptfs : keymaster module name is Keymaster QCOM HAL
05-26 21:18:44.954   149   160 I Cryptfs : keymaster version is 3
05-26 21:18:44.954   149   160 I Cryptfs : Found keymaster0 module, using keymaster0 API.
05-26 21:18:45.553   149   160 I Cryptfs : Using scrypt with keymaster for cryptfs KDF
05-26 21:18:46.034   149   160 I Cryptfs : keymaster module name is Keymaster QCOM HAL
05-26 21:18:46.034   149   160 I Cryptfs : keymaster version is 3
05-26 21:18:46.034   149   160 I Cryptfs : Found keymaster0 module, using keymaster0 API.
05-26 21:18:46.035   149   160 I Cryptfs : Signing safely-padded object
05-26 21:18:47.040   149   160 D Cryptfs : Just triggered post_fs_data
05-26 21:18:47.090   149   160 D Cryptfs : post_fs_data done
05-26 21:18:49.091   149   160 D Cryptfs : Just triggered restart_min_framework
05-26 21:18:49.091   149   160 I Cryptfs : Using scrypt with keymaster for cryptfs KDF
05-26 21:18:49.676   149   160 I Cryptfs : keymaster module name is Keymaster QCOM HAL
05-26 21:18:49.676   149   160 I Cryptfs : keymaster version is 3
05-26 21:18:49.676   149   160 I Cryptfs : Found keymaster0 module, using keymaster0 API.
05-26 21:18:49.685   149   160 I Cryptfs : Signing safely-padded object
05-26 21:18:50.297   149   160 I Cryptfs : Enabling support for allow_discards in dmcrypt.
05-26 21:18:50.297   149   160 I Cryptfs : target_type = crypt
05-26 21:18:50.297   149   160 I Cryptfs : real_blk_name = /dev/block/platform/msm_sdcc.1/by-name/userdata, extra_params = 1 allow_discards
05-26 21:18:50.300   149   160 I Cryptfs : Encrypting ext4 filesystem in place...
05-26 21:18:50.300   149   160 I Cryptfs : Encrypting group 0
05-26 21:18:50.301   149   160 I Cryptfs : Encrypting from sector 0
05-26 21:18:50.371   149   160 I Cryptfs : Encrypted to sector 790016
05-26 21:18:50.371   149   160 I Cryptfs : Encrypting from sector 802816
05-26 21:18:50.378   149   160 I Cryptfs : Encrypted to sector 813568
05-26 21:18:50.378   149   160 I Cryptfs : Encrypting from sector 819200
05-26 21:18:50.388   149   160 I Cryptfs : Encrypted to sector 840704
    [...]
05-26 21:19:43.819   149   160 I Cryptfs : Encrypting group 215
05-26 21:19:43.821   149   160 I Cryptfs : Encrypted to sector 3590587392
05-26 21:19:43.821   149   160 I Cryptfs : Encrypting from sector 3607101440
05-26 21:19:43.896   149   160 I Cryptfs : Encrypting group 216
05-26 21:19:43.898   149   160 I Cryptfs : Encrypted to sector 3607364608
05-26 21:19:43.898   149   160 I Cryptfs : Encrypting from sector 3623878656
05-26 21:19:43.971   149   160 I Cryptfs : Encrypting group 217
05-26 21:19:43.974   149   160 I Cryptfs : Encrypted to sector 3624141824
05-26 21:19:43.974   149   160 I Cryptfs : Encrypting from sector 3640655872
05-26 21:19:44.108   149   160 I Cryptfs : Encrypted to sector 3641183744

Good luck encrypting your phone in safe mode!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.