I finally managed to encrypt my Samsung Galaxy Tab S2 using LineageOS with microG. When I was trying to encrypt my tablet via the interface, I had the little droid for an instant, and then the tablet was restarting without being encrypted.
Here is how I fixed it - please make sure that you understand the commands if you want to do the same!
Identifying the issue
First, using adb shell, or using the terminal app that you can activate in the Developer options, write the log into a file:
On the computer:
$ adb logcat -d > logcat.txt
On the device itself:
# logcat -d -f logcat.txt
Then, try to encrypt your phone/tablet, so that it fails. Retrieve the lines of the logfile that contain Cryptfs:
cat logcat.txt | grep Cryptfs 02-02 10:12:29.919 362 9954 E Cryptfs : Bad magic for real block device /dev/block/bootdevice/by-name/userdata 02-02 10:12:29.919 362 9954 E Cryptfs : Orig filesystem overlaps crypto footer region. Cannot encrypt in place.
If you have these error, the following instructions should be helpful. As stated in this issue, this error is caused by the fact that the data partition takes all the space possible, but Android needs 16KB to perform the encryption. We’re going to reclaim these 16KB now.
Resize the data partition
Reboot your phone or tablet in recovery. You will need a console access, I personally use TWRP which provides it in Advanced -Terminal. First, make sure the data partition is mounted and write down its filesystem and its size:
# df Filesystem 1K-blocks Used Available Use% Mounted on ... /dev/block/mmcblk0p39 60899744 546144 60353600 1% /data ...
If you don’t find the data system (i.e. there is no line with a filesystem mounted on /data), go back in the TWRP interface and mount it.
Now that we have this information, we can unmount the data partition in the TWRP interface and we’re going to first check and possible repair the filesystem, a required step before resizing it:
# e2fsck -f /dev/block/mmcblk0p39
Follow e2fsck’s instructions to fix the eventual errors in your filesystem, at the end your filesystem should be clean. Finally, let’s resize the data partition. The size of the data partition should be shrinked by 16KB, so just substract 16 to the original size that was displayed by df. In my example: 60899744 - 16 = 60899728.
# resize2fs /dev/block/mmcblk0p39 60899728K
You should now be able to reboot on the system, and run the LineageOS encryption.