shakalaca/MagiskOnEmulator

Failed to patch Android S Beta 2,3,4

Closed this issue ยท 27 comments

Before patching, the ramdisk has a size of 2.5M but after patching its size shrinks to 1.8M.
ramdisk.zip

I tried to uncompress the ramdisk.img with lz4, recompress it with gzip and patch it with MagiskOnEmulator. Now it works, and with proper size.
ramdisk.zip

Can confirm this issue in beta 4 as well, by repacking it with gzip I was able to get it through.
Anyway the script fails to enable Magisk (no errors in the log, Magisk app get installed but shows as not active - N/A). Installing with canary or manager options does not change things. Someone else with any idea?

Can confirm this issue in beta 4 as well, by repacking it with gzip I was able to get it through.
Anyway the script fails to enable Magisk (no errors in the log, Magisk app get installed but shows as not active - N/A). Installing with canary or manager options does not change things. Someone else with any idea?

Because beta 4 uses bootconfig now. And Magisk does not yet support bootconfig. However, you can try magisk alpha: https://github.com/vvb2060/Magisk/tree/alpha

I successfully installed fully functional magisk alpha on my Android S beta 4 AVD. Notice that you should use alpha-31 since I fixed a bug with AVD supports.

Thank you will try!

Superb! Worked like a charm thank you! For future use i attach the apk (unzip it first, it is an apk) for Magisk alpha-31 here
Magisk.apk.zip

After much trouble another problem came out (is this a Magisk issue or MagiskOnEmulator?)
busybox in /data/adb/magisk get always installed in arm64 version not x86_64 leading to all kind of problems.

So a guide for everyone who's trying to setup magisk on Android 12 (beta 4 and below) and an emulator x86_64:

  1. Download MagiskOnEmulator
  2. Download Magisk alpha-31 (linked above)
  3. Copy the original ramdisk, extract it with lz4 and repack it with gzip
  4. Copy back the gzipped ramdisk and start the emulator (cold boot)
  5. Run patch.sh
  6. Stop the emulator, copy the modified ramdisk over the original one and cold boot it again
  7. Download busybox64 from https://raw.githubusercontent.com/Magisk-Modules-Repo/busybox-ndk/master/busybox-x86_64-selinux , rename it to 'busybox'
  8. Restart adb with root permissions, copy the busybox binary to /data/adb/magisk/
  9. Open an adb shell with root permissions and navigate to /data/adb/magisk/, chmod +x busybox
  10. Reboot and finally enjoy Magisk!

Thank you @yujincheng08 for the help. @shakalaca can we look into this and maybe fix it? Thank you all for your hard work!

It's from MagiskOnEmulator. You can notice a comment in MagiskOnEmulator saying comment this to use the original busybox instead of the prepared one. So the only thing you need to do is to comment that part of codes:

diff --git a/busybox_arm b/busybox_arm
deleted file mode 100644
index 8de3f5c..0000000
Binary files a/busybox_arm and /dev/null differ
diff --git a/process.sh b/process.sh
index 2b01262..66b9eea 100644
--- a/process.sh
+++ b/process.sh
@@ -126,14 +126,14 @@ fi

 # Use x86_64 busybox instead of built-in one.
 # If you don't wanna take it, comment out those lines
