Hello there.
First of all, let me thank this incredible tool made by @topjohnwu, it's really a nice idea and implementation. I don't own any of the code here, it's just a modification to be able to install and run under Android-x86.org latest Nougat version (as of now, 7.1-rc2). It may work with other versions, including RemixOS and PhoenixOS, but I have not tested it. It was tested using a normal installation on a FAT32 partition, and should work with either a RW or RO system image.
Newer versions of Magisk don't use magic_magisk.sh anymore, that's why I've chosen v12.0 (it can be downloaded from the official thread on XDA). If topjohnwu want to add patches to the source code, I would be more than glad to help. But probably it's not worth the trouble... Another log is created on cache called logtmp.log if you want to check more info about what's going on.
The first step is to make a "fake" boot.img for the installer can patch the ramdisk.img. In order to do this, you will need the handy tool mkbootimg from this other XDA thread:
https://forum.xda-developers.com/showthread.php?t=2319018
Copy both kernel and ramdisk.img from the original installation and use this command (all files must be in the current directory, of course):
Code:
./mkbootimg --kernel kernel --ramdisk ramdisk.img -o boot.img
then copy the resulting boot.img to the Magisk v12.0 folder you will use to install it on your Android x86 installation. The easy way is use a flash drive connected to USB, and I will assume from now on that you have downloaded and decompressed the Magisk files to the root of your flash drive, creating a folder Magisk-v12.0 on it.
After that, if you still have su working on your installation, do the steps bellow after calling "su" (Magisk installer will remove the original su, so if you do not have it you should still be able to access root using the ALT+F1 terminal):
Code:
cd /dev
mkdir tmp
mkdir tmp/magisk
cd tmp/magisk
cp -r /storage/YOUR-FLASH-DRIVE-ID-HERE/Magisk-v12.0/* .
mv boot.img /data
sh ./META-INF/com/google/android/update-binary
YOUR-FLASH-DRIVE-ID-HERE must be replaced with your drive's unique ID. Alternatively you can copy the folder using a file manager to you internal storage (/sdcard) and then use this command instead:
Code:
cp -r /sdcard/Magisk-v12.0/* .
If everything goes well, you should see a message in the end that the new ramdisk.img is ready in the current directory, move it to somewhere else you can replace the installed one. The easiest way is moving it to a flash drive, boot on another system and replace the original one. If you can't do it, you can also move it to /data then boot in DEBUG mode and replace it on /mnt after you type "exit" once. then reboot. Also, delete boot.img from /data, it won't be necessary anymore.
This should result in a full installation of Magisk v12.0. Be aware that current modules for Magisk V14.0 won't work, so you have to dig old ones compatible with v12.0. Also, as many have asked me, probably SafetyNet won't work because it's an old version and Android x86 is a debug version anyway, you must "fake" a lot of things to pass SafetyNet test.
Attached are the modified files:
- updater-script
- magic_mask.sh
- magisk.apk (I had to use 4.3.3 for better compatibility, do not upgrade or it make break installation)
Have fun!
I do everything according to the instructions, but I can not.
Displays the following message.
I ask for help.
android-x86_64-7.1-rc2x
Code:
/dev/tmp/magisk # sh ./META-INF/com/google/android/update-binarg
unzip: can’t open [.zip]
***************************
Magisk v12.0 Boot Image Patcher
*******************************
0) /dev/tmp/magisk/common /-/
- Mounting /sistemro), /cache, /data
- Device platform: x64
chmod: /dev/tmp/magisk/chromeos: No such file or directorg
chmod: /dev/tmp/magisk/X64: No such file or directorg
- Constructing environment
cp: bad ’/dev/tmp/magisk/x64/busgbox’I No such file or directorg
cp: bad ’/dev/tmp/magisk/Xfié/magiskboot’I No such file or directorg
cp: bad ’/dev/tmp/magisk/xfié/magiskpolicg’I No such file or directorg
cp: bad ’/dev/tmp/magisk/common/init.magisk.rc’I No such file or directorg
cp: bad ’/dev/tmp/magisk/common/custom_ramdisk_patch.sh’I No such file or directorg
chmod: chmod ’sepolicy_inject’ to 120755: No such file or directorg
./METH-INF/com/google/android/update_binarg[280]: /dev/tmp/magisk/x64/busgbox: not found
./METH7INF/com/google/android/update7binarg[289]: /dev/tmp/magisk/X64/magiskpolicy: not found
- Creating /data/magisk.img
/dev/tmp/magisk/common/file_contexts_image: No such file or directorg
mount: ’/’ not in /proc/mounts
mount: ’/’ not in /proc/mounts
! Magisk image mount failed...
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Done independently. It was necessary to take the original Magisk-v12.0, in which it was necessary to replace the files from the post above and then install it.
free39 said:
I do everything according to the instructions, but I can not.
Displays the following message.
I ask for help.
android-x86_64-7.1-rc2x
Done independently. It was necessary to take the original Magisk-v12.0, in which it was necessary to replace the files from the post above and then install it.
Click to expand...
Click to collapse
I think you were successful in the end, but just to clarify: you're correct, one must first download v12.0 from the official thread then replace the files with the ones attached to OP, and only then use it. :good:
@lfom
Can you please make a video and upload to YouTube. So we can learn how to do it exactly. I did try on my pc, not work. DO wee need linux for make boot.img? Can you please explain us about more detail, if possible with video please.
@lfom
Can you give a bit more detailed guide?
Like, do we have to reboot into Android partition with debug flag enabled in the kernel, then run the magisk script?
harkaman said:
@lfom
Can you please make a video and upload to YouTube. So we can learn how to do it exactly. I did try on my pc, not work. DO wee need linux for make boot.img? Can you please explain us about more detail, if possible with video please.
Click to expand...
Click to collapse
Sorry, I cannot make a video now. It's not that simple because I cannot use a screen recorder for many steps. But it's basically what is written in the tutorial. I have used Linux, but the original thread says it should work with Cygwin., although I haven't tested, it should work are long as you have the correct files as you only need one executable (mkbootimg).
https://en.wikipedia.org/wiki/Cygwin
silv3rfox said:
@lfom
Can you give a bit more detailed guide?
Like, do we have to reboot into Android partition with debug flag enabled in the kernel, then run the magisk script?
Click to expand...
Click to collapse
No, you don't need debug mode. To run the magisk install script you need superuser rights, so the easier way it to open the console mode using ALT+F1 (you need either an external keyboard or maybe a custom keyboard that allows ALT commands, like Hacker's Keyboard).
I'll try to answer questions as soon as possible, so the information is clear enough so anyone can do it.
lfom said:
Sorry, I cannot make a video now. It's not that simple because I cannot use a screen recorder for many steps. But it's basically what is written in the tutorial. I have used Linux, but the original thread says it should work with Cygwin., although I haven't tested, it should work are long as you have the correct files as you only need one executable (mkbootimg).
https://en.wikipedia.org/wiki/Cygwin
No, you don't need debug mode. To run the magisk install script you need superuser rights, so the easier way it to open the console mode using ALT+F1 (you need either an external keyboard or maybe a custom keyboard that allows ALT commands, like Hacker's Keyboard).
I'll try to answer questions as soon as possible, so the information is clear enough so anyone can do it.
Click to expand...
Click to collapse
Would these steps work for the latest magisk 14.0?
Sent from my ONEPLUS A5000 using Tapatalk
the_mentor said:
Would these steps work for the latest magisk 14.0?
Click to expand...
Click to collapse
No, it won't. As stated in OP, v12.0 was the last version to use the magic_mask.sh. Newer versions use binaries so it's much more difficult to mod unless you change the source code and re-compile the tool.
It works :good: tried on two different pcs. Windows users can use Android Image Kitchen for creating boot.img
maxriter said:
It works :good: tried on two different pcs. Windows users can use Android Image Kitchen for creating boot.img
Click to expand...
Click to collapse
I have createed bootimg . what shell i do next? do i need to copy and go in android x86?
harkaman said:
I have createed bootimg . what shell i do next? do i need to copy and go in android x86?
Click to expand...
Click to collapse
follow steps from OP, download magisk, replace files in magisk with that from the attachment, copy magisk along with boot.img to sdcard or usb drive, boot to android-x86, run the commands from OP, as a result you will get a patched ramdisk.img, copy this ramdisk to usb drive, boot back to windows, replace the original ramdisk from android x86 with the patched one.
hi.
I have installed magisk in android x86 and new ramdisk is created. BUt where and how can i copy, since i lose root. How can I copy new ramdisk?
Code:
x86_64:/ $ su
x86_64:/ # cd /dev
x86_64:/dev # mkdir tmp
x86_64:/dev # mkdir tmp/magisk
x86_64:/dev # cd tmp/magisk
x86_64:/dev/tmp/magisk # cp -r /storage/B6B4-79A3/Magisk-v12.0/* .
x86_64:/dev/tmp/magisk # mv boot.img /data
x86_64:/dev/tmp/magisk # sh ./META-INF/com/google/android/update-binary
unzip: cannot find or open , .zip or .ZIP.
*****************************
Magisk v12.0 Boot Image Patcher
*****************************
0) /dev/tmp/magisk/common /-/
- Mounting /system(ro), /cache, /data
! System installed root detected, mount rw :(
- Device platform: x64
- Constructing environment
- Creating /data/magisk.img
Creating filesystem with parameters:
Size: 67108864
Block size: 4096
Blocks per group: 32768
Inodes per group: 4096
Inode size: 256
Journal blocks: 1024
Label:
Blocks: 16384
Block groups: 1
Reserved block group size: 7
Created filesystem with 11/4096 inodes and 1294/16384 blocks
losetup: /data/magisk.img
losetup: /data/magisk.img
losetup: /data/magisk.img
- Mounting /data/magisk.img to /magisk
- Found Boot Image: /data/boot.img
- Unpacking boot image
MagiskBoot (by topjohnwu) - Boot Image Modification Tool
Parsing boot image: [/data/boot.img]
IMG [AOSP]
KERNEL [6098096] @ 0x10008000
RAMDISK [1795598] @ 0x11000000
SECOND [0] @ 0x10f00000
DTB [0] @ 0x10000100
PAGESIZE [2048]
NAME []
CMDLINE []
COMPRESSION [gzip]
Decompressing to [ramdisk.cpio]
- Checking patch status
MagiskBoot (by topjohnwu) - Boot Image Modification Tool
Loading cpio: [ramdisk.cpio]
- Backing up stock boot image
15424+0 records in
15424+0 records out
7897088 bytes (7.5MB) copied, 0.067583 seconds, 111.4MB/s
MagiskBoot (by topjohnwu) - Boot Image Modification Tool
Compressing to [/data/stock_boot_1b72ffffff9317ffffffdaffffffe6ffffffe7ffffff8870ffffffc0ffffffabffffff8dffffffc4fffffff356ffffff937e7c16ffffffb0.img.gz]
- Patching ramdisk
MagiskBoot (by topjohnwu) - Boot Image Modification Tool
Loading cpio: [ramdisk.cpio]
Dump cpio: [ramdisk.cpio]
MagiskBoot (by topjohnwu) - Boot Image Modification Tool
Loading cpio: [ramdisk.cpio]
Dump cpio: [ramdisk.cpio]
MagiskBoot (by topjohnwu) - Boot Image Modification Tool
Loading cpio: [ramdisk.cpio]
Extracting [init.rc] to [init.rc]
MagiskBoot (by topjohnwu) - Boot Image Modification Tool
Loading cpio: [ramdisk.cpio]
Add entry [init.rc] (0750)
Dump cpio: [ramdisk.cpio]
MagiskBoot (by topjohnwu) - Boot Image Modification Tool
Loading cpio: [ramdisk.cpio]
Extracting [sepolicy] to [sepolicy]
MagiskBoot (by topjohnwu) - Boot Image Modification Tool
Loading cpio: [ramdisk.cpio]
Add entry [sepolicy] (0644)
Dump cpio: [ramdisk.cpio]
MagiskBoot (by topjohnwu) - Boot Image Modification Tool
Loading cpio: [ramdisk.cpio]
Create directory [magisk] (0755)
Dump cpio: [ramdisk.cpio]
MagiskBoot (by topjohnwu) - Boot Image Modification Tool
Loading cpio: [ramdisk.cpio]
Add entry [init.magisk.rc] (0750)
Dump cpio: [ramdisk.cpio]
MagiskBoot (by topjohnwu) - Boot Image Modification Tool
Loading cpio: [ramdisk.cpio]
Add entry [sbin/magic_mask.sh] (0750)
Dump cpio: [ramdisk.cpio]
MagiskBoot (by topjohnwu) - Boot Image Modification Tool
Loading cpio: [ramdisk.cpio]
Loading cpio: [ramdisk.cpio.orig]
Entry [init.magisk.rc] is new
Entry [init.rc] missmatch
Entry [magisk] is new
Entry [sbin/magic_mask.sh] is new
Entry [sepolicy] missmatch
Dump cpio: [ramdisk.cpio]
MagiskBoot (by topjohnwu) - Boot Image Modification Tool
- Repacking boot image
MagiskBoot (by topjohnwu) - Boot Image Modification Tool
Parsing boot image: [/data/boot.img]
IMG [AOSP]
KERNEL [6098096] @ 0x10008000
RAMDISK [1795598] @ 0x11000000
SECOND [0] @ 0x10f00000
DTB [0] @ 0x10000100
PAGESIZE [2048]
NAME []
CMDLINE []
COMPRESSION [gzip]
Repack to boot image: [new-boot.img]
Compressing to [ramdisk.cpio.gz]
KERNEL [6098096] @ 0x10008000
RAMDISK [1851668] @ 0x11000000
SECOND [0] @ 0x10f00000
DTB [0] @ 0x10000100
PAGESIZE [2048]
NAME []
CMDLINE []
COMPRESSION [gzip]
Boot partition too small!
! Boot partition space insufficient
! Remove ramdisk backups and try again
MagiskBoot (by topjohnwu) - Boot Image Modification Tool
Loading cpio: [ramdisk.cpio]
Remove [.backup]
Remove [.backup]
Remove [.backup]
Remove [.backup]
Dump cpio: [ramdisk.cpio]
MagiskBoot (by topjohnwu) - Boot Image Modification Tool
Parsing boot image: [/data/boot.img]
IMG [AOSP]
KERNEL [6098096] @ 0x10008000
RAMDISK [1795598] @ 0x11000000
SECOND [0] @ 0x10f00000
DTB [0] @ 0x10000100
PAGESIZE [2048]
NAME []
CMDLINE []
COMPRESSION [gzip]
Repack to boot image: [new-boot.img]
Compressing to [ramdisk.cpio.gz]
KERNEL [6098096] @ 0x10008000
RAMDISK [1797690] @ 0x11000000
SECOND [0] @ 0x10f00000
DTB [0] @ 0x10000100
PAGESIZE [2048]
NAME []
CMDLINE []
COMPRESSION [gzip]
Boot partition too small!
! Boot partition size still too small...
Do not worry, it's fine...
New ramdisk.img ready - /dev/tmp/magisk/ramdisk.img
Copy it to an external drive to replace Android boot one
- Done
x86_64:/dev/tmp/magisk #
Replace installed system.img from the one in android-x86 iso, and repeat the procedure.
Copy this new ramdisk: /dev/tmp/magisk/ramdisk.img to your usb drive: /storage/B6B4-79A3/ and reboot to windows.
A standard android-x86 iso contains initrd.img, system.img/sfs and ramdisk.img + kernel (used to create the boot.img)
installed somewhere in your pc. Replace this ramdisk.img with the patched one from the usb drive.
Thanks for the guide !
I managed to get magisk v15.3 work on latest CM 14.1 x86 on my "tesco connect 7" , a z3735g atom bay-trail based tablet.
inorder to make the patched ramdisk.img I used virtualbox and ran lubuntu x32 16.04 - since I couldn't used mkbootimg on the android directly:
A. because the linked tool is for x64 systems, so x86 android can't run it.
B. because I was emulating android on virtual machine so I ran it as "live", making system as read only I think.
C. although on my x86 virtual android it doesn't work, on my virtual ubuntu x32 it does ( guess it can run x64 binaries somehow ).
once I make boot.img I moved it to android's sdcard ( on my virtual machine running the same image as my tablet ) -> installed magisk manager ( v5.5.5 -the current latest ) then I picked install -> install -> direct install -> picked my boot.img from /sdcard -> then magisk created SDcard/MagiskManager/patched_boot.img.
* in retrospect, a very similar guide can be found here.
then once I had patched_boot.img I moved it to my virtual ubuntu, and ran "unkbootimg patched_boot.img".
this gave me a "ramdisk.cpio.gz", which is actually the "ramdisk.img" needed for the android's iso ( i.e booting using grub ).
so i've rename it "ramdisk.img" and replaced the one found on the android iso root folder.
then I rebooted that modded iso ( i.e with the modded ramdisk.img ) on my virtual -> installed magisk manager -> AND IT SHOWS IT IS INSTALLED !!!!!
now I need to replace my current ramdisk.img on my tablet to actually "magisking" my tablet.
@gps3dx Thanks, your method works. Updated Magisk from 12 to 15.3!
maxriter said:
@gps3dx Thanks, your method works. Updated Magisk from 12 to 15.3!
Click to expand...
Click to collapse
nice to hear.
I suggest you check the magisk log to see if any issue like non-mounted error occurs.
Although magisk reports installed, I have issues - but I see from the magisk beta thread that i'm not the only one... so I guess it's the specific version fault and not the way I install it.
also make sure that you've got magisk files under /data/magisk that resembles (not 1:1) the magisk zip...
i.e that you've got files like "magiskinit", "magiskboot".... I think that if you don't do "direct install" these files won't appear, since I don't think that patching the boot.img alone installs these files on the device.
/data/magisk (ln to /data/adb/magisk ?) does contain those files, I can use root related functions and magisk hide works. Seems good so far.
Moreover i updated from 12 to 15.3, so there is that.
gps3dx said:
nice to hear.
I suggest you check the magisk log to see if any issue like non-mounted error occurs.
Although magisk reports installed, I have issues - but I see from the magisk beta thread that i'm not the only one... so I guess it's the specific version fault and not the way I install it.
also make sure that you've got magisk files under /data/magisk that resembles (not 1:1) the magisk zip...
i.e that you've got files like "magiskinit", "magiskboot".... I think that if you don't do "direct install" these files won't appear, since I don't think that patching the boot.img alone installs these files on the device.
Click to expand...
Click to collapse
do you know Android x86 special mount ?
mount /dev/xxxx on /mnt
mount /mnt/$SRC/system /android/system
mount /mnt/$SRC/data /android/data
https://forum.xda-developers.com/showpost.php?p=75345518&postcount=4926
P.S my android is NOT running from an img or sfs file, since i've expanded and extract the system onto my tablet's hdd ext4 partition.
Click to expand...
Click to collapse
your Android system is hdd ext4 partition /Android-x86/system folder.
so "Mounting mirrors,Magisk : mount /dev/block/mmcblk1p5->/sbin/.core/mirror/system",even though success,no use.
if you use system.sfs or system.img,"Mounting mirrors,Magisk : mount /dev/loop0(or /dev/loop1)->/sbin/.core/mirror/system",must failed,should be mount /dev/block/loop0(/dev/block/loop1)
if you understand magisk 12 magic_mask.sh
SYSTEMBLOCK=`mount | grep " /system " | awk '{print $1}' | awk '{print substr($0,6)}'`
busybox mount -o noatime /dev/block/$SYSTEMBLOCK $MIRRDIR/system
if you not use magisk dummy,you needn't magisk mirror system.
for example,this example must use mirror system.
PHP:
Replace with dummy: /system/app
New directory: /system/app/ChromeCustomizations
Replace with dummy: /system/app
New directory: /system/app/com.google.android.apps.nexuslauncher
Replace with dummy: /system/app
New directory: /system/app/com.google.android.nexusicons
New directory: /system/priv-app/Greenify
Replace with dummy: /system/priv-app
Clone skeleton: /system/priv-app/AnalyticsService
Clone skeleton: /system/priv-app/AudioFX
Clone skeleton: /system/priv-app/BackupRestoreConfirmation
…………
…………
Clone skeleton: /system/app/AndroidTerm
Clone skeleton: /system/app/BasicDreams
Clone skeleton: /system/app/Bluetooth
…………
Does this work with ubuntu? I'm opening the terminal in the folder where every file is but after entering the first command it says file or directory not found. Also i'm running it from a live usb.
youling257 said:
do you know Android x86 special mount ?
mount /dev/xxxx on /mnt
mount /mnt/$SRC/system /android/system
mount /mnt/$SRC/data /android/data
https://forum.xda-developers.com/showpost.php?p=75345518&postcount=4926
your Android system is hdd ext4 partition /Android-x86/system folder.
so "Mounting mirrors,Magisk : mount /dev/block/mmcblk1p5->/sbin/.core/mirror/system",even though success,no use.
if you use system.sfs or system.img,"Mounting mirrors,Magisk : mount /dev/loop0(or /dev/loop1)->/sbin/.core/mirror/system",must failed,should be mount /dev/block/loop0(/dev/block/loop1)
if you understand magisk 12 magic_mask.sh
SYSTEMBLOCK=`mount | grep " /system " | awk '{print $1}' | awk '{print substr($0,6)}'`
busybox mount -o noatime /dev/block/$SYSTEMBLOCK $MIRRDIR/system
if you not use magisk dummy,you needn't magisk mirror system.
for example,this example must use mirror system.
PHP:
Replace with dummy: /system/app
New directory: /system/app/ChromeCustomizations
Replace with dummy: /system/app
New directory: /system/app/com.google.android.apps.nexuslauncher
Replace with dummy: /system/app
New directory: /system/app/com.google.android.nexusicons
New directory: /system/priv-app/Greenify
Replace with dummy: /system/priv-app
Clone skeleton: /system/priv-app/AnalyticsService
Clone skeleton: /system/priv-app/AudioFX
Clone skeleton: /system/priv-app/BackupRestoreConfirmation
…………
…………
Clone skeleton: /system/app/AndroidTerm
Clone skeleton: /system/app/BasicDreams
Clone skeleton: /system/app/Bluetooth
…………
Click to expand...
Click to collapse
I don't understand what do you think I need to do inorder to make it work ?
Also, you're wrong... my "system" folder sits at the root of my android partition...
so it's /dev/mmcblk1p5 partition... which after I mount it... I have "System", "data" and kernel, ramdisk.img & initrd.img files AT THE ROOT of that partition....
Gionikva said:
Does this work with ubuntu? I'm opening the terminal in the folder where every file is but after entering the first command it says file or directory not found. Also i'm running it from a live usb.
Click to expand...
Click to collapse
try ubuntu x64...
I use 'ubuntu-16.04.3-desktop-amd64.iso'
Related
HEllo everybody
MAGISK V15.3 installed on Samsung TAB S2 SM-T810.
I tried to install MAGISK v16.O with MAGISK installer
Installation failed with this log
- Device platform: arm
- Extracting files
- Patch boot/ramdisk image: /dev/block/mmcblk0p9
boot_patch.sh: ./util_functions.sh: line 15: ps: Permission denied
boot_patch.sh: ./util_functions.sh: line 15: grep: Permission denied
boot_patch.sh: ./util_functions.sh: line 15: grep: Permission denied
boot_patch.sh: ./util_functions.sh: line 16: grep: Permission denied
boot_patch.sh: ./util_functions.sh: line 16: grep: Permission denied
boot_patch.sh: ./util_functions.sh: line 17: id: Permission denied
boot_patch.sh: ./util_functions.sh: line 17: grep: Permission denied
boot_patch.sh: line 75: chmod: Permission denied
boot_patch.sh: line 78: ./magiskinit: Permission denied
- Unpacking boot image
boot_patch.sh: line 87: ./magiskboot: Permission denied
boot_patch.sh: line 117: ./magiskboot: Permission denied
boot_patch.sh: line 148: ./magiskboot: Permission denied
boot_patch.sh: line 150: rm: Permission denied
boot_patch.sh: line 177: ./magiskboot: Permission denied
- Checking ramdisk status
- Patching ramdisk
- Repacking boot image
! Unable to repack boot image!
Failed!
! Installation failed
Any Idea ?
Thanks for your help
I have Samsung S5 g900w8
Identical problem.. my log file is exactly the same.
Try uninstalling v15.3 first and then install v16.0 clean.
I have uninstalled magisk 15.3, then installed magisk 16.0 with twrp.
Its perfect !
Thanks for your help
I did the Uninstaller /clean install method, which did update me to v16. Unfortunately now it fails safety net and apps can all detect root.
Lem0ns said:
I did the Uninstaller /clean install method, which did update me to v16. Unfortunately now it fails safety net and apps can all detect root.
Click to expand...
Click to collapse
It seems like some users have had issues with MagiskHide after updating to v16... Try toggling MagiskHide off and on. If that still doesn't work, navigate to /data/property and delete the file persist.magisk.hide, if it exists.
Uploading a Magisk debug log would also be useful.
Didgeridoohan said:
It seems like some users have had issues with MagiskHide after updating to v16... Try toggling MagiskHide off and on. If that still doesn't work, navigate to /data/property and delete the file persist.magisk.hide, if it exists.
Uploading a Magisk debug log would also be useful.
Click to expand...
Click to collapse
I've tried toggling everything off /on. I've Uninstalled and reinstalled twice.
The persist.magisk.hide file wasn't there.
I'm not sure how to install the beta version in order to get the debug log.
If I just go back to an older version, will this fix?
Lem0ns said:
I'm not sure how to install the beta version in order to get the debug log.
Click to expand...
Click to collapse
Change update channel in the Manager settings you beta and press install...
If I just go back to an older version, will this fix?
Click to expand...
Click to collapse
No it won't (well, maybe for you, but the underlying issue won't be).
Please at least provide the debug log before reverting. Make sure you've done a SafetyNet check before saving the log.
Didgeridoohan said:
Change update channel in the Manager settings you beta and press install...
No it won't (well, maybe for you, but the underlying issue won't be).
Please at least provide the debug log before reverting. Make sure you've done a SafetyNet check before saving the log.
Click to expand...
Click to collapse
First, thank you for all of your help. I'm still not able to get a debug log. I have toggled 2 Beta And pressed install but it's still just downloads the same file version 16 and won't install internally (see above post). When I install with TW RP it messed up the boot partition and I had to restore from backup. The next attempt it seemed to install fine but there is no log file in the ADB directory. How can I tell if the beta is installed?
I wish I hadn't tried to update. The previous version worked great and I only updated because it was nagging me 200 times a day and I have a hard time not updating to the newest version of things.
Just in case something helps here's a timeline of what I tried.
-direct install from previous version several times (failed with unable to repack boot image error)
-install via zip in TWRP - success - fails safety net + hide doesn't work
-toggle all settings on/off etc. (side note... sometimes settings don't "stick". like I toggle the hosts file setting on or off and then close the menu and when I open it it's back on/off as if I hadn't changed it)
-try just reinstalling - boots right to odin/download mode
-restore boot partition from backup - boots fine, still fails safety net
-try "core function only" mode - magisk asks to reboot manually... try this and it comes up in regular mode... toggle the switch again and reboot and it seems to work. I get SU access but still fails safety net.
-try uninstalling, reboot, re-install via TWRP.. no luck.. try formatting system partition and restore from backup.. reinstall magisk.. same result.
-toggle to beta update path, click install. Not sure what is supposed to happen here. It appears to download exactly the same file as the non beta. It won't install direct and when I flash with TWRP it doesn't appear different. Still fails safet net. When I browse to data/adb there are no log files.
I grabbed the 15.2 version and installed it. Everything seems to work now.
Thanks again for your help. Maybe I'll try again on the next update.
sumsung J720F with Oreo 8.0.0
magisk installed
patching the boot.img and at the end i have
! Unable to repack boot image!
! Installation failed
any help idea plz ???
here is the full log of Magisk
Code:
- Copying image to cache
- Device platform: arm64-v8a
- Downloading zip
... 0%
1038+1 records in
1038+1 records out
1063528 bytes transferred in 0.027 secs (39389925 bytes/sec)
- Unpacking boot image
MagiskBoot v18.1(18100) (by topjohnwu) - Boot Image Modification Tool
Parsing boot image: [/data/user_de/0/com.topjohnwu.magisk/install/boot.img]
HEADER_VER [0]
KERNEL_SZ [22504320]
RAMDISK_SZ [4067161]
SECOND_SZ [4278190336]
EXTRA_SZ [738199576]
RECOV_DTBO_SZ [3489687392]
OS_VERSION [41.68.0]
PATCH_LEVEL [2000-01]
PAGESIZE [8]
NAME [RPRA09A001KU]
CMDLINE [ndroidboot.selinux=permissive ��_�]
CHECKSUM [c6]
Invalid DTB detection at 0xe936a2: header tag of first node != FDT_BEGIN_NODE
Invalid DTB detection at 0xe9e587: header tag of first node != FDT_BEGIN_NODE
Invalid DTB detection at 0xea93ad: header tag of first node != FDT_BEGIN_NODE
Invalid DTB detection at 0xeb4133: header tag of first node != FDT_BEGIN_NODE
Segmentation fault
- Checking ramdisk status
MagiskBoot v18.1(18100) (by topjohnwu) - Boot Image Modification Tool
- Stock boot image detected
- Backing up stock boot image
MagiskBoot v18.1(18100) (by topjohnwu) - Boot Image Modification Tool
Compressing to [stock_boot_2f3acf3530c9d7aafc3a2370f747a32ea107f0a3.img.gz]
cp: can't stat 'ramdisk.cpio': No such file or directory
- Patching ramdisk
MagiskBoot v18.1(18100) (by topjohnwu) - Boot Image Modification Tool
Add entry [init] (0750)
Patch with flag KEEPVERITY=[false] KEEPFORCEENCRYPT=[true]
Segmentation fault
- Repacking boot image
MagiskBoot v18.1(18100) (by topjohnwu) - Boot Image Modification Tool
Parsing boot image: [/data/user_de/0/com.topjohnwu.magisk/install/boot.img]
HEADER_VER [0]
KERNEL_SZ [22504320]
RAMDISK_SZ [4067161]
SECOND_SZ [4278190336]
EXTRA_SZ [738199576]
RECOV_DTBO_SZ [3489687392]
OS_VERSION [41.68.0]
PATCH_LEVEL [2000-01]
PAGESIZE [8]
NAME [RPRA09A001KU]
CMDLINE [ndroidboot.selinux=permissive ��_�]
CHECKSUM [c6]
Invalid DTB detection at 0xe936a2: header tag of first node != FDT_BEGIN_NODE
Invalid DTB detection at 0xe9e587: header tag of first node != FDT_BEGIN_NODE
Invalid DTB detection at 0xea93ad: header tag of first node != FDT_BEGIN_NODE
Invalid DTB detection at 0xeb4133: header tag of first node != FDT_BEGIN_NODE
Segmentation fault
! Unable to repack boot image!
! Installation failed
Hello i want to install magisk on my SM-G390F, on android 8.1.0, baseband G390FXXU2BRH3, when i patch the boot.img i get this errors
Code:
- Copying image to cache
- Device platform: armeabi-v7a
- Downloading zip
... 0%
- Extracting files
boot_patch.sh[73]: can't create /proc/self/fd/: Is a directory
MagiskBoot v17.1(17100) (by topjohnwu) - Boot Image Modification Tool
Parsing boot image: [/data/user_de/0/com.topjohnwu.magisk/install/boot.img]
KERNEL [14758304]
RAMDISK [2478705]
SECOND [0]
EXTRA [376832]
PAGESIZE [2048]
OS_VERSION [8.1.0]
PATCH_LEVEL [2018-08]
NAME [SRPPK23A000KU]
CMDLINE [androidboot.selinux=permissive androidboot.selinux=permissive]
CHECKSUM [72c35f6755e256251a06f7f26c7d0d111dc8ceeb]
KERNEL_FMT [raw]
RAMDISK_FMT [gzip]
boot_patch.sh[98]: can't create /proc/self/fd/: Is a directory
MagiskBoot v17.1(17100) (by topjohnwu) - Boot Image Modification Tool
Loading cpio: [ramdisk.cpio]
boot_patch.sh[120]: can't create /proc/self/fd/: Is a directory
boot_patch.sh[120]: can't create /proc/self/fd/: Is a directory
MagiskBoot v17.1(17100) (by topjohnwu) - Boot Image Modification Tool
Compressing to [stock_boot_445cd3cd8b66e965c8ab1fc3850aab7d36aef5a8.img.gz]
boot_patch.sh[126]: can't create /proc/self/fd/: Is a directory
MagiskBoot v17.1(17100) (by topjohnwu) - Boot Image Modification Tool
Loading cpio: [ramdisk.cpio]
Add entry [init] (0750)
Patch with flag KEEPVERITY=[false] KEEPFORCEENCRYPT=[false]
Remove pattern [,verify]
Replace pattern [forceencrypt] with [encryptable]
Save SHA1: [445cd3cd8b66e965c8ab1fc3850aab7d36aef5a8] -> [.backup/.sha1]
Loading cpio: [ramdisk.cpio.orig]
Backup mismatch entry: [fstab.samsungexynos7570] -> [.backup/fstab.samsungexynos7570]
Backup mismatch entry: [init] -> [.backup/init]
Dump cpio: [ramdisk.cpio]
MagiskBoot v17.1(17100) (by topjohnwu) - Boot Image Modification Tool
Loading dtbs from [extra]
MagiskBoot v17.1(17100) (by topjohnwu) - Boot Image Modification Tool
MagiskBoot v17.1(17100) (by topjohnwu) - Boot Image Modification Tool
MagiskBoot v17.1(17100) (by topjohnwu) - Boot Image Modification Tool
MagiskBoot v17.1(17100) (by topjohnwu) - Boot Image Modification Tool
Patch @ 00CD8752 [736B69705F696E697472616D6673]->[77616E745F696E697472616D6673]
boot_patch.sh[169]: can't create /proc/self/fd/: Is a directory
MagiskBoot v17.1(17100) (by topjohnwu) - Boot Image Modification Tool
Parsing boot image: [/data/user_de/0/com.topjohnwu.magisk/install/boot.img]
KERNEL [14758304]
RAMDISK [2478705]
SECOND [0]
EXTRA [376832]
PAGESIZE [2048]
OS_VERSION [8.1.0]
PATCH_LEVEL [2018-08]
NAME [SRPPK23A000KU]
CMDLINE [androidboot.selinux=permissive androidboot.selinux=permissive]
CHECKSUM [72c35f6755e256251a06f7f26c7d0d111dc8ceeb]
KERNEL_FMT [raw]
RAMDISK_FMT [gzip]
Repack to boot image: [new-boot.img]
KERNEL [14758304]
RAMDISK [2722538]
SECOND [0]
EXTRA [376832]
PAGESIZE [2048]
OS_VERSION [8.1.0]
PATCH_LEVEL [2018-08]
NAME [SRPPK23A000KU]
CMDLINE [androidboot.selinux=permissive androidboot.selinux=permissive]
CHECKSUM [72d64a95fd6cd020abf973d2d081b0c9b0cdf320]
MagiskBoot v17.1(17100) (by topjohnwu) - Boot Image Modification Tool
Cleaning up...
****************************
Patched image is placed in
/storage/emulated/0/Download/patched_boot.img.tar
****************************
- All done!
My boot.img and the patched boot image links are bellow as the files are to big to attach, if anyone can help me out that will be great.
https://www.dropbox.com/s/i2jtq7cxtf8rw7z/boot.img?dl=0
https://www.dropbox.com/s/i2jtq7cxtf8rw7z/boot.img?dl=0
If i ignore the above and go ahead and flash the patched image trough odin i get this after the phone boots
https://i.imgur.com/hkrbddB.jpg
Now i reseted the phone , restart funny i still have magisk 17.1 installed but my problem now is that my imei is gone and so my network connection so i'm not able to get any signal from any mobile network (ee,o2,vodafone etc)
If i try to install a module from magisk i get the fallowing error: Unable to extract zip file. Installation failed!
Root on the other hand is working.
If i reflash the stock all comes back to normal
Can anyone give me hand with this.
Many Thanks,
George
Right i found a half way, i installed a twrp even if my phone was going in boot loop with it then installed magisk reboot then my phone started just fine and with the magisk
FreeTheWeb said:
Right i found a half way, i installed a twrp even if my phone was going in boot loop with it then installed magisk reboot then my phone started just fine and with the magisk
Click to expand...
Click to collapse
Hi ! Can you help me to install TWRP and Magisk on my Xcover 4 ? I can't find any TWRP version for it ... thanks
Hi this is what i used
https://drive.google.com/file/d/1CS9DIdUyw_QmhYcorcUwYZGZCGGYfolz/view?usp=sharing
FreeTheWeb said:
Hi this is what i used
https://drive.google.com/file/d/1CS9DIdUyw_QmhYcorcUwYZGZCGGYfolz/view?usp=sharing
Click to expand...
Click to collapse
Thanks but it does not work ..
I got "fail to open recovery no such file or directory"
"no support single sku"
"E:unknown volume for path [/odm]"
"E:unknown volume for path [/vendor]"
maybe cause i'm on android 8.1 ?
I will try to install magisk without TWRP with the "boot.img" trick...
Thanks alot FreeTheWeb
You saved my phone, i have been trying 20 different ways in 30 hours and finally i got into TWRP.
Used: G390FXXU2BRJ1 Firmware from sammobile.
I also have Xcover 4 on 8.1 oreo and I have the same problems. Patching boot causes no signal range, TWRP is missing for this model, and installing this from a thread causes a message like the user of Doc_Emmett_Brown. At Nougat, I had root patching boot.iso without any problems, and here Oreo are the problems. Please help.
Zdzisław said:
I also have Xcover 4 on 8.1 oreo and I have the same problems. Patching boot causes no signal range, TWRP is missing for this model, and installing this from a thread causes a message like the user of Doc_Emmett_Brown. At Nougat, I had root patching boot.iso without any problems, and here Oreo are the problems. Please help.
Click to expand...
Click to collapse
Hi! Can you explain how do you get root at Nougat on Xcover4? I have this one and I can't find any working solution.
Read my previous posts to get magisk on your xcover.
Zdzisław said:
I also have Xcover 4 on 8.1 oreo and I have the same problems. Patching boot causes no signal range, TWRP is missing for this model, and installing this from a thread causes a message like the user of Doc_Emmett_Brown. At Nougat, I had root patching boot.iso without any problems, and here Oreo are the problems. Please help.
Click to expand...
Click to collapse
i have the same problem, after flashing patched boot img, im getting no signal bug
Works on Xperia XZ1? ?
Sent from my Sony H9436 using XDA Labs
HI
Update 13.04.2023 /bs
To install Magisk v26.0 or newer the script version 25.01.2023 v2.5.1.0 is necessary.
Unfortunately there is a new feature in Magisk v26.x that prevents the full installation of Magisk from within a booted recovery; from the Magisk docs:
This means that any installation of Magisk v26+ using custom recovery will be incomplete; a subsequent re-installation through the Magisk app after booting up is required.
Click to expand...
Click to collapse
Therefor currently the installation of Magisk v26.x via script without user intervention does not yet work
I wrote a little shell script for Linux (bash) to add Magisk to the boot partition of a phone without user intervention called install_magisk_via_twrp.sh.
This is useful for example to re-install Magisk into the boot partition after an OS upgrade .
The script uses only the commands fastboot and adb, a recovery image (e.g. TWRP), and the patch script from Magisk to re-install Magisk into the boot partition.
Notes
Note that the script version 1.1.0.0 or newer also works if the phone is secured via PIN or something similar.
Since version 2.0.0.0 it is not necessary anymore to install Magisk via Magisk App into a boot image file before starting the script.
Since version 2.0.0.0 the script can install Magisk into the partition even if the Magisk app is not installed yet.
SInce version 2.1.0.0 the script will also copy the Magisk apk to the phone file if requested via parameter.
Version 2.5.1.0 of the script install_magisk_via_twrp.sh or newer of the script is necessary to install Magisk v26.1 or newer
The usage for the script is:
Code:
[ OmniRom 13 Dev - [email protected] /data/develop/android/scripts_on_linux ] $ ./install_magisk_via_twrp.sh -h
install_magisk_via_twrp.sh version - v2.3.0.0 - add Magisk to the boot partition of a phone running Android using TWRP
install_magisk_via_twrp.sh [-h|help|-H] [boot_slot] [wait=n] [dd|fastboot] [twrp_image] [cleanup] [delete_adb_dir] [adb_only] [use_apk] [copy_apk]
[ OmniRom 13 Dev - [email protected] /data/develop/android/scripts_on_linux ] $
Use the parameter -H to print the detailed usage:
Spoiler: Detailed usage
Code:
[ OmniRom 13 Dev - [email protected] /data/develop/android/scripts_on_linux ] $ ./install_magisk_via_twrp.sh -H
install_magisk_via_twrp.sh version - v2.3.0.0 - add Magisk to the boot partition of a phone running Android using TWRP
Usage
install_magisk_via_twrp.sh [-h|help|-H] [boot_slot] [wait=n] [dd|fastboot] [twrp_image] [cleanup] [delete_adb_dir] [adb_only] [use_apk] [copy_apk]
All parameter are optional. The parameter can be used in any order.
Use the parameter "help" or "-H" to print the detailed usage help; use the parameter "-h" to print only the short usage help
The parameter "boot_slot" can be a, b, active, inactive, next, current; default is the current boot slot of the phone
The value for the parameter "wait" is the number of seconds to wait before starting the script to install Magisk on the phone
This seems to be necessary to avoid errors while repacking the boot image. The default wait time is 10 seconds.
Use the parameter "dd" to request repatching via dd in an adb session ; use the parameter "fastboot" to request repatching via "fastboot"
Default is to use "dd" to flash the patched boot image.
The parameter "twrp_image" can be used to define another TWRP image to use. The parameter is optional - the
default for "twrp_image" is hardcoded in the script (variable TWRP_IMAGE)
The default TWRP image of the script is the TWRP for the ASUS Zenfone 8.
Use the parameter "cleanup" to delete the directory /data/MagiskInst at script end
If the parameter "delete_adb_dir" is used the script will delete all files and directories created in the directory /data after Magisk
was successfully installed into the boot partition
If the parameter "adb_only" is used the script will only install the directories and binaries for Magisk in the directory /data/adb.
The script will unpack the necesseray files for adding Magisk to the boot partition from the installed Magisk apk file to
the temporary directory /data/MagiskInst if the files in /data/adb/magisk are missing.
Use the parameter "use_apk" to force the script to use the files from the Magisk app even if the files in /data/adb/magisk exist.
If the parameter "copy_apk" is used the script will copy the Magisk apk file to the phone.
The script now can also install Magisk into a boot partition without an installed Magisk app. To use this feature copy the Magisk apk file
(Magisk*apk) to the directory /data or /sdcard/Download on the phone before starting the script or use the parameter "copy_apk".
The phone to patch must be attached via USB.
The phone can be either in fastboot mode, in normal mode with enabled adb support, or already booted from the TWRP image
To change some of the values used by the script you can set environment variables before starting the script:
Set the environment variable REBOOT to "yes" before starting the script to automatically reboot the phone after patching the new image
Set the environment variable REBOOT to "no" before starting the script to disable the automatic reboot after patching the new image.
Set the environment variable SERIAL_NUMBER to the serial number of the phone to patch if there is more then one phone connected via USB
Set the environment variable ADB_OPTIONS to the options to be used with the adb command
Set the environment variable FASTBOOT_OPTIONS to the options to be used with the fastboot command
Set the environment variable DOWNLOAD_DIR_ON_PHONE to the data directory to use on the phone (def.: /sdcard/Download)
Set the envionment variable MAGISK_APK_FILE to the Magisk apk file to use
The default TWRP image to use is "/data/backup/ASUS_ZENFONE8/twrp/current_twrp.img"
[ OmniRom 13 Dev - [email protected] /data/develop/android/scripts_on_linux ] $
In the default the script will ask the user for input before rebooting the phone from the patched boot partition.
To disable this request call the script like this
Code:
REBOOT=yes install_magisk_via_twrp.sh
Additional infos
Prerequisites
the Magisk App; either installed or as apk file
a computer running Linux with working adb and fastboot binaries available via PATH variable
a phone with unlocked boot loader
a working recovery image (e.g. TWRP) for the attached phone that automatically mounts /data and has enabled adb support (For the ASUS Zenfone 8 the official TWRP image from https://twrp.me/asus/zenfone8.html version 3.7.0 or newer can be used)
Test Environment
Tested on an ASUS Zenfone 8 and with
OmniROM 12 (Android 12) and Magisk v24.3
OmniROM 12 (Android 12) and Magisk v25.0
OmniROM 12 (Android 12) and Magisk v25.2
OmniROM 13 (Android 13) and Magisk v25.2
AospExtended 9.0 w/o GAPPS (Android 12) and Magisk v24.3
AospExtended 9.0 w/o GAPPS (Android 12) and Magisk v25.0
ASUS Original Android 11 and Magisk v24.3
ASUS Original Android 12 and Magisk v24.3
ASUS Original Android 13 Beta 1 and Magisk v25.0
Details
The script uses the scripts and binaries from the directory /data/adb/magisk. If these executables do not exist the script searches for the installed Magisk apk file /data/app/*/com.topjohnwu.magisk*/base.apk and extracts the scripts and binaries from that file. If the Magisk apk is not installed the script searches for the Magisk APK file Magisk*.apk in the directories /sdcard/Download and /data and extracts the scripts and executables from that file if found.
If the parameter copy_apk is used the script copies the Magisk apk file to the directory /sdcard/Download on the phone or, if that directory does not exist, to the directory /data on the phone
The patched boot images will be created in the directory /sdcard/Downloads on the phone (variable DOWNLOAD_DIR_ON_PHONE)
The script uses the original script called boot_patch.sh from Magisk to patch the boot image.
You can execute the script as often as you like.
The script will not delete the created files in the directory /sdcard/Download on the phone so you might do a cleanup of that directory manual
If the directory /sdcard/Download is not available the script will use the directory /tmp for temporary files (Note: /tmp is mounted on a ramdisk)
If the check sum of the boot image before the patching is equal to the check sum after the successfull patching then Magisk was already installed in the boot partition
The script will boot the phone up to 4 times.
Trouble Shooting
- Error message like this
Code:
/data/adb/magisk/boot_patch.sh[211]: can't create /proc/self/fd/: Is a directory
can be ignored (these are only error messages from the function to print some additional messages)
Note: Since version 2.0.0.0 these error messages should not occur anymore.
- Patching the boot partition via "dd" fails sometimes for unknown reason so you should only use it if you know how to fix a damaged boot partition!
- Downloading the patched boot image via "adb pull" (neccessary for patching the boot partition using fastboot) sometimes fails for unknown reason:
So if you get an error message like this:
Code:
[ 77%] /sdcard/Download/patched_boot_a.391985.img
ERROR: Error downloading the file "/sdcard/Download/patched_boot_a.391985.img" from the phone!
just restart the script again (or download the file and flash the boot partition manually)
- If the adb connection dies and there are error messages like this
Code:
adb: insufficient permissions for device
restart the adb server using
Code:
adb kill-server
if that does not work disconnect and reconnect the USB cable
Spoiler: Sample output of the script
Code:
[[email protected] /data/backup/Android/scripts_on_linux]$ ./install_magisk_via_twrp.sh
./install_magisk_via_twrp.sh version - 2.0.0.0 - add Magisk to the boot partition of a phone running Android using TWRP
Using the TWRP image hardcoded in the script: "/data/backup/ASUS_ZENFONE8/twrp/twrp-3.7.0_12-0-I006D.img"
Checking the script prerequisites ...
Will wait 10 second(s) before starting the script on the phone
The script is running as user "xtrnaw7" -- will use "sudo" for the fastboot commands ...
Will patch the boot partition on the attached phone with the serial number "M6AIB760D0939LX"
Using the options "-d -s M6AIB760D0939LX " for the adb commands
Using the options " -s M6AIB760D0939LX " for the fastboot commands
Checking for a connected phone booted into fastboot mode ...
No attached phone in fastboot mode found
Checking for an attached phone with working access via adb (USB) ...
Linux localhost 5.4.147-Omni-qgki-perf-gea6f815f5af9-dirty #42 SMP PREEMPT Tue Sep 27 18:03:41 CEST 2022 aarch64
... found a phone connected via USB with working adb access
The phone is booted in normal mode
The installed OS is based on Android 12 (Wed Aug 10 06:59:46 CEST 2022); the description for the distribution is "omni_zenfone8-user 12 SQ3A.220605.009.A1 eng.xtrnaw.20220810.065947 release-keys"
The installed version of Magisk is com.topjohnwu.magisk versionCode 25200
Booting the phone into the fastboot mode now ...
Waiting up to 60 seconds for the boot into the fastboot mode ...
Booting the phone from the TWRP image "/data/backup/ASUS_ZENFONE8/twrp/twrp-3.7.0_12-0-I006D.img" now ...
Sending 'boot.img' (98304 KB) OKAY [ 2.489s]
Booting OKAY [ 10.359s]
Finished. Total time: 12.888s
Waiting up to 60 seconds for the boot of the phone ....
Retrieving the current boot slot from the phone ...
The current boot slot is "_b"
The boot slot to patch is "_b"
The boot partition to patch is "boot_b"
Checking if the Magisk patch script "boot_patch.sh" exists on the phone ....
-rwxr-xr-x 1 root root 5987 2022-10-27 07:33 /data/adb/magisk/boot_patch.sh
Checking if the download directory "/sdcard/Download" exists on the phone ....
/sdcard/Download
Creating the boot image file "/sdcard/Download/boot_b.732627.img" from the partition "/dev/block/by-name/boot_b" ...
196608+0 records in
196608+0 records out
100663296 bytes (96 M) copied, 0.308243 s, 311 M/s
Checking the result ...
-rw-rw---- 1 root media_rw 100663296 2022-10-28 09:51 /sdcard/Download/boot_b.732627.img
The check sums are:
The check sum of the boot partition "/dev/block/by-name/boot_b" on the phone is "4108888341"
The check sum of th boot image file on the phone is "/sdcard/Download/boot_b.732627.img" is "4108888341"
Patching the boot image file "/sdcard/Download/boot_b.732627.img" ...
Waiting now 10 seconds ...
- Unpacking boot image
Parsing boot image: [/sdcard/Download/boot_b.732627.img]
HEADER_VER [3]
KERNEL_SZ [42025472]
RAMDISK_SZ [34080597]
OS_VERSION [12.0.0]
OS_PATCH_LEVEL [2022-05]
PAGESIZE [4096]
CMDLINE []
KERNEL_FMT [raw]
RAMDISK_FMT [gzip]
VBMETA
- Checking ramdisk status
Loading cpio: [ramdisk.cpio]
- Stock boot image detected
- Patching ramdisk
Loading cpio: [ramdisk.cpio]
Add entry [init] (0750)
Create directory [overlay.d] (0750)
Create directory [overlay.d/sbin] (0750)
Add entry [overlay.d/sbin/magisk64.xz] (0644)
Patch with flag KEEPVERITY=[false] KEEPFORCEENCRYPT=[false]
Found fstab file [system/etc/fstab.postinstall]
Remove pattern [,avb_keys=/product/etc/security/avb/system_other.avbpubkey]
Loading cpio: [ramdisk.cpio.orig]
Backup mismatch entry: [init] -> [.backup/init]
Record new entry: [overlay.d] -> [.backup/.rmlist]
Record new entry: [overlay.d/sbin] -> [.backup/.rmlist]
Record new entry: [overlay.d/sbin/magisk64.xz] -> [.backup/.rmlist]
Backup mismatch entry: [system/etc/fstab.postinstall] -> [.backup/system/etc/fstab.postinstall]
Create directory [.backup] (0000)
Add entry [.backup/.magisk] (0000)
Dump cpio: [ramdisk.cpio]
- Repacking boot image
Parsing boot image: [/sdcard/Download/boot_b.732627.img]
HEADER_VER [3]
KERNEL_SZ [42025472]
RAMDISK_SZ [34080597]
OS_VERSION [12.0.0]
OS_PATCH_LEVEL [2022-05]
PAGESIZE [4096]
CMDLINE []
KERNEL_FMT [raw]
RAMDISK_FMT [gzip]
VBMETA
Repack to boot image: [new-boot.img]
HEADER_VER [3]
KERNEL_SZ [42025472]
RAMDISK_SZ [34331854]
OS_VERSION [12.0.0]
OS_PATCH_LEVEL [2022-05]
PAGESIZE [4096]
CMDLINE []
Checking the result ...
-rw-r--r-- 1 root root 100663296 2022-10-28 09:51 /data/adb/magisk/new-boot.img
The patched boot image is "/sdcard/Download/patched_boot_b.732627.img"
Waiting now 5 seconds ...
Patching the partition "/dev/block/by-name/boot_b" from the patched boot image file "/sdcard/Download/patched_boot_b.732627.img" via dd ...
196608+0 records in
196608+0 records out
100663296 bytes (96 M) copied, 4.721236 s, 20 M/s
Checking the result ....
The check sums for the images and devices on the phone are:
4108888341 100663296 /sdcard/Download/boot_b.732627.img
3369959638 100663296 /sdcard/Download/patched_boot_b.732627.img
3369959638 100663296 /dev/block/by-name/boot_b
OK, patching the boot partition "/dev/block/by-name/boot_b" was successfull
*** Press return to reboot the phone now
Rebooting the phone now ...
[[email protected] /data/backup/Android/scripts_on_linux]$
Update 03.07.2022 /bs
The script now uses the directory /tmp for temporary file if the directory /sdcard/Download is not available. Therefor it will also work if the phone is secured by a PIN or something similar.
Update 05.07.2022/bs
The script is also available on my web site:
http://bnsmb.de/files/public/Android/install_magisk_via_twrp.sh
Update 30.12.2022/bs
Updated the usage help for the script to match the version 2..3.0 of the script
Update 28.10.2022 /bs
Updated the post to match the new script version 2.0.0.0
Update 17.12.2022 /bs
Updated the post to match the new script version 2.1.0.0
see here for How to install TWRP via script
Update 13.04.2023 /bs
To install Magisk v26.0 or newer the script version 25.01.2023 v2.5.1.0 is necessary.
Unfortunately there is a new feature in Magisk v26.x that prevents the full installation of Magisk from within a booted recovery; from the Magisk docs:
This means that any installation of Magisk v26+ using custom recovery will be incomplete; a subsequent re-installation through the Magisk app after booting up is required.
Click to expand...
Click to collapse
Therefor currently the installation of Magisk v26.x via script without user intervention does not yet work
In Magisk v26.0 the developer changed the code so that it's not possible anymore to install Magisk into the boot partition while booted from a recovery image.
from the Magisk change log:
"This means that any installation of Magisk v26+ using custom recovery will be incomplete; a subsequent re-installation through the Magisk app after booting up is required."
The installation of Magisk v26.x while booted into the recovery (for example using my script install_magisk_via_twrp.sh; see How to install Magisk into the boot partition using script) will succeed but executing the Magisk app after the necessary reboot will end with this dialog:
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
After pressing OK in that dialog Magisk will reinstall itself in the boot partition and reboot. And afterwards Magisk works again. But that step needs user intervention.
Without executing this additional step Magisk won't work. There is no way to trigger this reinstallation via an CLI command that is usable in a script (at least I did not found it until now ...)
Unfortunately, Magisk also does not execute the init scripts from /data/adb/post-fs-data.d or /data/adb/service.d in this state.
Therefor the automatic installation of Android, TWRP, Magisk, etc like implemented in the tasks in prepare_phone.include (see How to install and configure the Android OS for details) will fail.
To get around this I added some code to the script install_magisk_via_twrp.sh to support the installation of Magisk v26:
install_magisk_via_twrp.sh version v3.1.0.0 (or newer) can now be used to also install Magisk v26 into the boot partition. There are two new parameter for the script install_magisk_via_twrp.sh to select the method to use for the installation:
oldmethod - install Magisk into the boot partition while booted into a recovery
newmethod - install Magisk into the boot partition image while booted into the Android OS
The installation using the "newmethod" only works if their is a working adb connection to the running Android OS on the phone.
Without one of the two new parameter the script will check the Magisk apk file to detect the necessary method to install Magisk into the boot partition. The default method if no apk file is used is still the old method.
Patching the boot image with Magisk v26 is done using these steps:
boot the phone from a TWRP image
create an image of the boot partition while booted from the TWRP image
copy the boot partition image and the Magisk executables to a directory that can be accessed by the user shell while booted into the Anroid OS
boot the phone into the Android OS
patch the boot partition image using the Magisk binaries (that can be done by the non-root user shell)
reboot the phone from a TWRP image
install the patched boot image via dd or fastboot
To do an automatic installation via script using Magisk v26 I added another task to prepare_phone.include:
install_magisk_v26_in_boot_partition
This task will install Magisk using the new method described above.
Because the installation of Magisk v26 needs a working adb connection the tasks in prepare_phone.include will first install Magisk v25.x and enable adb via Magisk init script like before. After this is done Magisk v26 can be installed via script.
So the new task list to install and configure the Android OS using the tasks in the file prepare_phone.include is:
Bash:
DEFAULT_TASKS="
enable_disable_abort_on_error:enable
boot_phone_from_twrp_image
install_os:noreboot:factory_reset
install_twrp:noreboot:next
#
# first install Magisk v25.x into the boot partition; this installation is necessary to
# enable the access via adb to the phone; the Magisk installation will be overwritten later
# with Magisk v26 or newer
#
install_magisk_in_boot_partition_only:noreboot:next
enable_adb:reboot
#
install_magisk_in_data_adb_only:noreboot:copy_apk
enable_root_access_for_the_shell:reboot
wait_for_access_via_adb:120:kill
#
# the next step is necessary to install Magisk v26 or newer
#
install_magisk_v26_in_boot_partition:active:reboot
install_the_magisk_app
wait_for_access_via_adb:120:kill
enable_disable_abort_on_error:disable
install_essential_scripts
install_essential_apps
install_essential_magisk_modules
enable_root_access_for_apps:reboot
execute_script_on_the_phone:ignorerc
"
To distinguish between the apk files for Magisk v25 and Magisk v26 two new variables must be defined in the config file prepare_phone.conf for the tasks in prepare_phone.include:
Bash:
MAGISK_v26_APK_FILE="/data/backup/Android/EssentialApps/Magisk-v26.1.apk"
MAGISK_v25_APK_FILE="/data/backup/Android/EssentialApps_Backup/Magisk-v25.2.apk"
see here for the log of an update of Magisk v25 to Magisk v26 via script using the command
Bash:
./prepare_phone.sh install_magisk_v26_in_boot_partition
see here for the log of an automated installation using the tasks in prepare_phone.include with the installation of Magisk v26 using the command
Bash:
./prepare_phone.sh all
Testenvironments for the installation of Magisk v26 via script
an ASUS Zenfone 8 running
OmniROM 13 with MicroG and Magisk v26.1
OmniROM 12 with MicroG and Magisk v26.1
ASUS Android 13 and Magisk v26.1
ASUS Android 12 and Magisk v26.1
LineageOS 19 and Magisk v26.1
All tests were done using TWRP 3.7.0.12
How to install TWRP via script
The recovery image TWRP is very useful for the maintenance of the Android OS. You can either boot the phone from the TWRP image without installing it using these commands:
Bash:
adb reboot bootloader
sudo fastboot boot ./twrp-3.7.0_12-0-I006D.img
or install the TWRP image into the boot partition and use the command
Bash:
adb reboot recovery
or
Bash:
sudo fastboot boot recovery
to boot into TWRP. Depending on the OS used there is also an option in the reboot dialog in the GUI to reboot into the recovery.
While the phone is booted from TWRP you can open a shell as user root via adb.
The only official method to install TWRP into the boot partition of the phone is via the TWRP GUI, e.g.:
boot the phone from the TWRP image (see above)
install TWRP into the boot partition using the menu entry "Advanced" and then "Flash Current TWRP". TWRP will then install itself into both boot partitions.
There is no method to install TWRP without user interaction via a script (at least I did not found any ...). Therefor I wrote a shell script to install TWRP without user input:
install_twrp_from_within_twrp.sh
The script install_twrp_from_within_twrp.sh can be used to install TWRP either into a boot partition or into an image file for the boot partition. The script must be executed in a shell on the phone while the phone is booted from the TWRP image that should be installed.
The usage of the script is:
Code:
ASUS_I006D:/data/local/tmp $ ./install_twrp_from_within_twrp.sh -h
install_twrp_from_within_twrp.sh - script to install TWRP into a boot partition or into a file
Usage:
install_twrp_from_within_twrp.sh [-f] [boot_image_file] [new_boot_image_file]
boot_image can be either an image file from the boot partition or a boot partition block device
(e.g. /dev/block/by-name/boot_a)
new_boot_partition_file must be the absolute name of a file.
Both parameter are optional
If the script is called without a parameter TWRP will be installed in the current boot partition.
If boot_image_file is a block device and new_boot_image_file is missing TWRP will be installed in the block device.
If the parameter new_boot_image_file is used the script will only write a boot partition image with TWRP into that file.
Use the parameter -f to ignore missing or invalid checksums.
This script must run in a shell in TWRP
Environment variables used by the script if set:
BIN_DIR (Current value: "/system/bin")
TMPDIR (Current value: "/data/local/tmp")
|ASUS_I006D:/data/local/tmp $
The commands used in the script install_twrp_from_within_twrp.sh to install TWRP are copied from the TWRP source file with the code to install TWRP:
https://github.com/TeamWin/android_bootable_recovery/blob/android-12.1/twrpRepacker.cpp
Note that TWRP contains a copy of the binary magiskboot to unpack and repack the boot partition. Therefor the installation should work on all phones that are supported by Magisk.
Be aware that the installation of TWRP will wipe out the installation of Magisk (or any other tool for enabling root access). So for installing TWRP and Magisk they must be installed in this order:
install TWRP
install Magisk (or a similar tool)
Example usage:
Code:
ASUS_I006D:/ # /cache/install_twrp_from_within_twrp.sh /dev/block/by-name/boot_b
Installing TWRP into a boot image or boot partition via script
Checking the running OS ...
OK, running a shell in TWRP: "twrp_I006D" version "3.7.0_12-0"
Checking the prerequisites for installing TWRP ...
Using the partition "/dev/block/by-name/boot_b" as source for the installation of TWRP
Creating the new boot image with TWRP in the file "/data/local/tmp/img.568/new-boot.img"
Checking if the required executables exist ...
OK, the file "/system/bin/magiskboot" exists and is executable
OK, the file "/system/bin/cpio" exists and is executable
OK, the file "/system/bin/sha256sum" exists and is executable
OK, the file "/system/bin/getprop" exists and is executable
OK, the file "/system/bin/dd" exists and is executable
Checking if the requried data files exist ...
OK, the file "/ramdisk-files.sha256sum" exists
OK, the file "/ramdisk-files.txt" exists
OK, the file "/dev/block/by-name/boot_b" exists
Checking the check sums of the files for the new ramdisk ...
OK, the check sums of the files for the new ramdisk are okay
Directory "/data/local/tmp" successfully created
Directory "/data/local/tmp/img.568" successfully created
Directory "/data/local/tmp/img_files.568" successfully created
The temporary directory to unpack the boot image is "/data/local/tmp/img_files.568"
Unpacking the boot image from "/dev/block/by-name/boot_b" ...
Parsing boot image: [/dev/block/by-name/boot_b]
HEADER_VER [3]
KERNEL_SZ [42027520]
RAMDISK_SZ [34080747]
OS_VERSION [12.0.0]
OS_PATCH_LEVEL [2022-05]
PAGESIZE [4096]
CMDLINE []
KERNEL_FMT [raw]
RAMDISK_FMT [gzip]
VBMETA
OK, "/dev/block/by-name/boot_b" successfully unpacked to "/data/local/tmp/img_files.568" :
Creating a backup of the original ramdisk ...
total 74412
-rw-rw-rw- 1 root root 50 2022-10-24 19:35 header
-rw-r--r-- 1 root root 42027520 2022-10-24 19:35 kernel
-rw-r--r-- 1 root root 34080747 2022-10-24 19:35 ramdisk.cpio.org
Creating the new ramdisk with TWRP ...
New ramdisk with TWRP "/data/local/tmp/img_files.568/ramdisk.cpio" successfully created.
-rw-rw-rw- 1 root root 85852380 2022-10-24 19:35 /data/local/tmp/img_files.568/ramdisk.cpio
-rw-r--r-- 1 root root 34080747 2022-10-24 19:35 /data/local/tmp/img_files.568/ramdisk.cpio.org
Repacking the boot image into the file "/data/local/tmp/img.568/new-boot.img" ...
+ cd /data/local/tmp/img_files.568
+ /system/bin/magiskboot repack /dev/block/by-name/boot_b /data/local/tmp/img.568/new-boot.img
Parsing boot image: [/dev/block/by-name/boot_b]
HEADER_VER [3]
KERNEL_SZ [42027520]
RAMDISK_SZ [34080747]
OS_VERSION [12.0.0]
OS_PATCH_LEVEL [2022-05]
PAGESIZE [4096]
CMDLINE []
KERNEL_FMT [raw]
RAMDISK_FMT [gzip]
VBMETA
Repack to boot image: [/data/local/tmp/img.568/new-boot.img]
HEADER_VER [3]
KERNEL_SZ [42027520]
RAMDISK_SZ [34080769]
OS_VERSION [12.0.0]
OS_PATCH_LEVEL [2022-05]
PAGESIZE [4096]
CMDLINE []
+ TEMPRC=0
+ set +x
OK, the new boot image "/data/local/tmp/img.568/new-boot.img" successfully created
-rw-r--r-- 1 root root 100663296 2022-10-24 19:35 /data/local/tmp/img.568/new-boot.img
Now rewriting "/dev/block/by-name/boot_b" using "/data/local/tmp/img.568/new-boot.img" ...
196608+0 records in
196608+0 records out
100663296 bytes (96 M) copied, 4.498630 s, 21 M/s
TWRP successfully installed in "/dev/block/by-name/boot_b"
ASUS_I006D:/ #
To install TWRP using the script without user input these steps are neccessary:
reboot the phone into the bootloader
boot the phone from the TWRP image that should be installed on the phone
copy the script install_twrp_from_within_twrp.sh to the phone
execute the script install_twrp_from_within_twrp.sh on the phone in an adb shell
To automate these steps I wrote a wrapper script :
install_twrp.sh
The wrapper script install_twrp.sh must be executed on a machine running Linux with the phone attached via USB.
The wrapper script will check the current status of the phone, boot the phone from the TWRP image, copy the script install_twrp_from_within_twrp.sh to the phone and execute it on the phone to install TWRP into either the active or the inactive boot partition.
The script install_twrp_from_within_twrp.sh must be in the same directory as install_twrp.sh (if not set the variable TWRP_INSTALL_SCRIPT before executing the script -- see the script usage below).
The usage for the script install_twrp.sh is:
Code:
[[email protected] /data/develop/android/scripts_on_linux]$ ./install_twrp.sh -h
./install_twrp.sh version - 1.0.0.0 - install TWRP to the boot partition of a phone running Android using TWRP
Usage
install_twrp_via_twrp.sh [boot_slot] [wait=n] [dd|fastboot] [twrp_image]
All parameter are optional
The parameter "boot_slot" can be a, b, active, inactive, next, current; default is the current boot slot of the phone
Use the parameter "dd" to request repatching via dd in an adb session ; use the parameter "fastboot" to request repatching via "fastboot"
Default is to use "dd" to flash the patched boot image
The value for the parameter "wait" is the number of seconds to wait before starting the script "install_twrp_from_within_twrp.sh" on the phone
This seems to be necessary to avoid errors while repacking the boot image. The default wait time is 10 seconds.
The parameter "twrp_image" can be used to define another TWRP image to use. The parameter is optional - the
default for "twrp_image" is hardcoded in the script (variable TWRP_IMAGE)
The default TWRP image of the script is the TWRP for the ASUS Zenfone 8.
The phone to patch must be attached via USB.
The phone can be either in fastboot mode, in normal mode with enabled adb support, or already booted from the TWRP image
The script uses the script "install_twrp_from_within_twrp.sh" to install TWRP. The script install_twrp_from_within_twrp.sh must
be in the same directory as this script. The script will be copied to the phone and then executed on the phone.
Set the variable TWRP_INSTALL_SCRIPT to the name of the script to use before starting this script if another script should be used .
To change some of the values used by the script you can set environment variables before starting the script:
Set the environment variable REBOOT to "yes" before starting the script to automatically reboot the phone after patching the new image
Set the environment variable REBOOT to "no" before starting the script to disable the automatic reboot after patching the new image.
Set the environment variable SERIAL_NUMBER to the serial number of the phone to patch if there is more then one phone connected via USB
Set the environment variable ADB_OPTIONS to the options to be used with the adb command
Set the environment variable FASTBOOT_OPTIONS to the options to be used with the fastboot command
Set the environment variable TMP_DIR_ON_THE_PHONE to the temporary directory to use on the phone
The default TWRP image to use is "/data/backup/ASUS_ZENFONE8/twrp/twrp-3.7.0_12-0-I006D.img"
The default script executed on the phone to install TWRP is "./install_twrp_from_within_twrp.sh"
[[email protected] /data/develop/android/scripts_on_linux]$
Without any parameter the script install_twrp.sh will install TWRP into the active boot partition.
Example:
Code:
[[email protected] /data/develop/android/scripts_on_linux]$ ./install_twrp.sh
./install_twrp.sh version - 1.0.0.0 - install TWRP to the boot partition of a phone running Android using TWRP
Using the TWRP image hardcoded in the script: "/data/backup/ASUS_ZENFONE8/twrp/twrp-3.7.0_12-0-I006D.img"
Checking the script prerequisites ...
Will wait 10 second(s) before starting the script on the phone
The script is running as user "xtrnaw7" -- will use "sudo" for the fastboot commands ...
Will patch the boot partition on the attached phone with the serial number "M6AIB760D0939LX"
Using the options "-d -s M6AIB760D0939LX " for the adb commands
Using the options " -s M6AIB760D0939LX " for the fastboot commands
Checking for a connected phone booted into fastboot mode ...
No attached phone in fastboot mode found
Checking for an attached phone with working access via adb (USB) ...
Linux localhost 5.4.147-Omni-qgki-perf-gea6f815f5af9-dirty #46 SMP PREEMPT Sat Oct 15 08:38:07 CEST 2022 aarch64
... found a phone connected via USB with working adb access
The phone is booted in normal mode
Booting the phone into the fastboot mode now ...
Waiting up to 60 seconds for the boot into the fastboot mode ...
Booting the phone from the TWRP image "/data/backup/ASUS_ZENFONE8/twrp/twrp-3.7.0_12-0-I006D.img" now ...
Sending 'boot.img' (98304 KB) OKAY [ 2.500s]
Booting OKAY [ 10.440s]
Finished. Total time: 12.983s
Waiting up to 60 seconds for the boot of the phone ....
Retrieving the current boot slot from the phone ...
The current boot slot is "_a"
The boot slot to patch is "_a"
The boot partition to patch is "boot_a"
Checking if the directory "/data/local/tmp" exists on the phone ....
/data/local/tmp
Copying the script "./install_twrp_from_within_twrp.sh" to the phone ...
./install_twrp_from_within_twrp.sh: 1 file pushed, 0 skipped. 216.6 MB/s (13141 bytes in 0.000s)
Creating the boot image file "/data/local/tmp/boot_a.327964.img" from the partition "/dev/block/by-name/boot_a" ...
196608+0 records in
196608+0 records out
100663296 bytes (96 M) copied, 0.311720 s, 308 M/s
Checking the result ...
-rw-rw-rw- 1 root root 100663296 2022-10-24 18:02 /data/local/tmp/boot_a.327964.img
The check sums are:
The check sum of the boot partition "/dev/block/by-name/boot_a" on the phohe is "728455636"
The check sum of the boot image file on the phone is "/data/local/tmp/boot_a.327964.img" is "728455636"
Installing TWRP using the boot image file "/data/local/tmp/boot_a.327964.img" ...
----------------------------------------------------------------------
[2022.10.24 20:02:43] Waiting now 10 seconds ...
+ adb -d -s M6AIB760D0939LX shell /data/local/tmp/install_twrp_from_within_twrp.sh /data/local/tmp/boot_a.327964.img /data/local/tmp/boot_a_witn_twrp.327964.img
Installing TWRP into a boot image or boot partition via script
Checking the running OS ...
OK, running a shell in TWRP: "twrp_I006D" version "3.7.0_12-0"
Checking the prerequisites for installing TWRP ...
Using the file "/data/local/tmp/boot_a.327964.img" as source for the installation of TWRP
Creating the boot image with TWRP in the file "/data/local/tmp/boot_a_witn_twrp.327964.img"
Checking if the required executables exist ...
OK, the file "/system/bin/magiskboot" exists and is executable
OK, the file "/system/bin/cpio" exists and is executable
OK, the file "/system/bin/sha256sum" exists and is executable
OK, the file "/system/bin/getprop" exists and is executable
Checking if the requried data files exist ...
OK, the file "/ramdisk-files.sha256sum" exists
OK, the file "/ramdisk-files.txt" exists
OK, the file "/data/local/tmp/boot_a.327964.img" exists
Checking the check sums of the files for the new ramdisk ...
OK, the check sums of the files for the new ramdisk are okay
Directory "/data/local/tmp" successfully created
Directory "/data/local/tmp/img.583" successfully created
Directory "/data/local/tmp/img_files.583" successfully created
The temporary directory to unpack the boot image is "/data/local/tmp/img_files.583"
Unpacking the boot image from "/data/local/tmp/boot_a.327964.img" ...
Parsing boot image: [/data/local/tmp/boot_a.327964.img]
HEADER_VER [3]
KERNEL_SZ [42025472]
RAMDISK_SZ [34080743]
OS_VERSION [12.0.0]
OS_PATCH_LEVEL [2022-05]
PAGESIZE [4096]
CMDLINE []
KERNEL_FMT [raw]
RAMDISK_FMT [gzip]
VBMETA
OK, "/data/local/tmp/boot_a.327964.img" successfully unpacked to "/data/local/tmp/img_files.583" :
Creating a backup of the original ramdisk ...
total 74412
-rw-rw-rw- 1 root root 50 2022-10-24 18:02 header
-rw-r--r-- 1 root root 42025472 2022-10-24 18:02 kernel
-rw-r--r-- 1 root root 34080743 2022-10-24 18:02 ramdisk.cpio.org
Creating the new ramdisk with TWRP ...
New ramdisk with TWRP "/data/local/tmp/img_files.583/ramdisk.cpio" successfully created.
-rw-rw-rw- 1 root root 85852380 2022-10-24 18:02 /data/local/tmp/img_files.583/ramdisk.cpio
-rw-r--r-- 1 root root 34080743 2022-10-24 18:02 /data/local/tmp/img_files.583/ramdisk.cpio.org
Repacking the boot image into the file "/data/local/tmp/boot_a_witn_twrp.327964.img" ...
+ cd /data/local/tmp/img_files.583
+ /system/bin/magiskboot repack /data/local/tmp/boot_a.327964.img /data/local/tmp/boot_a_witn_twrp.327964.img
Parsing boot image: [/data/local/tmp/boot_a.327964.img]
HEADER_VER [3]
KERNEL_SZ [42025472]
RAMDISK_SZ [34080743]
OS_VERSION [12.0.0]
OS_PATCH_LEVEL [2022-05]
PAGESIZE [4096]
CMDLINE []
KERNEL_FMT [raw]
RAMDISK_FMT [gzip]
VBMETA
Repack to boot image: [/data/local/tmp/boot_a_witn_twrp.327964.img]
HEADER_VER [3]
KERNEL_SZ [42025472]
RAMDISK_SZ [34080758]
OS_VERSION [12.0.0]
OS_PATCH_LEVEL [2022-05]
PAGESIZE [4096]
CMDLINE []
+ TEMPRC=0
+ set +x
OK, the new boot image "/data/local/tmp/boot_a_witn_twrp.327964.img" successfully created
-rw-r--r-- 1 root root 100663296 2022-10-24 18:03 /data/local/tmp/boot_a_witn_twrp.327964.img
Note: Flashing the new image to the boot partition was not requested
+ set +x
----------------------------------------------------------------------
Checking the result ...
The patched boot image is "/data/local/tmp/boot_a_witn_twrp.327964.img"
-rw-r--r-- 1 root root 100663296 2022-10-24 18:03 /data/local/tmp/boot_a_witn_twrp.327964.img
[2022.10.24 20:03:05] Waiting now 5 seconds ...
Patching the partition "/dev/block/by-name/boot_a" from the patched boot image file "/data/local/tmp/boot_a_witn_twrp.327964.img" via dd ...
196608+0 records in
196608+0 records out
100663296 bytes (96 M) copied, 4.865411 s, 20 M/s
Checking the result ....
The check sums for the images and devices on the phone are:
Checksum Size File/Device name
-------------------------------------
728455636 100663296 /data/local/tmp/boot_a.327964.img
2360878166 100663296 /data/local/tmp/boot_a_witn_twrp.327964.img
2360878166 100663296 /dev/block/by-name/boot_a
OK, patching the boot partition "/dev/block/by-name/boot_a" was successfull
*** Press return to reboot the phone now
Rebooting the phone now ...
[[email protected] /data/develop/android/scripts_on_linux]$
Advanced Usage
To install TWRP and Magisk via script these commands can be used (for example after an OS upgrade) :
Bash:
# install the Magisk App (if not already done ...)
#
cat Magisk-25.1_25100.apk | adb shell pm install -S "$( ls -l Magisk-25.1_25100.apk | awk '{ print $5}' )"
# install TWRP and Magisk into the boot partition
#
REBOOT=no ./install_twrp.sh ; REBOOT=yes ./install_magisk_via_twrp.sh
To install a new OS image including TWRP and Magisk these commands can be used:
Bash:
# boot the phone into the boot loader
#
adb reboot bootloader
# boot the phone from the TWRP image
#
sudo fastboot boot /data/backup/ASUS_ZENFONE8/twrp/twrp-3.7.0_12-0-I006D.img
# copy the OS image to install to the phone
#
adb push /data/develop/android/OmniROM/out/target/product/zenfone8/omni-12-20221015-zenfone8-MICROG.zip /sdcard/Download/
# install the OS image
#
adb shell twrp install /sdcard/Download/omni-12-20221015-zenfone8-MICROG.zip
# reboot into the new OS
#
adb shell twrp reboot
# install the Magisk app
#
cat Magisk-v25.2.apk | adb shell pm install -S "$( ls -l Magisk-v25.2.apk | awk '{ print $5}' )"
# install TWRP and Magisk
#
REBOOT=no ./install_twrp.sh ; REBOOT=yes ./install_magisk_via_twrp.sh
The documentation for the script install_magisk_via_twrp.sh can be found here:
How to install Magisk into the boot partition using a script.
Details
The script install_twrp_from_within_twrp.sh was tested on an ASUS Zenfone 8 with
OmniROM 12 (Android 12) and TWRP 3.7.0.12
OmniROM 12 (Android 12) and TWRP 3.6.1.12
Original Android 12 from ASUS and TWRP 3.7.0.12
OmniROM 13 (Android 13) and TWRP 3.7.0.12 (see note below)
Important Update 04.12.2022 /bs
In TWRP installed in the boot partition of an ASUS Zenfone 8 running early versions of OmniROM 13 the touch screen does not work. You can only use TWRP in an adb session in this configuration.
This bug was fixed in OmniROM 13 from 04.12.2022.
To get around this bug boot the phone from the image file with TWRP, e.g.:
Bash:
sudo fastboot boot twrp-3.7.0_12-0-I006D.img
or, better, update OmniROM 13 to the image from 04.12.2022 or later.
The script install_twrp_from_within_twrp.sh does not create a backup of the boot partition before rewriting it.
The script install_twrp_from_within_twrp.sh creates temporary files in the directory ${TMPDIR} on the phone; the default value for this variable in the script is
Bash:
TMPDIR="${TMPDIR:=/cache/install_twrp.$$}"
The default value for the variable in the tested TWRP versions is /data/local/tmp so without changes the temporary files will be created in that directory.
The script does not delete the temporary files so a manual cleanup of the directory might be necessary .
Trouble Shooting
For unknown reasons repacking the boot image fails sometimes and the script ends with an error message like this:
Code:
ERROR: The size of the new boot image file is 56713216 but the size of the original image file is 100663296 -- that does not match (RC=33)
To avoid this error increase the wait time using the script parameter "wait=n" (the default wait time is 10 seconds).
If increasing the wait time does not help just restart the wrapper script install_twrp.sh again while the phone is still booted from the TWRP image. So a workaround for this problem is :
Bash:
install_twrp.sh ; [ $? = 33 ] && install_twrp.sh
The following error message appears when executing the script install_twrp_from_within_twrp.sh after booting the already installed TWRP:
Code:
ERROR: Error checking the check sums of the files for the new ramdisk
./system/etc/fstab.postinstall: FAILED
Installing TWRP via script only works if the phone is booted from the TWRP image.
To ignore this error the parameter -f can be used - but this is NOT recommended.
Notes:
see here on How to install Magisk into the boot partition via script
[added 29.10.2022/bs]
see here for How to add additional files to the TWRP image
How to process Android boot image files on a PC running the Linux OS
To unpack and repack the boot image for phones running the Android OS the Magisk binary magiskboot is necessary (well, there might be other tools for this task but magiskboot seems to be one of the best tools for this task). Therefor these kind of tasks will usually be done on a phone running the Android OS.
But there is also a magiskboot binary for x86 CPUs in the Magisk apk file and that executable can be used to work with boot images for Android phones on a PC running the Linux OS on a machine with x86 CPU. To retrieve the x86 version of magiskboot from the Magisk apk file do:
Bash:
# to use the 32 bit version
unzip Magisk-v25.2.apk lib/x86/libmagiskboot.so
mv lib/x86/libmagiskboot.so ./magiskboot
chmod 755 ./magiskboot
or
Bash:
# to use the 64 bit version
unzip Magisk-v25.2.apk lib/x86_64/libmagiskboot.so
mv lib/x86_64/libmagiskboot.so ./magiskboot
chmod 755 ./magiskboot
Example:
Code:
[[email protected] /data/develop/android/magisk]$ unzip Magisk-v25.2.apk lib/x86_64/libmagiskboot.so
Archive: Magisk-v25.2.apk
version=25.2
versionCode=25200
inflating: lib/x86_64/libmagiskboot.so
[[email protected] /data/develop/android/magisk]$
[[email protected] /data/develop/android/magisk]$ mv lib/x86_64/libmagiskboot.so ./magiskboot
[[email protected] /data/develop/android/magisk]$
[[email protected] /data/develop/android/magisk]$ chmod 755 magiskboot
[[email protected] /data/develop/android/magisk]$
[[email protected] /data/develop/android/magisk]$ file ./magiskboot
./magiskboot: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=b2d42d7bab2f70a0d66fc606a1fb2726a0559fed, stripped
[[email protected] /data/develop/android/magisk]$
[[email protected] /data/develop/android/magisk]$ ldd ./magiskboot
not a dynamic executable
[[email protected] /data/develop/android/magisk]$
[[email protected] /data/develop/android/magisk]$ ./magiskboot
MagiskBoot - Boot Image Modification Tool
Usage: ./magiskboot <action> [args...]
...
[[email protected] /data/develop/android/magisk]$
The binary magiskboot from the Magisk apk file is a statically linked executable either for 32 Bit or 64 Bit. Therefor it should run on any Linux distribution that supports executing executables for x86. I tested the binary from the apk file with Magisk v25.2 on these distributions:
Fedora 36 (64 Bit, kernel 6.x)
Redhat 8.6 (64 Bit, kernel 4.x)
Redhat 6.10 (64 Bit, kernel 2.x)
GRML LiveCD (32 Bit, kernel 5.x, the 32 bit version only)
RockyLinux 9.0 (64 Bit, kernel 5.x)
openSUSE LEAP 15.2 (64 Bit, kernel 5.x)
Unpacking a boot image file using magiskboot on a PC running the Linux OS can be done using this command;
Bash:
./magiskboot unpack boot_a.img
To change files in the ramdisk from the boot image use the magiskboot parameter cpio:
Code:
[[email protected] /data/develop/android/test2]$ ./magiskboot
MagiskBoot - Boot Image Modification Tool
Usage: ./magiskboot <action> [args...]
Supported actions:
...
cpio <incpio> [commands...]
Do cpio commands to <incpio> (modifications are done in-place)
Each command is a single argument, add quotes for each command
Supported commands:
exists ENTRY
Return 0 if ENTRY exists, else return 1
rm [-r] ENTRY
Remove ENTRY, specify [-r] to remove recursively
mkdir MODE ENTRY
Create directory ENTRY in permissions MODE
ln TARGET ENTRY
Create a symlink to TARGET with the name ENTRY
mv SOURCE DEST
Move SOURCE to DEST
add MODE ENTRY INFILE
Add INFILE as ENTRY in permissions MODE; replaces ENTRY if exists
extract [ENTRY OUT]
Extract ENTRY to OUT, or extract all entries to current directory
test
Test the current cpio's status
Return value is 0 or bitwise or-ed of following values:
0x1:Magisk 0x2:unsupported 0x4:Sony
patch
Apply ramdisk patches
Configure with env variables: KEEPVERITY KEEPFORCEENCRYPT
backup ORIG
Create ramdisk backups from ORIG
restore
Restore ramdisk from ramdisk backup stored within incpio
sha1
Print stock boot SHA1 if previously backed up in ramdisk
...
[[email protected] /data/develop/android/test2]$
E.g. to change the file system/etc/ramdisk/build.prop in the ramdisk, extract the file from the ramdisk
Bash:
./magiskboot cpio ramdisk.cpio "extract system/etc/ramdisk/build.prop build.prop"
edit the file, and add the file back to the ramdisk using this command:
Bash:
./magiskboot cpio ramdisk.cpio "add 0644 system/etc/ramdisk/build.prop build.prop"
Notes
Note that I did not yet manage to create a working boot image with magiskboot running in the Linux OS after extracting, changing, and recreating the ramdisk via the Linux cpio command (as Linux user root, of course) :
Creating a new boot image this way with magiskboot running in the LInux OS works without error but booting the new created boot image always ends with a ramdump error on the phone. So extracting the ramdisk via Linux cpio command can only be used to view the files in a boot image file for an Android Phone from wthin the Linux OS.
Trouble Shooting
To test the new boot image without installing it use this approach:
Bash:
# boot the phone into the bootloader
#
adb reboot bootloader
# boot the phone from the patched image file
#
sudo fastboot boot ./new-boot.img
If booting the phone works and everything is fine flash the image to the active boot partition
In case you get a ramdump error after booting the phone from the new boot partition just restart the phone into the bootloader mode and flash the old image back to the boot partition.