How to encrypt the Android /data partition if it only makes a quick reboot.

How to encrypt the Android /data partition if it only makes a quick reboot

Miguel Menéndez Comments

After installing a new custom ROM I tried to encrypt the mobile. However, the process fails without displaying any error message, the device simply makes a quick (or soft) reboot.

Reviewing the error log with the adb logcat command, I find the following:

E Cryptfs: Bad magic for real block device /dev/block/bootdevice/by-name/userdata
E Cryptfs: Not a valid ext4 superblock
Orig filesystem overlaps crypto footer region. Cannot encrypt in place.

Apparently, the userdata partition, mounted on /data, is correctly formatted with the ext4 file system … After two days trying several unsuccessful options, I find this thread in the XDA Developers forum and I read that TWRP 3.2 and later versions including the current one (3.3.1-0 at the time of writing this) is not formatting the /data partition correctly.

Thus, the solution will be to install a version of TWRP prior to 3.2 to format the /data partition and, subsequently, install the latest version of TWRP to install the desired ROM (without formatting /data):

Example

1. I visit the official TWRP page and select my device, in this example a Xiaomi Redmi 4A (rolex).

2. In the section «Download links» I select one of the mirror servers (America or Europe) and I download:

2A. The TWRP version immediately prior to version 3.2.1-0, that is, the 3.1.1-1 of 11/27/2017 (twrp-3.1.1-1-rolex.img) and

2B. The latest version available (or the version suitable for installing the desired ROM), in this example version 3.3.1-0 of 05/21/2019 (twrp-3.3.1-0-rolex.img).

3. I restart the mobile in Bootloader mode (holding down the volume down button).

4. I install TWRP 3.1.1-1:

~$ sudo -i
~# fastboot flash recovery twrp-3.1.1-1-rolex.img

5. I restart the mobile this time in Recovery mode:

~# fastboot reboot recovery
If this does not work: Press and hold the power button and the volume up button for at least 10 seconds.

6. Once in TWRP 3.1.1-1, format the partition data.

7. I restart in Bootloader mode again and now I install the current version of TWRP:

~# fastboot flash recovery twrp-3.3.1-0-rolex.img

8. Restart the mobile again in Recovery mode:

~# fastboot reboot recovery
If this does not work: Press and hold the power button and the volume up button for at least 10 seconds.

9. Once in TWRP 3.3.1-0, I install the desired ROM normally, making the corresponding previous and subsequent wipes. Always without formatting the data partition!

10. I reboot the mobile and I proceed to encryption.

Source: XDA Developers Forum.

Image: Freepik based.