-if [[ $IS64BIT == true ]]; then
-  rm -f ${TMP_DIR}${BINDIR}/$ARCH/busybox
-  if [[ $ARCH == "x86" ]]; then
-    $BUSYBOX wget -c https://raw.githubusercontent.com/Magisk-Modules-Repo/busybox-ndk/master/busybox-x86_64-selinux -O ${TMP_DIR}${BINDIR}/$ARCH/busybox
-  else
-    $BUSYBOX wget -c https://raw.githubusercontent.com/Magisk-Modules-Repo/busybox-ndk/master/busybox-arm64-selinux -O ${TMP_DIR}${BINDIR}/$ARCH/busybox
-  fi
-fi
+# if [[ $IS64BIT == true ]]; then
+#   rm -f ${TMP_DIR}${BINDIR}/$ARCH/busybox
+#   if [[ $ARCH == "x86" ]]; then
+#     $BUSYBOX wget -c https://raw.githubusercontent.com/Magisk-Modules-Repo/busybox-ndk/master/busybox-x86_64-selinux -O ${TMP_DIR}${BINDIR}/$ARCH/busybox
+#   else
+#     $BUSYBOX wget -c https://raw.githubusercontent.com/Magisk-Modules-Repo/busybox-ndk/master/busybox-arm64-selinux -O ${TMP_DIR}${BINDIR}/$ARCH/busybox
+#   fi
+# fi
 # END
 cp ${TMP_DIR}${BINDIR}/$ARCH/* $MAGISK_DIR
 mv ${TMP_DIR}${COMMON}/* $MAGISK_DIR

Yeah I saw that but this is right. See I downloaded the very same version and substituted manually in /data/adb/magisk. I also see in the log that it download the x86_64 version from GitHub, but then in the data folder there is the arm version. Why?

Hi, you're talking about ADB and I ran into an error,

"
C\Users\treni\Desktop\f\MagiskOnEmulator-master>patch.bat

"adb" is not an internal or external
command, executable program, or batch file.

"

Can you tell me what manipulation you need to do with ADB

In this video everything goes without running ADB https://youtu.be/RcSYjWUPq2M?t=373

You have to install adb, the script expects to have it. Download adb from Here and then add it to PATH (search on the internet for instructions)

After much trouble another problem came out (is this a Magisk issue or MagiskOnEmulator?) busybox in /data/adb/magisk get always installed in arm64 version not x86_64 leading to all kind of problems.

So a guide for everyone who's trying to setup magisk on Android 12 (beta 4 and below) and an emulator x86_64:

  1. Download MagiskOnEmulator
  2. Download Magisk alpha-31 (linked above) --- in the same folder as MagiskOnEmulator?
  3. Copy the original ramdisk, extract it with lz4 and repack it with gzip --- what name should the extracted lz4 have and how exactly to repack it ?
  4. Copy back the gzipped ramdisk and start the emulator (cold boot) --- where to copy the ramdisk, in .\Android\Sdk\system-images\android-31\default\x86_64 ?
  5. Run patch.sh
  6. Stop the emulator, copy the modified ramdisk over the original one and cold boot it again --- overwrite the same in \Android\Sdk\system-images\android-31\default\x86_64 ?
  7. Download busybox64 from https://raw.githubusercontent.com/Magisk-Modules-Repo/busybox-ndk/master/busybox-x86_64-selinux , rename it to 'busybox'
  8. Restart adb with root permissions, copy the busybox binary to /data/adb/magisk/
  9. Open an adb shell with root permissions and navigate to /data/adb/magisk/, chmod +x busybox
  10. Reboot and finally enjoy Magisk!

Thank you @yujincheng08 for the help. @shakalaca can we look into this and maybe fix it? Thank you all for your hard work!

I have some doubts about this (see bolded). Can you please share some guidelines? Thank you!

@fusionneur see the following answers
2. Yes, and unzip it (it's an apk)
3. The name of the lz4 doesn't matter, the only thing important is that the output gzipped file keeps the same name as the original one. To gzip a file simply run gzip filename
4. Exactly where you have found it, typically <sdk_home>/system-images/<platform>/*/ramdisk.img
6. Yes

