[OnePlus 9] lawhec:
As a OnePlus 9 user who likes to root their phone mainly to allow Network Signal Guru to work (as well as a few other root things like AdAway) I had been trying to extract the boot.img the same way as I had done with a OnePlus 7T using Payload Dumper for Windows. However it looks like Payload Dumper has issues with extracting xx.img files (including boot.img) if the payload.bin file is bigger than 4.3 GB in size. So I've been looking to see if another method was possible that would work for our OnePlus 9 ROMs that are above this file size. As I use Linux Mint as my usual desktop OS & only fall back onto Windows for stuff that'll only run on that OS, I went to have a look to see if something could be done under Linux. Turns out there is an old thread elsewhere on XDA that almost nearly provides what is needed for this, and I thought I would gives details here that should work for the time of this post (March 2023).

This not only extracts the boot.img to patch in Magisk, but also extracts other xx.img files as well.

I'm using Linux Mint 21.1, but I'd assume that this will also work for similar Ubuntu builds or anything that is based on Debian.

Obligatory disclaimer: The following instructions I'm giving below have worked well for me several times in the past, however I am in no way responsible for screwing up or damaging your phone if you try and follow what I've written below. In extreme cases, a bad flash may require using the OnePlus MSM tool to completely reflash your phone. Back up anything important first before doing any of the following!​

1. You will need to ensure that you have downloaded packages to be able to do adb & fastboot from the command line. You can check by running the following commands - if it's already installed with the latest versions, the terminal interface will let you know...

sudo apt install adb

sudo apt install fastboot

2. You will need to go to your software manager in LM21.1 and install both Python 3 & the Python Protobuf compiler. Just search for "Python 3" & "Protobuf-compiler" in the software manager and the first option for each search is what you should need - if they are not installed, install them.

3. Create a read/writable directory that will hold your ROM that you've just downloaded & other files that I'll mention soon. I just use a folder calls "ROM" in my Downloads folder (e.g. /home/lawhec/Downloads/ROM ), but you can choose wherever you want that suits you.

4. If you have not done so already, make sure you have the FULL package of your OnePlus 9 ROM downloaded. As of right now (March 2023) it seems the best way is to download the package using the Oxygen Updater app which is available on Google Play - more info available at oxygenupdater.com - just download the ROM to your phone and transfer it on to your computer into the folder you've created for it.

5. Download and save the following two Python scripts/files ("Right click" & "Save Link As") into the folder you have just created for your ROM (all credit to Gregory Cyxx at github.com/cyxx )...

https://raw.githubusercontent.com/c...payload/master/extract_android_ota_payload.py

https://raw.githubusercontent.com/cyxx/extract_android_ota_payload/master/update_metadata_pb2.py

6. Make sure in your file browser (Nemo in my case as it is the default for LM21.1 Cinammon, yours may differ) the window is open in the ROM folder that contains the two Python scripts above that you've just downloaded as well as a ROM package (ZIP file) you've downloaded (in my case from Oxygen Updater mentioned in step 3). Create a new folder for the extracted images to be written to - in my case I just call the folder "output" which is located at "/home/lawhec/Downloads/ROM/output" but again you can call it what you wish.

7. After you've created your output folder, in your ROM directory in the file manager window right-click on your mouse in a white or free space and select "Open in Terminal" - a command terminal will pop up defaulting to your directory.

8. In the command terminal, type the following command and press enter/return...

sudo python3 extract_android_ota_payload.py <<Your ROM.zip>> <<Your Output Directory>>

...for example, in my case the command would be either...

sudo python3 extract_android_ota_payload.py LE2113_11_F-75.zip output

...or for handiness you can type "sudo python3 extract_android_ota_payload.py " (remember to leave a space) and simply drag the ROM zip file to the command terminal, press space and then drag the output foler to the terminal line, which will look like in my case...

sudo python3 extract_android_ota_payload.py '/home/lawhec/Downloads/ROM/LE2113_11_F-75.zip' '/home/lawhec/Downloads/ROM/output'

...this will now run the python script you downloaded earlier that will begin extracting the ROM you've specified and will output all relevant xx.img files into your output folder, including the one we want, "boot.img" - there is no need to extract paylod.bin beforehand, the script will automatically do this for you. Once all xx.img files have been extracted the script will stop, depending on your computer this will take anything from 1-5 minutes, maybe longer on some very old or low spec'd computers - but just let it run its course. Once it is done you can then close the terminal window.

9. Now with the boot.img we've extracted, transfer this file on to your phone (the Downloads folder is usually a good choice). Now open Magisk and patch the boot.img file - once this has been completed, it'll generate a patched boot.img file named something like "magisk_patched-25200_12345.img" - copy and paste this patched boot image back on to your computer (into the folder you've been using will be fine here).

10. If your OnePlus 9 phone is connected to your computer via USB cable, disconnect it now. Then shutdown your phone into a power-off state then reboot it into fastboot mode - this can be done by holding down the volume up & down buttons, then holding down the power button and keep holding down all three buttons until you feel a vibration from your phone. Your OnePlus 9 should then boot into fastboot mode.

11. Now reconnect your OnePlus 9 to your computer via the USB cable and then open up a new display terminal (preferably by right-clicking in the file window of the directory where you saved your Magisk patched boot.img file). Enter the following...

fastboot devices

...you should then get a line featuring a block of numbers that should match the serial number that is displayed on your phone's display, followed by "fastboot", for example...

85f53405 fastboot

...if you get anything else, double check your connections at try again - if more than one device is displayed, disconnect the and try again to make sure that only one device is listed. It might also be the case that you don't have the proper drivers installed on your computer for your phone though in my case LM21.1 automatically recognises my phone, so I'm not of any direct help here I'm afraid for this, sorry.

12. Now you will be flashing your patched boot.img to your phone - this is where things can be a little nervous though as long as you do everything right nothing should really go wrong. Type the following into the command terminal, assuming you did so by opening a command terminal from the folder your Magisk Patched boot.img file is located...

fastboot flash boot <<Magisk Patched boot.img>>

...for example in my case the command line would be...

fastboot flash boot magisk_patched-25200_12345.img

...otherwise you will need to provide the location of where your patched boot.img is, so in this case...

fastboot flash boot '/home/lawhec/Downloads/ROM/magisk_patched-25200_12345.img'

...either way, your phone will now be in the process of getting its boot image replaced with the one patched by Magisk. This should take no more than a few seconds and that should be it done! You can then close the terminal window again.

13. Once you've patched the boot image, disconnect the phone from the USB cable to the computer and make sure that the screen on your mobile says "START" in green at the top, if it doesn't, use the volume keys to change this. Then just simply press the power button and your phone will now reboot, this can take a little bit longer than before as your phone's firmware has changed so give it time - (however if it takes longer than 10 minutes or so you might have a problem here) - once your home screen becomes available, give it a few seconds once you've entered before selecting the Magisk app. Once you've done this, Magisk should say that it is installed however to double check, use an app that requires root permissions either to work (e.g. Network Signal Guru) or to do additional things, like a simple root checker app that you can download from wherever you download your apps. If everything is good, then you've rooted your OnePlus 9!

Notes: This process will probably work for other firmware packages for various phones where the boot.img can be extracted to be patched by Magisk and then flashed via fastboot (assuming the bootloader is unlocked) which includes the OnePlus 7T's stock firmware, but I can give no guarantees for this. Once again, try at your own risk.​