[Xiaomi Mi A2 / 6X Guides, News, & Discussion] Nebrassy:
Flashing for Dummies

In this guide we'll go over how to flash custom ROMs with root and TWRP in addition to updating

this guide will always be updated

Read the ENTIRE guide before you start

Your warranty is now void.

We are not responsible for bricked devices, bootloop... Please
do some research if you have any concerns about mods
included in these GUIDES before using them! YOU are choosing to
make these modifications.

things to keep in mind:

1- when you flash a ROM through TWRP, it will flash to your inactive slot, that's why you need to switch slot after flashing it and then flash everything else, think of it like an OTA update except you need to switch active slot yourself

2- when you change your active slot in TWRP, it will only change after you reboot, your active slot will always be the one you're currently booted on

3- the order of flashing anything that modifies boot is

1) TWRP

2) custom kernel

3) noverity

4)Magisk

if you're not sure, flash stock boot of your rom and do it again, flashing TWRP will break Magisk, flashing a custom kernel will break magisk, flashing TWRP after flashing a custom kernel will most likely get you a bootloop

Before you begin

you need to unlock your bootloader first https://xdaforums.com/mi-a2/how-to/unlock-bootloader-n-root-magisk-easy-t3856800

It is no longer required to be on stock Oreo before flashing, but I currently still recommend you do so as there might be some minor bugs on some custom roms, but otherwise everything will work just fine.

get latest platform-tools if you haven't already, using an older one WILL result in errors

platform-tools

extract it and open the folder

hold shift then right click on an empty space then click "open command window here"

if you're on windows 10, doing that will open power shell instead, inside power shell, type "cmd" and press enter, use cmd for everything below

if you're coming from stock, you need to do this first

type the following command (data and files will be wiped)

fastboot -w
fastboot set_active b

Notes:

Pixel Experience includes Gapps, do not flash them after the rom

many roms include TWRP, such as Havoc, AICP and many others, check ROM thread first, if it includes it then don't flash TWRP.

Flashing custom ROMs and other stuff

download latest TWRP img and zip from https://twrp.me/xiaomi/xiaomimia2.html and place it in the same folder you extracted platform-tools to

NOTE: if you are on stock then use TWRP 3.2.3 img, not 3.3

note: if you're having issues with official TWRP, I've built an unofficial one with F2FS support which you can try here

be careful if you switch to F2FS, it will only work with a recovery that supports it and a ROM that supports it, no stock.

rename the img to twrp.img

in cmd, type

fastboot boot twrp.img

if you get a bootloop, force shutdown (power + volume down) and try again

using MTP copy the files needed to flash to your phone

if MTP doesn't work, you have the following options

1) wipe data from TWRP, try again

2) advanced > file manager, go to /data/media , if there is nothing in there, create a new folder called 0 there by going to Advanced > Terminal and typing the following commands

cd /data/media
mkdir 0

then reboot to bootloader and try again

3) try using PBRP for MTP, then go back to TWRP PBRP

4) use adb sideload:

in TWRP, go to Advanced > adb sideload, then on PC

adb sideload file.zip

do that for each thing you want to flash

(you can type adb sideload then drag and drop the file you want to flash onto cmd, make sure there's a space between sideload and the file you want to flash)

5) use adb push. follow methode 2 to create the folder, then in cmd, type this command

adb push file.zip /data/media/0/

do that for each file you need

after you got the files on your phone, it's time to flash

remember that when flashing a ROM, it will flash to your inactive slot, in this guide I'll assume your active slot is B, use "fastboot set_active b" in fastboot if you'd like to follow along

First go to wipe > advanced and select System and Data then wipe, then you can start flashing

1- flash the ROM zip

2- flash TWRP zip, so you can boot to TWRP without the need of a PC (ONLY if the ROM doesn't include it already)

3- switch your active slot (to A if you are on B and to B if you were on A)

4- reboot recovery

5- flash Gapps if required by the ROM you're flashing, Opengapps nano is recommended, you can get it here http://Opengapps.org

6- (optional) flash a custom kernel if desired/needed

7- (optional) flash DM-VERITY & FORCEENCRYPT DISABLER zip , this will disable DM verity and encryption in vendor, this is not required by most custom ROMs as they will disable encryption anyway, it is most useful on stock, and in the possibility that the ROM you're flashing does not disable encryption

8- flash Magisk

9- reboot to system

IMPORTANT, if you get an error while flashing ROM zip, do the following

use latest official TWRP, if you're already using it, then the ROM you're flashing is one of the older ROMs

previously, ROMs and TWRP used Jasmine as a codename for our device, while the real codename is Jasmine_sprout, this caused some issues, newer ROMs and TWRP now use the correct codename, but that means new TWRP can not flash older ROMs, and so you will need some simple modifications to the ROM zip:

1- open the ZIP using WinRAR on PC or X-plore on phone

2- go to META-INF/com/android/metadata and open it as text

3- on the last line, edit 'pre-device=jasmine' to 'pre-device=jasmine_sprout'

4- save it and try flashing again

Switching between custom ROMs

follow the same flashing instructions, you can boot directly to TWRP by holding power + volume up, wipe data and system first then flash ROM and the rest.

Updating Custom ROMs

For OFFICIAL ROMs which support A/B OTA it's very easy

1- once you get a notification that an update is available, download and install with the system updater but don't reboot (If the ROM includes TWRP then don't do any of the following steps, just reboot)

2- go to Magisk, Downloads, search for "TWRP A/B Retention Script" and install it

3- on the main Magisk page, click install > install > Install to Inactive Slot (After OTA)

4- once Magisk finishes, reboot, you will now be on the opposite slot with both Magisk and TWRP installed.

for Unofficial ROMs with no OTA or Official ROMs that don't support A/B OTA, you'll need to use TWRP, do not wipe anything:

1- boot to TWRP

2- flash the ROM zip

3- flash TWRP zip (ONLY IF the ROM doesn't include TWRP)

4- switch your active slot (to A if you are on B and to B if you were on A)

5- reboot recovery

6- flash Gapps if required by the ROM you're flashing, Opengapps nano is recommended, you can get it here http://Opengapps.org

7- (optional) flash a custom kernel if desired/needed

8- (optional) flash DM-VERITY & FORCEENCRYPT DISABLER zip , this will disable DM verity and encryption in vendor, this is not required by most custom ROMs as they will disable encryption anyway, it is most useful on stock, and in the possibility that the ROM you're flashing does not disable encryption

9- flash Magisk

10- reboot to system