@fusionneur see the following answers 2. Yes, and unzip it (it's an apk) 3. The name of the lz4 doesn't matter, the only thing important is that the output gzipped file keeps the same name as the original one. To gzip a file simply run gzip filename 4. Exactly where you have found it, typically <sdk_home>/system-images/<platform>/*/ramdisk.img 6. Yes

I am not able to make it work on Android S. I tried all kind of ways. Which is the lz command you used?
I used: lz4 -d ./ramdisk.img ramdisk
Afterwards I used: gzip ramdisk into ramdisk.gz
Lastly, I used: mv ramdisk.gz ramdisk.img and overwrote the one located in system-images

Also related to busybox, at step 6 you are cold booting after patching and then you change busybox, but for me it gives busybox error during patching. I tried commenting those lines in the process.sh but the emulator won't boot (black screen)

What could I be missing ?

I have to try patching again because I recently updated to beta 4 for error and lost root access. As soon as I try i will update you

@fusionneur Tried today the procedure explained in #904196546 and can confirm it works perfectly fine in beta 4.
Try to reinstall the emulator maybe something got corrupted and try again following the steps exactly as they are.

#39 (comment) should make it more clear that the Magisk "canary" or "alpha" is required to make it work. I was able to root it via https://github.com/newbit1/rootAVD after figuring this out. People need clear simple instructions!

First its written right in the point #2 "Download Magisk alpha-31 (linked above)", second all of this is done for free so no need to complain at all. If you want to provide clearer instructions you are free to do so

In your opinion I should "fork" your comment above to provide my own description but I think merging my suggestions (not complains) would be more useful for other people. Another suggestion is to also make it clear that your solution requires the a non-googleplay system image, otherwise the adb root stuff won't work. This is not about being payed or not, is about delivering clear info to save other people time, which I think it's our common target

iotY commented

@yujincheng08 @fusionneur @shakalaca I gave up trying to patch AVD:S/12.0 x86_64 due to busybox missworking /data/local/tmp/process.sh[167]: /data/local/tmp/busybox: not executable: 64-bit ELF file (magisk.apk: 23016).

GOOD NEWS is MagiskOnEmulator succeeds with latest Canary 23016 on AVD:API32 (Google APIs) x86_64 e.g. 12L(beta) Tiramisu

As for https://github.com/newbit1/rootAVD I have no idea why this forked gplv3 patch.sh includes unknown busybox binaries in the end of the sh script (!!), ( @osm0sis ?)

Magisk has official support for AVD now.

topjohnwu/Magisk@20ef724

Good news. Which will be the version which will support this and if there is any guide on how to properly root avd? Thank you!

I successfully patched android api 32 rev. 3 (Google APIs Intel x86 Atom_64 System Image) under Android Studio Beta 2021.2.1

What i did:

  1. Downloaded magisk apk from https://github.com/topjohnwu/Magisk/releases/download/v24.1/Magisk-v24.1.apk

  2. renamed apk into Magisk.zip and copied into MagiskOnEmulator folder

  3. copied the ramdisk.img from C:\Users\[user]\AppData\Local\Android\Sdk\system-images\android-32\google_apis\x86_64 to MagiskOnEmulator folder

  4. while avd running, ran the patch script with no other parameter

  5. copied the patched ramdisk.img back to C:\Users\[user]\AppData\Local\Android\Sdk\system-images\android-32\google_apis\x86_64

  6. powered off avd, then cold booted it. Magisk was shown properly installed and i was able to adb shell into it and then "su -", granted root access to shell and for example the command "ls /" worked as expected

Extra note:
I also commented this section in the process.sh script for a full offline patching (no internet required in avd) before running patch.bat:

# # Use x86_64 busybox instead of built-in one.
# # If you don't wanna take it, comment out those lines
# if [[ $IS64BIT == true ]]; then
  # rm -f ${TMP_DIR}${BINDIR}/$ARCH/busybox
  # if [[ $ARCH == "x86" ]]; then
    # $BUSYBOX wget -c https://raw.githubusercontent.com/Magisk-Modules-Repo/busybox-ndk/master/busybox-x86_64-selinux -O ${TMP_DIR}${BINDIR}/$ARCH/busybox
  # else
    # $BUSYBOX wget -c https://raw.githubusercontent.com/Magisk-Modules-Repo/busybox-ndk/master/busybox-arm64-selinux -O ${TMP_DIR}${BINDIR}/$ARCH/busybox
  # fi
# fi
# # END

Adding my steps here, as the solutions proposed so far didn't work for me. Verified on archlinux patching the x86_64 image of "Android 12 (Google Play)" using rootAVD.

  1. git clone https://github.com/newbit1/rootAVD
  2. locate the original ramdisk.img file of the AVD, e.g. in ~/Android/Sdk/system-images/android-31/google_apis_playstore/x86_64/ramdisk.img, and make a backup of it
  3. copy the original ramdisk.img to the rootAVD dir just cloned
  4. download the latest version of Magisk (tested with Magisk v24.1), rename it to Magisk.zip and move it to the rootAVD dir, replacing the existing one
  5. start the avd
  6. from the rootAVD dir, run echo 1 | ./rootAVD.sh ramdisk.img. This will patch the ramdisk.img in the current dir, it will install magisk manager to the running avd and then it will shut down the avd
  7. copy the patched ramdisk.img from the rootAVD folder back to the system-images folder, to replace the original file
  8. launch the avd

If everything worked correctly, you should be able to run adb shell -t su and get a root shell. If you open the magisk manager app you will see a warning "requires additional setup" but this is normal. If you experience problems, always start from the original backed-up ramdisk.img.

good to know there are other alternatives out there, but you are basically promoting another one here and not actually contributing to this project. As i said in the previous comment, magiskOnEmulator works as well for latest android. If something is not working, you should open an issue.

but you are basically promoting another one here and not actually contributing to this project

This project has no activity since May 2021, but this issue is a reference for people trying to root avds with Android 12. I think the right place to solve this is on the Magisk repo (not here, not in rootAVD), I'm just providing a list of steps which work for me and hopefully can help other people.

magiskOnEmulator works as well for latest android

It does not work for me :/

If something is not working, you should open an issue.

I guess this is the issue?

what error/issue did you get when following my steps?

GeT1t commented

Adding my steps here, as the solutions proposed so far didn't work for me. Verified on archlinux patching the x86_64 image of "Android 12 (Google Play)" using rootAVD.

  1. git clone https://github.com/newbit1/rootAVD
  2. locate the original ramdisk.img file of the AVD, e.g. in ~/Android/Sdk/system-images/android-31/google_apis_playstore/x86_64/ramdisk.img, and make a backup of it
  3. copy the original ramdisk.img to the rootAVD dir just cloned
  4. download the latest version of Magisk (tested with Magisk v24.1), rename it to Magisk.zip and move it to the rootAVD dir, replacing the existing one
  5. start the avd
  6. from the rootAVD dir, run echo 1 | ./rootAVD.sh ramdisk.img. This will patch the ramdisk.img in the current dir, it will install magisk manager to the running avd and then it will shut down the avd
  7. copy the patched ramdisk.img from the rootAVD folder back to the system-images folder, to replace the original file
  8. launch the avd

If everything worked correctly, you should be able to run adb shell -t su and get a root shell. If you open the magisk manager app you will see a warning "requires additional setup" but this is normal. If you experience problems, always start from the original backed-up ramdisk.img.

on work