What's new

Welcome to Gaming Legion

Join us now to get access to all our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, and so, so much more. It's also quick and totally free, so what are you waiting for?

How to root your Android Device (Windows, Linux & MacOS)

Status
Not open for further replies.
Joined
Feb 24, 2022
Messages
66
Reaction score
1,702
Points
83
Location
0.0.0.0
Website
www.gaming-legion.net
Magisk-Feature-Image-Background-Colour-e1628095063685.png


Installing Magisk requires you to have a custom recovery for which your phone needs to have an unlocked bootloader.
If you've already unlocked the bootloader on your phone, you're good to go.
If you haven't and you don't know what we're talking about, we recommend you head over to the XDA Forums, search for your device, and then look for a guide to unlocking the bootloader.
There's no universal method for this, as it differs from phone to phone.
Once you've unlocked the bootloader, you can proceed further.

Rich (BB code):
Disclaimer:
Unlocking the bootloader will wipe all the data on your smartphone and in some cases, may even void your warranty.
It’s advisable to back up all your data before performing these steps.
It’s also important to understand that not following the steps correctly may result in a bricked phone so make sure you know how to recover your phone back to its original state in case you end up in a situation like that.

Furthermore, Magisk may cause issues with a few banking and payment-related apps so if those are absolutely vital to you, proceed with caution.

Table of Contents:
  • How to Install ADB on Windows, macOS, and Linux
  • Locating the boot image
  • Patching the boot image
  • Verification

Chapter 1: How to Install ADB on Windows, macOS, and Linux
What is Android Debug Bridge (ADB)?
The internal structure of the Android Debug Bridge (ADB) is based on the classic client-server architecture.
There are three components that make up the entire process.
  1. The client, i.e. the PC or Mac you have connected to your Android device. We are sending commands to our device from this coomputer through the USB cable (and wirelessly as well in some cases).
  2. A daemon (adbd), which runs commands on a device. The daemon runs as a background process on each device.
  3. A server, which manages communication between the client and the daemon. The server runs as a background process on the PC/Mac.
