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:
Flashed the Cyanogenmod recovery image
sudo fastboot flash recovery /path/to/cm-13.0-20160418-SNAPSHOT-ZNH0EAO2NM-hammerhead-recovery.img
Booted into recovery mode and wiped the full device, including data and cache.
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
Still in the bootloader, go into the recovery mode, twrp this time.
Push the cyanogenmod zip to the phone.
adb push /path/to/cm-13.0-20160418-SNAPSHOT-ZNH0EAO2NM-hammerhead.zip /sdcard
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.
- Reboot into the bootloader. Don't boot cyanogenmod yet. Make sure you are in the boot loader.
Flash the Cyanogenmod recovery image again.
sudo fastboot flash recovery /path/to/cm-13.0-20160418-SNAPSHOT-ZNH0EAO2NM-hammerhead-recovery.img
Now, boot cyanogenmod, set language, date, time, timezone. Don't change any settings yet, don't connect to wifi.
- Press the power button until the Shutdown dialog pops up.
- Long press the shut down option until a confirmation dialog comes, which askes you to confirm rebooting into safe mode.
- Confirm and reboot into safe mode.
- Go to settings and security, hit encrypt phone and confirm encryption, again.
- Wait a few minutes. On a clean install, it should not take more than 5-10 minutes on a Nexus 5.
- 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!