[Essential Phone Guides, News, & Discussion] bmg1001:
WARNING: Before attempting to root your device, do note that by unlocking your bootloader and modifying your device with root, ROMs, etc... you are risking voiding your warranty! I am NOT responsible for what you do to your device either, so follow these instructions at your own risk. Make sure you know what you're doing, it's best to understand the process rather than just copy and paste commands and such.

Useful and important general information can be found in the second post here.

NOTES

1. If you flash the TWRP Installer when you've already got Magisk installed, your device will keep booting to the recovery. You should be able to fix this by just simply reflashing Magisk.

2. If you have TWRP installed via the TWRP Installer, you will not be able to install stock OTA updates. You will have to reflash the stock boot image for whatever build you're running beforehand.

3. The prebuilt TWRP image may not have touch functionality if you're using the September 2018 Update or newer. Patching the boot image, however, for these builds with the TWRP Installer will allow touch to work flawlessly. Here is a pre-patched September 2018 Boot Image with TWRP. It should also work with builds newer than September. Since it's based off the September 2018 update, I suggest not using this as your main boot image but rather just as a replacement for the pre-built TWRP image from the official TWRP thread.

4. Simple "flash and forget" boot images pre-patched with Magisk and TWRP are provided by @aer0zer0 and are available here. They are based on ianmacd's variant of Magisk. If you are running stock, you can flash these boot images to get root and TWRP instead of following the guide to patch it yourself. Here is January's.

If you don't care about TWRP and simply want to just root your device, you can just simply patch the boot image for your ROM with the Magisk Manager and flash it in fastboot with

fastboot flash boot patched_boot.img

The link to the boot images for most stock builds can be grabbed from my Google Drive link in the second post or from the back-to-stock zips.

REQUIREMENTS

An unlocked bootloader

Working adb and fastboot environment, along with knowledge on how they work.

The latest build of TWRP along with the TWRP Installer.

Read Note 3 above beforehand.

1. Download the latest build of TWRP and the TWRP Installer. Transfer the TWRP Installer zip to your device.

2. Reboot your phone into fastboot. Once in fastboot, change your device's current slot using the command

fastboot set_active other

If the command above doesn't work for you, use fastboot getvar current-slot followed by fastboot -aX, replacing "X" with the slot opposite (a or b) from your current slot.

3. Once your device's current slot has been switched, flash the TWRP image you downloaded earlier using the command

fastboot flash boot twrp.img

Depending on your version of fastboot, the above command might not work either. In that case, you can enter the following command, replacing "X" with your current slot (a or b).

fastboot flash boot_X twrp.img

4. Once TWRP has been flashed, boot into the recovery.

5. Once you have booted into TWRP, simply flash the TWRP Installer zip.

6. Once you have finished flashing the TWRP Installer zip, boot to recovery on the OPPOSITE slot. You can do this from TWRP by going to "Reboot", then selecting the opposite of the current slot (if on A, select Slot B. If on B, select Slot A), then select "Recovery." You can also do this through fastboot by running the same command from step 2.

7. Once you have booted back into TWRP, simply flash the Magisk zip and you are now good to go! Feel free to flash anything else like kernels while you're at it.

8. Reboot. :good:

NOTE: TWRP

WILL

remain installed on your device so long as you reflash the installer zip after every update.