I was trying to encrypt my Xiaomi Redmi 5 Plus (Settings -> Security & location -> Encryption & credentials -> Encruypt phone). I was not successful as I was hitting LineageOS bug.
Encryption did not finish, display just went black and returned back to lock screen.
In the output of adb logcat command was:
01-10 22:05:33.655 445 7908 E Cryptfs : Bad magic for real block device /dev/block/bootdevice/by-name/userdata
01-10 22:05:33.656 445 7908 E Cryptfs : Orig filesystem overlaps crypto footer region. Cannot encrypt in place.
How to fix it:
- On the phone go to Settings -> About phone and click on Build number multiple times until you enable developer options.
- On the phone go to Settings -> System -> Advanced -> Developer options and enable Root access and Android debugging.
- Turn off the phone. Then press Volume Up and Power buttont to get into Recovery.
- Connect the ohone to computer via USB cable. On the computer run adb shell command.
- Mount system partition by running command
mount /dev/block/bootdevice/by-name/system /system
- Check filesystem:
- Find out Block count for the partition we are going to resize:
tune2fs -l /dev/block/bootdevice/by-name/userdata | grep 'Block count:'
# tune2fs -l /dev/block/bootdevice/by-name/userdata | grep 'Block count:'
Block count: 6273913
- Subtract 4 from Block count and use result in resize command for the partition.
# /system/bin/resize2fs /dev/block/bootdevice/by-name/userdata 6273909
resize2fs 1.43.3 (04-Sep-2016)
Resizing the filesystem on /dev/block/bootdevice/by-name/userdata to 6273909 (4k) blocks.
The filesystem on /dev/block/bootdevice/by-name/userdata is now 6273909 (4k) blocks long.
- Reboot the phone and start phone encryption again.
If you have any questions regarding this, feel free to contact me at my e-mail address.