# Device rooting

![](https://3928478158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjMjdRXwO33Lfo7uCpl6%2Fuploads%2Fgit-blob-8c5d6ef24ae54759175052b237351dccf0432770%2Fmapt.png?alt=media)

## Technical guide

All the following phases are applicable for devices with AB layout (e.g. all the pixels) and were tested on a Google Pixel 6a.

* Enable the **Developer Options** and the **USB Debugging** on the device.
* Identify device and partition layout (A/B vs A-only)

  ```shell
  adb shell getprop ro.build.ab_update    # "true" means A/B
  adb shell getprop ro.product.device     # device codename
  ```

  If A/B, you will often patch the boot image and flash it back (no custom recovery needed on some devices). If A-only, you commonly flash a custom recovery (TWRP) then flash Magisk.

  ![](https://3928478158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjMjdRXwO33Lfo7uCpl6%2Fuploads%2Fgit-blob-bc9999367ebaa822d68c2bd0704ecd61e46223d3%2Fos_type.png?alt=media)
* Install the latest **Magisk** version from [here](https://github.com/topjohnwu/Magisk/releases/) on the mobile device:

![](https://3928478158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjMjdRXwO33Lfo7uCpl6%2Fuploads%2Fgit-blob-42c2c5a7abf8e9f7ce43e02681d457f5d7cf28d8%2Fmagisk_install.png?alt=media)

* Unlock OEM in Developer Options to unlock the bootloader:

![](https://3928478158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjMjdRXwO33Lfo7uCpl6%2Fuploads%2Fgit-blob-c5d37499f24feca5ec2840bc82f9e7c3c731ede7%2FOEM_unlock.png?alt=media)

* Download the system OTA (Over-The-Air) update related to your system version and extract it:

![](https://3928478158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjMjdRXwO33Lfo7uCpl6%2Fuploads%2Fgit-blob-2b6ba5910ef1622e39b84c0c67387158ba0e8bc5%2Fota_payload.png?alt=media)

Download `payload-dumper-go` to dump the OTA payload `payload.bin` and collect the `boot.img` in the results folder using the following command:

```shell
payload-dumper-go payload.bin
```

![](https://3928478158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjMjdRXwO33Lfo7uCpl6%2Fuploads%2Fgit-blob-57f2c7f8554eb4959c39c81801ce9dc8e456fbea%2Fboot_img.png?alt=media)

![](https://3928478158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjMjdRXwO33Lfo7uCpl6%2Fuploads%2Fgit-blob-54d47942d54dedd0fa67033206f1e3f683599761%2Fboot_img2.png?alt=media)

* Transfer the boot.img from the PC to the mobile device, for example:

  ```shell
  adb push boot.img /sdcard/
  ```
* Run magisk and, after clicking on the install button, select the `boot.img` previously transfered to patch it:

  ![](https://3928478158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjMjdRXwO33Lfo7uCpl6%2Fuploads%2Fgit-blob-0cdcd14aa87e1c229988ecfc58925d0d366eab72%2Fmagisk_run.png?alt=media)

  <br>

  ![](https://3928478158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjMjdRXwO33Lfo7uCpl6%2Fuploads%2Fgit-blob-d0ea69f3a2ed74ec094f1dee7352885143042aea%2Fmagisk_patch.png?alt=media)

  <br>

  ![](https://3928478158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjMjdRXwO33Lfo7uCpl6%2Fuploads%2Fgit-blob-cb6b694684c1649a1195d93571204c65715ab084%2Fmagisk_patch2.png?alt=media)

  <br>

  ![](https://3928478158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjMjdRXwO33Lfo7uCpl6%2Fuploads%2Fgit-blob-520dae0f42f2dfc69510087565ffd021564fb927%2Fmagisk_patch3.png?alt=media)

  <br>

  or run via `adb shell`:

  ```
  su
  data/adb/magisk/magiskboot repack boot.img
  ```
* Transfer the patched boot image, created by magisk, to the PC:

  ```shell
  adb pull magisk_patched-<xxx>.img
  ```
* Restart the device on bootloader

  ```shell
  adb.exe reboot bootloader
  ```

  ![](https://3928478158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjMjdRXwO33Lfo7uCpl6%2Fuploads%2Fgit-blob-a3dbe5cda588cc8ce52d95612bc82fe5ab70bb3e%2Fflashing_unlock.png?alt=media)

  <br>

  ![](https://3928478158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjMjdRXwO33Lfo7uCpl6%2Fuploads%2Fgit-blob-28f4f14f009027ada91f55083e7034d4de15ec1e%2Ffastboot_mode.png?alt=media)
* Unlock the bootloader

  ```shell
  fastboot flashing unlock
  ```

  ![](https://3928478158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjMjdRXwO33Lfo7uCpl6%2Fuploads%2Fgit-blob-f32d4e1073ef0e9803ca7f92cb842a0aca3a16df%2Funlock_bootloader.png?alt=media)

  <br>

  ![](https://3928478158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjMjdRXwO33Lfo7uCpl6%2Fuploads%2Fgit-blob-eb4e43968769129a5fd4a6a7460bf46b240864ca%2Funlocked_bootloader.png?alt=media)
* Flash patched boot image

  ```shell
  flash boot magisk_patched-<xxx>.img
  ```

  ![image](https://3928478158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjMjdRXwO33Lfo7uCpl6%2Fuploads%2Fgit-blob-99aea71296234dd1b8640817e64e622ce604e053%2Fboot_patched_sent.png?alt=media)
* Reboot the device

  ```shell
  fastboot reboot
  ```

  ![image](https://3928478158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjMjdRXwO33Lfo7uCpl6%2Fuploads%2Fgit-blob-248eb94505cdd714904d5dfd110edbc5a37421a8%2Ffastboot_reboot.png?alt=media)