How does ADB Work?
Because there are three pieces that makeup ADB (the Client, Daemon, and the Server), this requires certain pieces to be up and running in the first place.
So if you have freshly booted the computer (and you don't have it setup to start the daemon on boot), then you will need it to be running before any communication can be sent to the target Android device.
You'll see this the following message in the command prompt or terminal, as it will check to make sure the daemon is running.
What-is-ADB-Start-Service.jpg
If the daemon isn't running, then it will start the process and tell you which local TCP port it has been started on.
Once that ADB service has been started, it will continue to listen to that specific port for commands that have been sent by the ADB client. It will then set up connections to all running devices which are attached to the computer (including emulators).
This is the moment where you'll receive the authorization request on the Android device if the computer hasn't been authorized in the past.

How to Setup ADB?
Code:
Note: Setting up ADB on the computer is just half the equation since you'll also need to do some things on the smartphone or tablet to accept the ADB commands.

Phone Setup
  1. Launch the Settings application on your phone.
  2. Tap the About Phone option generally near the bottom of the list.
  3. Then tap the Build Number option 7 times to enable Developer Mode. You will see a toast message when it is done.
  4. Now go back to the main Settings screen and you should see a new Developer Options menu you can access.
  5. Go in there and enable the USB Debugging mode option.
Image-001-1-768x509.jpg
  1. You are partially done with the phone setup process. Next up, you will need to scroll below and follow the rest of the instructions for your particular operating system.
Follow along for the operating system on your computer.

Setup ADB on Microsoft Windows
  1. Download the Android SDK Platform Tools ZIP file for Windows.
  2. Extract the contents of this ZIP file into an easily accessible folder (such as C:\platform-tools)
  3. Open Windows explorer and browse to where you extracted the contents of this ZIP file
  4. Then open up a Command Prompt from the same directory as this ADB binary. This can be done by holding Shift and Right-clicking within the folder then click the "Open command window here" option. (Some Windows 10 users may see "PowerShell" instead of "command window".)ADBOpenHere.jpg
  5. Connect your smartphone or tablet to your computer with a USB cable. Change the USB mode to "file transfer (MTP)" mode. Some OEMs may or may not require this, but it's best to just leave it in this mode for general compatibility.
  6. In the Command Prompt window, enter the following command to launch the ADB daemon:
    Code:
    adb devices
  7. On your phone's screen, you should see a prompt to allow or deny USB Debugging access. Naturally, you will want to grant USB Debugging access when prompted (and tap the always allow check box if you never want to see that prompt again).
    Image-002-2.jpg
  8. Finally, re-enter the command from step #6. If everything was successful, you should now see your device's serial number in the command prompt (or the PowerShell window).
Windows-PowerShell-adb-devices.jpeg

Yay! You can now run any ADB command on your device!
Now go forth and start modding your phone by following our extensive list of tutorials!

How to setup ADB on macOS
  1. Download the Android SDK Platform Tools ZIP file for macOS.
  2. Extract the ZIP to an easily-accessible location (like the Desktop for example).
  3. Open Terminal.
  4. To browse to the folder you extracted ADB into, enter the following command:
    Code:
    cd /path/to/extracted/folder/
  5. For example, on my Mac it was this:
    Code:
    cd /Users/Doug/Desktop/platform-tools/
  6. Connect your device to your Mac with a compatible USB cable. Change the USB connection mode to "file transfer (MTP)" mode. This is not always required for every device, but it's best to just leave it in this mode so you don't run into any issues.
  7. Once the Terminal is in the same folder your ADB tools are in, you can execute the following command to launch the ADB daemon:
    Code:
    adb devices
  8. On your device, you'll see an "Allow USB debugging" prompt. Allow the connection.
  9. Image-002-2_1.jpg
  10. Finally, re-enter the command from step #7. If everything was successful, you should now see your device's serial number in macOS's Terminal window.
    macOS-Terminal-adb-devices.png
    Congratulations! You can now run any ADB command on your device! Now go forth and start modding your phone by following our extensive list of tutorials!
    While the guide above will certainly work, some seasoned macOS users should be aware that there can be an easier way to install ADB on their Macs using an unofficial package manager such as Homebrew or MacPorts.
How to setup ADB on Linux
  1. Download the Android SDK Platform Tools ZIP file for Linux.
  2. Extract the ZIP to an easily-accessible location (like the Desktop for example).
  3. Open a Terminal window.
  4. Enter the following command:
    Code:
     cd /path/to/extracted/folder/
  5. This will change the directory to where you extracted the ADB files.
  6. So for example:
    Code:
    cd /Users/Doug/Desktop/platform-tools/
  7. Connect your device to your Linux machine with your USB cable. Change the connection mode to "file transfer (MTP)" mode. This is not always necessary for every device, but it's recommended so you don't run into any issues.
  8. Once the Terminal is in the same folder your ADB tools are in, you can execute the following command to launch the ADB daemon:
    Code:
    adb devices
  9. Back on your smartphone or tablet device, you'll see a prompt asking you to allow USB debugging. Go ahead and grant it.Image-002-2_2.jpg
  10. Finally, re-enter the command from step #8. If everything was successful, you should now see your device's serial number in the Terminal window output.
    Ubuntu-Linux-adb-devices.png
Congrats! You can now run any ADB command on your device! Now go forth and start modding your phone by following our extensive list of tutorials!

Some Linux users should be aware that there can be an easier way to install ADB on their computer. The guide above will certainly work for you, but those own a Debian or Fedora/SUSE-based distro of Linux can skip steps 1 and 2 of the guide above and use one of the following commands:

  • Debian-based Linux users can type the following command to install ADB:
    Code:
    sudo apt-get install android-tools-adb
  • Fedora/SUSE-based Linux users can type the following command to install ADB:
    Code:
    sudo yum install android-tools
However, it is always better to opt for the latest binary from the Android SDK Platform Tools release, since the distro-specific packages often contain outdated builds.

Just to cover all of our bases here, users may need to put a ./ in front of the ADB commands we list in future tutorials, especially when they are using the extracted binaries directly from the Platform Tools ZIP. This is something that is likely known by any *nix user (or Windows user running PowerShell) already, but again, we want as many people as possible to understand how to do these tweaks for Android no matter how much of your operating system you know.

Examples of ADB Commands

To check if you have successfully installed ADB, connect your device to your PC/Mac with your USB cable, and run the adb devices command as described above. It should display your device listed in the Command Prompt/PowerShell/Terminal window.
If you get a different output, we recommend starting over with the steps.

As mentioned above, you can use ADB to do all sorts of things on an Android device. Some of these commands are built directly into the ADB binary and should work on all devices.
You can also open up what is referred to as an ADB Shell and this will let you run commands directly on the device.
The commands which are run directly on the device can vary from device to device (since OEMs can remove access to certain ones, and also modify adb behavior) and can vary from one version of Android to the next as well.

Below, you'll find a list of example commands which you can do on your device:

  • Print a list of connected devices:
    Code:
    adb devices
  • Kill the ADB server:
    Code:
    adb kill-server
  • Install an application:
    Code:
    adb install <path_to_the_APK_file>
  • Set up port forwarding:
    Code:
    adb forward tcp:6100 tcp:7100
  • Copy a file/directory from the device:
    Code:
    adb pull <path_to_the_remote_object> <path_to_the_local_destination>
  • Copy a file/directory to the device:
    Code:
    adb push <path_to_the_local_object> <path_to_the_remote_destination>
  • Initiate an ADB shell:
    Code:
    adb shell
Chapter 2: Locating the boot image

In order to patch the boot image for your device, you need to extract it from the official firmware packages.
In case you're using a custom ROM like LineageOS, the flashable ZIP file contains the boot image.

Case I: You have access to the recovery-flashable ZIP file

If you have a device that still uses the A-only partition scheme, you can find the 'boot.img' right inside the recovery-flashable ZIP file. Just extract it using a suitable archiver program.

POCO-M3-recovery-zip-boot.img_.jpg
Code:
Notice the boot.img file inside POCO M3’s recovery ZIP.

However, if your device utilizes the A/B partition scheme, then the boot image and other partition images are further packed inside a file named payload.bin as shown below.

Google-Pixel-5-recovery-zip-payload.bin_.jpg
Code:
The recovery ZIP of the Google Pixel 5 contains a payload.bin file. 
In that case, you have to extract the payload.bin file first, then use one of the community-developed payload.bin unpackers to get the boot.img out of it. 
We strongly suggest you opt for the extractor written in Go as it’s cross-platform and has been actively developed.

Known as 'payload-dumper-go', this fork even allows end-users to extract a single partition image without unpacking the whole payload.bin, which is particularly useful for this usage scenario.

  • First, use the -l parameter to list the partition images inside the payload.
    Code:
    bin.payload-dumper-go -l payload.bin
  • Then use the -p parameter with the name of the boot image (commonly stored as "boot") to extract it.
    Code:
    payload-dumper-go -p boot payload.bin
ASUS-ROG-Phone-5-payload.bin-boot.img_.jpg

Case II: You have access to the Fastboot-flashable image

A handful of OEMs like Google and Xiaomi provide Fastboot-flashable factory images for their devices.
If you managed to grab such a package, then the raw 'boot.img' can easily be extracted from the archive.

Google-Pixel-5-fastboot-boot.img_.jpg

Special Case: Samsung

Samsung Galaxy devices don't a traditional Fastboot interface, hence their factory images are packed differently.
  1. Use Samsung Firmware Downloader to download the factory image for your model.
  2. Unzip the decrypted package and locate the AP tar file to your device. It is normally named as
    Code:
    AP_[device_model_sw_ver].tar.md5.

Chapter 3: Patching the boot image
Now we have the boot image in hand, we should proceed with the patching part.

Case I: The value of the "Ramdisk" parameter is "Yes"

  • Copy the boot image to your device. In fact, you can patch it on a different Android device than the target one, but you need to install the Magisk app on the secondary device as well.
  • Press the Install button on the Magisk card.
  • Choose Select and Patch a File under method, and select the stock boot image.
    Magisk-select-and-patch-image.jpg

  • The Magisk app will patch the image to [Internal Storage]/Download/magisk_patched_[random_strings].imgMagisk-patch-boot-image.jpg
  • Copy the patched image to your PC with ADB:
    Code:
    adb pull /sdcard/Download/magisk_patched_[random_strings].img
  • Flash the patched boot image to your device. For most devices, reboot into Fastboot mode and flash with the following command:
    Code:
    fastboot flash boot /path/to/magisk_patched.img
  • Reboot and enjoy Magisk!
Keep in mind it's possible to patch the boot image on the fly on legacy devices having boot ramdisk through a custom recovery like TWRP, but the method is no longer recommended on modern devices.
Having said that, if you have an old phone and want to stick with the custom recovery route, the steps are as follows:

  • Download the Magisk APK.
  • Rename the .APK file extension to .ZIP (e.g. Magisk-v23.0.APK → Magisk-v23.0.ZIP).
  • Flash the ZIP file just like any other ordinary flashable ZIP.
Magisk-TWRP.jpg
  • Note that the sepolicy.rule file of modules may be stored in cache partition, so do not clear it.
  • Check whether the Magisk app is installed. If it isn't installed automatically, manually install the APK.
Case II: The value of the "Ramdisk" parameter is "No"

In this case, you need to locate the recovery.img file from the factory image of your device instead of boot.img file. This is because Magisk needs to be installed in the recovery partition, which means you'll have to reboot to the recovery mode every time you want to access Magisk.

  • Copy the recovery image to your device (or a secondary device with the Magisk app installed).
  • Press the Install button on the Magisk card.
  • Choose Select and Patch a File under method, and select the stock recovery image.
  • The Magisk app will patch the image to [Internal Storage]/Download/magisk_patched_[random_strings].img.
  • Copy the patched image to your PC with ADB:
    Code:
    adb pull /sdcard/Download/magisk_patched_[random_strings].img
  • Flash the patched recovery image to your device. For most devices, reboot into Fastboot mode and flash with the following command:
    Code:
    fastboot flash recovery /path/to/magisk_patched.img
  • Reboot.
At this stage, there are three possible scenarios:

  • Power up normally: You'll end up with no Magisk.
  • Recovery Key Combo → Splash screen → Release all buttons: The system should boot with Magisk.
  • Recovery Key Combo → Splash screen → Keep pressing volume up: To access the stock recovery mode
Special Case: Samsung

  • Copy the extracted AP tar file to your device.
  • Press the Install button on the Magisk card.
  • If your device doesn't have a boot ramdisk, make sure Recovery Mode is checked in options.
  • Choose Select and Patch a File under method, and select the AP tar file.
  • The Magisk app will patch the whole firmware file to [Internal Storage]/Download/magisk_patched_[random_strings].tar
  • Copy the patched tar file to your PC with ADB:
    Code:
    adb pull /sdcard/Download/magisk_patched_[random_strings].tar
    • Don't try to copy over the MTP interface as it is known to corrupt large files.
  • Reboot to download mode. Open Odin on your PC, and flash magisk_patched.tar as AP, together with BL, CP, and CSC from the original firmware.
    • Don't choose HOME_CSC because we want to wipe data.
  • Your device should reboot automatically once Odin finished flashing. Agree to do a factory reset if asked.
  • If your device doesn't have a boot ramdisk, reboot to recovery now to enable Magisk.
  • Install the latest Magisk app and launch the app. It should show a dialog asking for additional setup. Let it do its job and the app will automatically reboot your device.
  • Reboot and enjoy Magisk!

Chapter 4: Verification

The last step is to verify that everything is working properly.
Locate the newly installed Magisk app and open it.
We want to see a version number beside the "Installed" parameter.
This means you have successfully installed Magisk. Great job!

Magisk-installed.jpg
Now you have Magisk installed, it's time to try out some nice Magisk Modules.
You can find lots of modules for specific purposes, and since Magisk gives you root access,
you can even install some of the best apps for rooted devices.
So install whichever apps and modules you like and get tweaking!
 
Status
Not open for further replies.
Top Bottom
AdBlock Detected

We get it, advertisements are annoying!

Sure, ad-blocking software does a great job at blocking ads, but it also blocks useful features of our website. For the best site experience please disable your AdBlocker.

I've Disabled AdBlock