After flashing TWRP, device no longer boots I just got a device running Android 7.1.1 (an BQ Aquaris X5 Plus to be precise). Fine device, and all – unlocking the bootloader was as easy as enabling bootloader unlock in settings, and running fastboot oem unlock. As I like complete backups and other features custom recoveries provide, I flashed twrp. Woked fine, could boot into it – but then, the device no longer boots up into Android itself – it simply gets stuck on the boot screen.

Things I've tried:


wiping /cache and /data (via TWRP's advanced wipe)
performing a factory reset via TWRP


No dice. What could that be, and how to solve the issue?
Searching the web gave me a clue: While before Android 7 one could easily flash a custom recovery without fearing side-effects, starting with Android 7 the system enforces DM Verity. That is, at a very early stage in the boot process, the system checks whether any partition was "tampered" with – which in my case meant the /recovery partition. As far as I could figure, in such a case a warning should be shown to the user and asked whether to continue anyway. In my case, there was no such thing.

So what to do to fix it? Actually, it is the boot image requiring a fix – namely, the verify option must be removed from the entries of affected partitions. The following options exist for this:


adb disable-verity is mentioned, but it isn't a good solution because it cannot be issued in TWRP and it requires the ROM to be a userdebug build or an engineering build (it doesn't work on user builds).
Manually disabling dm-verity in the boot.img describes how to modify the boot image (i.e. change the fstab file removing the verify option). That requires extracting the boot image, modifying it, repacking it, flashing it back. Can be done using SuperR's Kitchen – which is available for Linux, Mac and Windows. Should definitely work, but is quite a bit of work itself.
LazyFlasher offers a flashable ZIP (no-verity-opt-encrypt-6.0.zip) which should do the trick. Should be fine for those who want avoid to root their device for one reason or the other. It will disable forced encryption along.
Flashing SuperSU did the trick for me: SuperSU detected that DM-Verity was active, extracted the boot image, patched it accordingly, and flashed back the patched version – which then also includes SuperSU itself.


So after flashing SuperSU, the device booted up normally again – issue solved for me. You might chose one of the other approaches (feedback welcome then).

Note that these two (SuperSU and LazyFlasher) are just examples. As iBug correctly points out, "SuperSU is dead" – so you'd better use Magisk, which in this context does the same: flashing itself systemlessly and disabling DM-Verity.