[Xiaomi Mi A1 Guides, News, & Discussion] Deleted member 4665219:
Device will be wiped if your bootloader isn't already unlocked.

Obviously, before doing this, you should enable OEM unlocking and ADB debugging in Developer Options. Also you should have ADB and Fastboot on your system (meaning they work on any directory). I use this version, just accept the installation of both the ADB/Fastboot drivers and the Google Device Drivers and you should be good to go.

Below you can find the untouched boot.img for the version you are on (or you can extract them yourselves, guide at the bottom of the thread):

2018:

March (V9.5.9.0.ODHMIFA) (OTA)

April (V9.5.10.0.ODHMIFA) (OTA)

May (V9.5.11.0.ODHMIFA) (OTA)

June (V9.6.2.0.ODHMIFE) (OTA)

June (V9.6.3.0.ODHMIFE) (OTA)

July (V9.6.4.0.ODHMIFE) (OTA)

August (V9.6.5.0.ODHMIFE) (OTA)

September (V9.6.6.0.ODHMIFE) (OTA)

October (V9.6.7.0.ODHMIFE) (OTA)

November (V9.6.8.0.ODHMIFE) (OTA)

December (V10.0.3.0.ODHMIFE) (OTA)

2019:

January (V10.0.4.0.ODHMIFE) (OTA)

January (V10.0.4.0.PDHMIXM) (OTA)

February (V10.0.5.0.PDHMIXM) (OTA)

March (V10.0.7.0.PDHMIXM) (OTA)

April (V10.0.8.0.PDHMIXM) (OTA)

May (V10.0.9.0.PDHMIXM) (OTA)

June (V10.0.10.0.PDHMIXM) (OTA)

July (V10.0.11.0.PDHMIXM) (OTA)

August (V10.0.12.0.PDHMIXM) (OTA)

September (V10.0.13.0.PDHMIXM) (OTA)

October (V10.0.14.0.PDHMIXM) (OTA)

November (V10.0.15.0.PDHMIXM) (OTA)

December (V10.0.16.0.PDHMIXM) (OTA)

Here we go:

GENERATING THE PATCHED BOOT.IMG

0. Download a suitable UNTOUCHED boot.img from above or extract one yourself by using the OTA links and dumping the image using the guide on the bottom of this thread.

To check which one is suitable for you go to Settings -> System -> About phone and check your build number. (e.g September 2019 one should be PKQ1.180917.001.V10.0.13.0.PDHMIXM)

1. Install Magisk Manager

2. Open the app and press Install on the prompt (It should prompt you to install the latest version).

3. Tap on Install on the prompt and then "Patch Boot Image File".

4. Select the untouched boot.img through your File Explorer. Wait for it to do its thing.

The patched_boot.img was created and it should be located at /storage/emulated/0/Download/patched_boot.img.

UNLOCKING THE BOOTLOADER

1. Move the patched_boot.img to your PC

2. Connect the device to your computer and open a Command Prompt

3. Check that ADB works with:

adb devices

Should say:

XXXXXXXXXXXX device

where the X's are a unique ID.

4. Boot into fastboot mode with:

adb reboot bootloader

(Yes you can obviously boot into bootloader by using Volume Down+Power Button etc)

5. You should be in fastboot mode. Check that it works properly:

fastboot devices

Should say:

XXXXXXXXXXXX fastboot

The device will be wiped after the next step.

6. Now we are going to unlock the device's bootloader with:

fastboot oem unlock

7. At this point the device is unlocked. Now do:

fastboot reboot

And let the phone boot

8. After booting, go into fastboot mode again with:

adb reboot bootloader

BOOTING INTO THE PATCHED IMAGE AND INSTALLATION

You should now be in fastboot mode from the last section.

1. Boot into the patched_boot.img that you generated earlier with:

fastboot boot patched_boot.img

The phone should boot normally and shouldn't take too long. For me it was the same boot time as always.

2. Now open Magisk Manager and press Install

3. When prompted tap onto Install and then choose "Direct Install (Recommended)"

Let it do its thing and then choose Reboot.

You should now have a rooted phone with Magisk without using TWRP.

Do not relock your bootloader or your device probably won't boot because you are rooted.

PAYLOAD DUMPING

Requirements: python3, protobuf (do python -m pip install protobuf after having installed python3)

1. Download the desired OTA (full OTA needed, not incremental ones, should probably be 1GB+)

2. Download the zip of the python script on github

3. Extract the script (both .py's) and inside the folder extract the payload.bin from the OTA archive

4. Now run:

python payload_dumper.py payload.bin

Wait for it to be done and you should have all the images in the same directory. With those, you can either just use the boot.img or even create a fastboot flashable OTA with a script.

Cheers!