Installing Magisk on Android 11 for root control on Raspberry Pi

Have a question? Want to contribute? Try the "Other Projects" section of the Raspberry Pi forum. Start your title with "WBC".

Rooting your device enables the use of important tools such as firewalls. However, access to root must be managed to avoid allowing untrustworthy apps or software that is ingested by otherwise trustworthy apps to take control of your system.

Because of this, root management is required. Several programs have been used over the years to manage root on Android. The ideal root management program is secure, routinely updated, and open source.


Management SoftwareComments
SuperSUThis formerly open source root management program was the standard for years. Unfortunately, it is now closed-source software and therefore should not be allowed to control this most sensitive device configuration.
LineageOS root management The LineageOS team developed its own root management system which is open source and works well. Unfortunately, Google changed the architecture of Android 10 (and up) so that LineageOS Privacy Guard and root control (which is closely related) could no longer be made to function (additional link).
MagiskThe death of LineageOS Privacy Guard made Magisk the de-facto open source root management solution for Android 10 and up. Magisk is also capable of performing various other tasks.

It should be noted that in 2021, Google hired the main developer of Magisk, John Wu, under the condition that he stop working on Magisk.

As of today, Magisk remains the best available root management software for Android 10 and up.

These instructions are based on those written by rsaxvc, but provide more detail and fill in some gaps. This guide assumes that you have a computer that runs Linux.

Requirements

Linux computer with a microSD card reader
Mkbootimg and unpackbootimg
The Magisk app - currently on version 23.0

Instructions

Download and compile Mkbootimg and unpackbootimg. Lets assume that you have created a working directory called /workingdir $ cd /workingdir $ git clone https://github.com/osm0sis/mkbootimg $ cd mkbootimg $ make
Place a microSD card that already has Android installed in the reader and allow Linux to mount it. This guide will assume that the first partition on the card mounts to /mount/boot and that the fourth partition mounts to /mount/userdata.
Use mkbootimg to create an artificial boot image that Magisk can later patch $ /workingdir/mkbootimg/mkbootimg --kernel /mount/boot/bzImage --ramdisk /mount/boot/ramdisk.img --output /workingdir/pre-magisk-image.bin $ sudo cp /workingdir/pre-magisk-image.bin /mount/userdata/media/0/Download
Unmount the microSD card, take the disk out of the reader and put it into the Raspberry Pi. Boot the Raspberry Pi.
Download the latest Magisk apk on your Pi and install it.

Install magisk to the image using Install -> Select and Patch a File

There should be a new image called magisk_patched_(random text).img in the Download folder. Turn off the Raspberry Pi, remove the microSD card, and put it into your computer

Lets assume that your working directory is called /workingdir, the first (boot) partition of the microSD mounts as /mount/boot, and the fourth (userdata) partition mounts as /mount/userdata. Run the following commands

$ cd /workingdir $ unpackbootimg -i /media/userdata/media/0/Download/magisk_patched_(random text).img $ sudo cp /mount/boot/ramdisk.img /mount/boot/ramdisk.img.bak $ sudo cat magisk_patched_(random text)-ramdisk.img > /mount/boot/ramdisk.img
Unmount the SD card, place it in the Raspberry Pi and boot
Load the magisk app. Configure the superuser settings as you wish.