This guide is a collaboration of research when a patched boot image is not easily obtainable. Here you will create your own patch boot image using Magisk and an OTA firmware image.
Beware that modifying your phone may cause instability or may even brick your device. Make sure you are using the correct version of your OTA firmware by checking the version on your device (Indian, Global, EU). If you cannot find the OTA firmware you wish to root, search for the firmware name in your search engine.
IN: Oxygen OS 10.5.12.IN11DA
EU: Oxygen OS 10.5.11.IN11BA
NA: Oxygen OS 10.5.12.IN11AA
Credits
Sam Beckman
GadgetHacks
topjohnwu on Github (Magisk)
geminids14 (payload-dumper)
How to root a OnePlus device with Magisk
Software needed:
OnePlus OTA Firmware
ADB Tools
Python
Payload-Dumper
Make sure bootloader is unlocked in Developer Options.
Whether already rooted or not, take the OTA update on the device. Boot up normally.
Install Python, make sure to check the box to add Python to “Path”
Create folder in the root of the c: drive called “tools”
Extract ADB to the c:\tools folder
Extract the payload-dumper files to the c:\tools folder and rename the folder to “payload”
Open the OTA firmware file using 7zip or other compression software and extract the payload.bin file to c:\tools\payload
Open a command prompt with administrative privileges, navigate to the c:\tools\payload folder and run the following commands:
python -m pip install -r requirements.txt
python -m pip install –upgrade pip (if needed)
python payload-dumper.py payload.bin
When this process is complete, grab the newly extracted boog.img from the output folder and copy it to the OnePlus device
Install Magisk from the Google Play Store and open the app
Click install and “Select and Patch a File” and locate the boot.img copied to the device
Copy the newly created magisk_patched.img file back to the computer in the c:\tools directory
Open a command prompt, navigate to the c:\tools folder and run the following commands:
adb reboot bootloader
fastboot devices (check that your device is listed)
fastboot flash boot magisk_patched.img
Continue normal start when complete
Open Magisk and click the install button and select “Direct install”
Reboot and check root status with a root checker app from the Google Play Store
You should now have root and may reuse this method when the next OTA is released. There may be quicker guides on XDA for maintaining root after installing an OTA if you prefer to search for those yourself.