Root Android Devices with Magisk

Daniyal Shahzad
5 min readNov 9, 2022

--

In this blog I will be discussing about rooting Android (the latest versions). Some Android devices are easy to root such as Pixel devices and some devices are very hard to root or even don’t allow rooting. I will be rooting a Pixel device in this tutorial while giving some idea how to root other android devices and restoring them to their original factory images.

WARNING!! Please make sure backup your all important data from your phone.

What you will need:

  1. Android Device which you want to root
  2. Factory Image or OTA Update file
  3. Magisk apk
  4. TWRP Recovery
  5. SDK Platform Tools

Procedure:

First of all we need to unlock the bootloader for our device. Some vendors allow bootloader unlocking and some don’t. Some vendors require you to purchase the unlocking key so then you can unlock your device. See the unlocking method according to your device on XDA-Developers forum.

Go to your device “settings”, then locate “about phone”.

About Phone in settings

Now find build number and tap on it 6–7 times to unlock “developers options”. If you have a screen lock set up on your device it will require you to enter your Pin or whatever you are using.

Build number Shows the system update currently installed on your device

Once done, go back and you will see new menu under “System” named “Developer Option”. Open this menu and you will see a lot of settings there, here we are interested in “OEM Unlocking” option and “Usb debugging”.

Developer Options has a lot of other features for developers

Enable both of these options.

Now, download Magisk apk from its official github repository and install it on your device. Now download the official firmware for your device. If you find factory image extract it and you will find another zip file in it. Open that file and extract boot.img file from it. If you don’t find factory image for your device download the OTA update file (if your vendor doesn’t provide it, Google is your best friend) once downloaded, extract payload.bin file the OTA and download payload-extractor from here and extract boot.img file using this tool. Transfer the boot.img to your phone. Now open magisk and select install, then select “Patch a image file” then locate your boot.img file and select it. Magisk will patch the boot.img file for you and save it to Downloads folder copy patched magisk boot.img file from your phone to your pc and reboot your device to bootloader

user@localhost$ adb reboot bootloader

Once you are in bootloader use this command to unlock your bootloader

user@localhost$ fastboot flashing unlock

or sometimes

user@localhost: fastboot oem unlock

Use Volume buttons to switch between options and power button to select the option. This will wipe all the user data from your device. Setup your phone again and install magisk.apk again otherwise root will not be detected. Reboot your device again to bootloader (You can enable developer options again if you want). Now enter

user@localhost$ fastboot flash boot Magisk_patched_boot.img

If you are not sure whether your device will be rooted correctly or not you can always test your patched boot.img for that use

user@localhost$ fastboot boot Magisk_patched_boot.img

If your device booted successfully and everything is working fine reboot your device to bootloader and use the fastboot flash command so it will permanently root your device.

What If???

Now sometimes you may not find the factory image or OTA update file for your device what you should do in that situations?
HOLD ON!!! I got your back. That is why I mentioned TWRP in the start. Download TWRP for your specific device from the source I mentioned in the start. Once you have downloaded TWRP.img file place it on your computer. Once you have done this download magisk.apk too to your PC. Now, here is a trick rename magisk.apk to magisk.zip and transfer it to your phone and connect your device and reboot it in bootloader. You can do it either by using power and volume buttons combination (may differ from device to device so look accordingly) or the simplest way is to use adb command.

user@localhost$ adb reboot bootloader

Once you are in bootloader enter this command to boot twrp

user@localhost$ fastboot boot twrp.img

You will be booted into TWRP custom recovery if you had a password on your phone enter the password and you will see a menu like this:

image from: https://commons.wikimedia.org/

select install and now locate magisk.zip you placed in your phone. Select the magisk.zip. You will now see a screen like this

Now swipe the blue button across the bar and you are good to go once the process is complete. Simply restart your phone. First make sure that you have already installed magisk.apk (magisk manager) in your phone before doing this process otherwise your root will not be detected

If your phone doesn’t have a TWRP recovery too. Don’t lose hope there are still methods available but those methods are very tricky and you might end up hard bricking your phone. I will discuss those methods too but you have to take the risk.

Thanks.

--

--