Where does the original boot.img for magisk restore needs to be put - Xiaomi Mi A2 / 6X Questions & Answers

I put the boot.img to the MagiskManager folder but this does not work. What do I need to do? I read something about gzipping but I'd be grateful for instructions

AFAIK you don't have to put stock boot.img anywhere as Magisk should have a backup of the stock boot at \root\data
You just need to select uninstall - restore images in Magisk Manager to restore stock boot.img

ckpv5 said:
AFAIK you don't have to put stock boot.img anywhere as Magisk should have a backup of the stock boot at \root\data
You just need to select uninstall - restore images in Magisk Manager to restore stock boot.img
Click to expand...
Click to collapse
Oh I forgot to say I used your images and fastboot but fastboot doesn't work currently for me so i tried to use the normal method.
Edit: Now i tried complete removal and now I am stuck on recovery screen with "no command". Fastboot is always reporting requested size more than allowed...

Don't you have the magisk backup stock boot at that location ?
Just check my current 9.6.13.0 (as example), both stock boot.img & magisk backup are same.
No idea how to fix your fastboot issue.
Benjamin_L said:
Edit: Now i tried complete removal and now I am stuck on recovery screen with "no command". Fastboot is always reporting requested size more than allowed...
Click to expand...
Click to collapse
Shouldn't try that before restore images is done.
Sorry.. no idea how to fix it without fastboot.

ckpv5 said:
Don't you have the magisk backup stock boot at that location ?
Just check my current 9.6.13.0 (as example), both stock boot.img & magisk backup are same.
No idea how to fix your fastboot issue.
Shouldn't try that before restore images is done.
Sorry.. no idea how to fix it without fastboot.
Click to expand...
Click to collapse
Fixed it with another laptop. Thank you for the time

How did you fix it ?

usernome said:
How did you fix it ?
Click to expand...
Click to collapse
FIX IT:
1 - Create a gzip archive named: stock_image_0.img.gz
2 - Put the file in your "/data" folder.
3 - GoTo "/root/sbin/.magisk" folder (is an hidden folder so you need to enable hidden files)
3 - Open file "config" and edit SHA1 string to "0". Usually that string is a SHA1 of the img file but i used "_0" so my SHA1 must be equal to "0".
4 - Now you are able to restore your stock boot image and you can do all other stuff to install your OTA Updates.

JDKerados said:
FIX IT:
1 - Create a gzip archive named: stock_image_0.img.gz
Click to expand...
Click to collapse
I needed to change that to /data/stock_boot_${SHA1}.img.gz ("boot" instead of "image") as found in Magisk sources.
Other than that it worked like a charm, thanks!

Is this info updated? im on android 12 magisk 24.7 and couldnt find those file and folders root and hidden acivated

JDKerados said:
FIX IT:
1 - Create a gzip archive named: stock_image_0.img.gz
2 - Put the file in your "/data" folder.
3 - GoTo "/root/sbin/.magisk" folder (is an hidden folder so you need to enable hidden files)
3 - Open file "config" and edit SHA1 string to "0". Usually that string is a SHA1 of the img file but i used "_0" so my SHA1 must be equal to "0".
4 - Now you are able to restore your stock boot image and you can do all other stuff to install your OTA Updates.
Click to expand...
Click to collapse
lap0 said:
I needed to change that to /data/stock_boot_${SHA1}.img.gz ("boot" instead of "image") as found in Magisk sources.
Other than that it worked like a charm, thanks!
Click to expand...
Click to collapse
rophiroth said:
Is this info updated? im on android 12 magisk 24.7 and couldnt find those file and folders root and hidden acivated
Click to expand...
Click to collapse
I'm in the same boat - I read that Magisk was supposed to autocreate a backup, if it did; it doesn't know where it went and I've tried a number of places (boot.img and gz zipped) and still nothing.
Android 12, Magisk 25.1
Thanks for any help!

I found this website:
fix-magisk-stock-backup-does-not-exist.md
GitHub Gist: instantly share code, notes, and snippets.
gist.github.com
I will post the edits I had to make below, but for the original, see the website.
** Load up Command Prompt on Windows**
# put stock boot.img into /sdcard/boot.img
# get sha1
adb shell
su
SHA1=$(cat $(magisk --path)/.magisk/config | grep SHA1 | cut -d '=' -f 2)
# repack boot.img.gz
gzip -9f /sdcard/boot.img
# restore backup
mkdir /data/magisk_backup_${SHA1}
mv /sdcard/boot.img.gz /data/magisk_backup_${SHA1}/boot.img.gz
chmod -R 755 /data/magisk_backup_${SHA1}
chown -R root.root /data/magisk_backup_${SHA1}
I was able to follow the guide to update from there, though to be fair, it's still "optimizing". Crossing my fingers.

b_fizzle said:
I found this website:
fix-magisk-stock-backup-does-not-exist.md
GitHub Gist: instantly share code, notes, and snippets.
gist.github.com
I will post the edits I had to make below, but for the original, see the website.
** Load up Command Prompt on Windows**
# put stock boot.img into /sdcard/boot.img
# get sha1
adb shell
su
SHA1=$(cat $(magisk --path)/.magisk/config | grep SHA1 | cut -d '=' -f 2)
# repack boot.img.gz
gzip -9f /sdcard/boot.img
# restore backup
mkdir /data/magisk_backup_${SHA1}
mv /sdcard/boot.img.gz /data/magisk_backup_${SHA1}/boot.img.gz
chmod -R 755 /data/magisk_backup_${SHA1}
chown -R root.root /data/magisk_backup_${SHA1}
I was able to follow the guide to update from there, though to be fair, it's still "optimizing". Crossing my fingers.
Click to expand...
Click to collapse
This wanted me today on the Nothing Phone 1. Thanks so much!

1.Create a gzip archive named: stock_image_0.img.gz
Guys how are you making this gzip.what application are you using or is just renaming the boot.img file to that.

b_fizzle said:
I found this website:
fix-magisk-stock-backup-does-not-exist.md
GitHub Gist: instantly share code, notes, and snippets.
gist.github.com
I will post the edits I had to make below, but for the original, see the website.
** Load up Command Prompt on Windows**
# put stock boot.img into /sdcard/boot.img
# get sha1
adb shell
su
SHA1=$(cat $(magisk --path)/.magisk/config | grep SHA1 | cut -d '=' -f 2)
# repack boot.img.gz
gzip -9f /sdcard/boot.img
# restore backup
mkdir /data/magisk_backup_${SHA1}
mv /sdcard/boot.img.gz /data/magisk_backup_${SHA1}/boot.img.gz
chmod -R 755 /data/magisk_backup_${SHA1}
chown -R root.root /data/magisk_backup_${SHA1}
I was able to follow the guide to update from there, though to be fair, it's still "optimizing". Crossing my fingers.
Click to expand...
Click to collapse
Magisk is refusing to allow superuser rights when I type su. I believe I have allowed apps and adb in magisk, but it's denying the su request.
how to get past this?

v.konvict said:
1.Create a gzip archive named: stock_image_0.img.gz
Guys how are you making this gzip.what application are you using or is just renaming the boot.img file to that.
Click to expand...
Click to collapse
That set of instructions didn't work for me - the one below that did (I'll quote it here):
b_fizzle said:
I found this website:
fix-magisk-stock-backup-does-not-exist.md
GitHub Gist: instantly share code, notes, and snippets.
gist.github.com
I will post the edits I had to make below, but for the original, see the website.
** Load up Command Prompt on Windows**
# put stock boot.img into /sdcard/boot.img
# get sha1
adb shell
su
SHA1=$(cat $(magisk --path)/.magisk/config | grep SHA1 | cut -d '=' -f 2)
# repack boot.img.gz
gzip -9f /sdcard/boot.img
# restore backup
mkdir /data/magisk_backup_${SHA1}
mv /sdcard/boot.img.gz /data/magisk_backup_${SHA1}/boot.img.gz
chmod -R 755 /data/magisk_backup_${SHA1}
chown -R root.root /data/magisk_backup_${SHA1}
I was able to follow the guide to update from there, though to be fair, it's still "optimizing". Crossing my fingers.
Click to expand...
Click to collapse

JustinChase said:
Magisk is refusing to allow superuser rights when I type su. I believe I have allowed apps and adb in magisk, but it's denying the su request.
how to get past this?
Click to expand...
Click to collapse
Honestly, I'm not sure. It sounds like ADB Debugging may not be enabled on the phone's Developer Settings(?)

b_fizzle said:
That set of instructions didn't work for me - the one below that did (I'll quote it here):
Click to expand...
Click to collapse
I fixed the problem with just making sure i root my phone by letting magisk patch the boot image as it backs up the stock one while making the patched one.

I dug a bit deeper and discovered that shell was disallowed from within Magisk for some reason. I have no recolleciton of it asking me, but once i enabled it in magisk, I was able to su in a prompt and get my problem solved.

Related

[Q] Odex before compression

Is it possible to odex a system before I compress it into a androidinstall and send it to my device to install?
If so how?
only way i have found to odex is through the phone
How do people release odex'ed builds then?
2 ways
1. if adb works push the odex script to /data run the scrpit (search odex donut or dzo's instructions on how to use it), then do an adb pull of /system then repack it into a .tar and go
2 adb doesnt work for me so here is how i do it, i load up my build and in the /data folder i have the odex script, i run the script using terminal emulator, then i restart after its finished and put in a blank sd card then i copy the app and framework folders from /system to the SD and replace those folders in the original .tar with the newly odex'd ones
I put the odex script into data and then added it to init
jholtom said:
Is it possible to odex a system before I compress it into a androidinstall and send it to my device to install?
If so how?
Click to expand...
Click to collapse
I asked dzo once and he answered me, in the Fresh Froyo thread. The search function isn't working right now, but when you read this it might be working. Another thread described things in more detail, but I long ago forgot where that thread is. I never got odexing to work outside the phone, but here is the script I have tried. Note that the dexpreopt.py python script has to be edited to mount system as read/write, or it completely fails. I run this after a complete build.
Code:
#! /bin/sh
. build/envsetup.sh
lunch us_vogue-userdebug
rm out/target/product/vogue/obj/PACKAGING/systemimage_unopt_intermediates/system.img
ONE_SHOT_MAKEFILE=/home/devel/android/build/tools/dexpreopt/Android.mk make -C /home/devel/android/ files
make
mkdir /tmp/system-odex
rm -rf /tmp/system-odex/system
cp -ra out/target/product/vogue/system /tmp/system-odex
dexpreopt.py --outsystemdir=/tmp/system-odex/system
for i in /tmp/system-odex/system/app/*.apk; do zipalign -f 4 $i /tmp/zip; mv /tmp/zip $i; done
tar -C /tmp/system-odex -czf odex.tgz system
n2rjt said:
I asked dzo once and he answered me, in the Fresh Froyo thread. The search function isn't working right now, but when you read this it might be working. Another thread described things in more detail, but I long ago forgot where that thread is. I never got odexing to work outside the phone, but here is the script I have tried. Note that the dexpreopt.py python script has to be edited to mount system as read/write, or it completely fails. I run this after a complete build.
Code:
#! /bin/sh
. build/envsetup.sh
lunch us_vogue-userdebug
rm out/target/product/vogue/obj/PACKAGING/systemimage_unopt_intermediates/system.img
ONE_SHOT_MAKEFILE=/home/devel/android/build/tools/dexpreopt/Android.mk make -C /home/devel/android/ files
make
mkdir /tmp/system-odex
rm -rf /tmp/system-odex/system
cp -ra out/target/product/vogue/system /tmp/system-odex
dexpreopt.py --outsystemdir=/tmp/system-odex/system
for i in /tmp/system-odex/system/app/*.apk; do zipalign -f 4 $i /tmp/zip; mv /tmp/zip $i; done
tar -C /tmp/system-odex -czf odex.tgz system
Click to expand...
Click to collapse
ok thanks
I'll work with it
Also there is a script I use to odex files as they are downloaded from the market or installed on the phone. It is inside of my barebones build and if you look inside my userinit from my build you will see the call to the file.
Edit: I do not take credit for it, I just claim to be a source of the file as I already have it.

[9001]fix md5 mismatch

this is how i did to fix md5 missmatch due to restore from feamod recovery
-firstly make a folder clockworkmod/backup/2011-12-16.12.56.43 IN INTERNAL SDCARD
open terminal emulator
type su
#cd / sdcard/clockworkmod/backup/2011-12-16.12.56.43
#rm nandroid .md5 (if u get this rm failed for nandroid. read-only file system just leave it)
#md5sum *img > nandroid.md5
reboot to recovery
restore from internal
Good idea to post that (used it too with some backups). If you can't get into your device (bootloop etc) you should be able to do it on your pc. I tried doing it with md5sum (see attached) but it then adds an extra x0D (carriage return)... so if someone knows how to do this, please add to this topic
Regards,
Nika.
Thnx. can be very usefull
I have ca. 3 archives where I get md5 mismatch only one is restorable. Only for understanding do I only create an empty folder and make this or must I use the backup folder from my backup ?
Thx in advance
Dontron
DonTron said:
I have ca. 3 archives where I get md5 mismatch only one is restorable. Only for understanding do I only create an empty folder and make this or must I use the backup folder from my backup ?
Thx in advance
Dontron
Click to expand...
Click to collapse
Please explain what you mean. You have 3 backups that give you this error? Then you should go to each of those backup-folders and run "md5sum *img > nandroid.md5" (without the quotes off course). This will regenerate the md5 file and then the restore should work if the backup files are intact (I've had some backups with 0 kb files too)
..I tried and get "bad substitution"
Dontron
Edit: I renamed the folders and now I can use the command..give a try.
Gesendet von meinem GT-I9001 mit Tapatalk
..thx now it works like a charm and I can restore my old working rom.
Dontron
Gesendet von meinem GT-I9001 mit Tapatalk
You want to do it automatically through ADB? Here's a script:
Code:
@echo off
set FixMD5backup=[COLOR=Red][B]/mnt/sdcard/clockworkmod/backup/011-12-16.12.56.43[/B][/COLOR]
echo cd %FixMD5backup% >FixMD5.adb
echo pwd >>FixMD5.adb
echo ls -l -a * >>FixMD5.adb
echo chmod 666 nandroid.md5 >>FixMD5.adb
echo rm nandroid.md5 >>FixMD5.adb
echo md5sum *img *tar ^>nandroid.md5 >>FixMD5.adb
echo ls -l -a * >>FixMD5.adb
echo cat nandroid.md5 >>FixMD5.adb
echo exit >>FixMD5.adb
adb -d shell <FixMD5.adb
del FixMD5.adb
pause
Make sure the path is correct
Regards,
Nika.
rideriang said:
this is how i did to fix md5 missmatch due to restore from feamod recovery
-firstly make a folder clockworkmod/backup/2011-12-16.12.56.43 IN INTERNAL SDCARD
open terminal emulator
type su
#cd / sdcard/clockworkmod/backup/2011-12-16.12.56.43
#rm nandroid .md5 (if u get this rm failed for nandroid. read-only file system just leave it)
#md5sum *img > nandroid.md5
reboot to recovery
restore from internal
Click to expand...
Click to collapse
If you are using a back from your sdcard, you will need to mount r/w.
Here is what I did, and it worked perfect.
BETAlatform-tools akelly$ ./adb shell
# mount -o remount rw /sdcard
# cd sdcard/clockworkmod/backup/
# ls
2011-11-09.MIUI-1.11.4-base 2011-12-12-CM7-GlitchV13
2011-11-09.MIUI-GLITCH-1.11.4-loaded 2011-12-12-CM7-GlitchV13-basic
# cd 2011-12-12-CM7-GlitchV13
# ls
boot.img datadata.yaffs2.img system.yaffs2.img
cache.yaffs2.img nandroid.md5
data.ext4.tar recovery.img
# rm nandroid.md5
# md5sum *img > nandroid.md5
Click to expand...
Click to collapse
rideriang said:
this is how i did to fix md5 missmatch due to restore from feamod recovery
-firstly make a folder clockworkmod/backup/2011-12-16.12.56.43 IN INTERNAL SDCARD
open terminal emulator
type su
#cd / sdcard/clockworkmod/backup/2011-12-16.12.56.43
#rm nandroid .md5 (if u get this rm failed for nandroid. read-only file system just leave it)
#md5sum *img > nandroid.md5
reboot to recovery
restore from internal
Click to expand...
Click to collapse
Worked out perfectly. You are a scholar and a gentleman.
nikagl said:
Good idea to post that (used it too with some backups). If you can't get into your device (bootloop etc) you should be able to do it on your pc. I tried doing it with md5sum (see attached) but it then adds an extra x0D (carriage return)... so if someone knows how to do this, please add to this topic
Regards,
Nika.
Click to expand...
Click to collapse
For reference, attached is md5.exe and dos2unix.exe.
Here's the script to execute md5.exe (see attached) and make the nandroid.md5 on your pc:
Code:
@echo off
del nandroid.md5
for %%i in (boot.img,cache.ext4.tar,data.ext4.tar,recovery.img,system.ext4.tar,.android_secure.vfat.tar) do md5 %%i>>nandroid.md5 && echo %%i>>nandroid.md5
dos2unix nandroid.md5
pause
Btw, for everyone good to know, you can always run the md5sum from adb in clockworkmod recovery too (just before doing the backup, even when you're in the backup screen!):
Code:
adb shell
# cd /sdcard/clockworkmod/backup/[B]BACKUPDATE[/B]
# rm nandroid.md5
# md5sum *img >nandroid.md5
# exit
Regards,
Nika.
nikagl said:
... reference, attached is md5.exe and dos2unix.exe.
Here's the script to execute md5.exe (see attached) and make the nandroid.md5 on your pc:.
Click to expand...
Click to collapse
Hi,
Could you guide how to use the file? I'm totally newbie here. Using ClockWorkMod Touch Recovery Lilg for Galaxy Mini
Tq
exz8 said:
Hi,
Could you guide how to use the file? I'm totally newbie here. Using ClockWorkMod Touch Recovery Lilg for Galaxy Mini
Tq
Click to expand...
Click to collapse
Can you first check the filesize of each file that the backup created? If there's 0kb files you will not be able to restore them, do it with Advanced Restore one by one and you may be able to get back stuff...
If you don't know how to use the files I uploaded, I doubt a guide will help you
nikagl said:
Can you first check the filesize of each file that the backup created? If there's 0kb files you will not be able to restore them, do it with Advanced Restore one by one and you may be able to get back stuff...
If you don't know how to use the files I uploaded, I doubt a guide will help you
Click to expand...
Click to collapse
Inside backup folder have 2 files.
both files are same size. Under CWM Folder I found 2 files as attach.
Anything wrong?
exz8 said:
Inside backup folder have 2 files.
both files are same size. Under CWM Folder I found 2 files as attach.
Anything wrong?
Click to expand...
Click to collapse
That does not seem like a complete backup. Normally you also have a system.ext4.tar, data.ext4.tar and cache.ext4.tar. I guess this backup failed.
The only things you have is a kernel (boot.img) and the recovery.
wintel_mac said:
That does not seem like a complete backup. Normally you also have a system.ext4.tar, data.ext4.tar and cache.ext4.tar. I guess this backup failed.
The only things you have is a kernel (boot.img) and the recovery.
Click to expand...
Click to collapse
Right, I'd talk to the one that supports your cwm (touch recovery Lilg for Galaxy Mini)
I think I know already. Today, I had try backup and it's fine. Probably last time, I'm not use the proper method. Anyway, thanks for intention to help.
Tq
i am newbie
sorry for my question :
i have 03 clockworkmod backup in my ext_sd card named :
1 - 2012-05-08.16.48.10
2 - 2012-05-08.16.17.27
3 - 2012-05-02.02.25.41
i renamed them to :
1 - nitrox
2 - moon
3 - kqb
but when i try to restor i have md5 mismatch for all them
how to do for fix them all
please
EDIT : i finally understund the way :
i have moved clockworkmod from external_sd to sdcard
put the phone in usb debug
and than call adb shell with this :
adb shell
$ su
#
# cd /sdcard/clockworkmod/backup/nitrox
# rm nandroid.md5
# md5sum *img >nandroid.md5
# cd /sdcard/clockworkmod/backup/moon
# rm nandroid.md5
# md5sum *img >nandroid.md5
# cd /sdcard/clockworkmod/backup/kqb
# rm nandroid.md5
# md5sum *img >nandroid.md5
# exit
and then move back the clockworkmod to extrenal_sd and now all my backups work fine
thank you very much
rideriang said:
this is how i did to fix md5 missmatch due to restore from feamod recovery
-firstly make a folder clockworkmod/backup/2011-12-16.12.56.43 IN INTERNAL SDCARD
open terminal emulator
type su
#cd / sdcard/clockworkmod/backup/2011-12-16.12.56.43
#rm nandroid .md5 (if u get this rm failed for nandroid. read-only file system just leave it)
#md5sum *img > nandroid.md5
reboot to recovery
restore from internal
Click to expand...
Click to collapse
worked like a charm!!
THANK YOU!!!!
HTC EVO 4G CM7
very helpful
thanks ..

[mod][6T] init.d / services.d framework using Magisk [linux]

This thread will allow you to set up init.d (and services.d) scripts on your phone so they can run at boot time.
Prerequisites
- understanding of what "init.d" scripts mean ...
- your phone must be rooted (see https://www.xda-developers.com/oneplus-6t-unlock-bootloader-root/)
- you must have a working Magisk (see https://forum.xda-developers.com/apps/magisk)
- linux knowledge (I am not a Windows guy but instructions below should easily apply to Windows / PowerShell)
- adb knowledge
If this scares you, stop reading and go play with something else.
Attached zip file contains
- a magisk.img file
- a directory with init.d scripts
- a directory with services.d scripts
You can use the scripts provided or not use (some) of them, or write your own.
What's the difference between init.d and services.d scripts?
The idea is to have 2 directories on your phone with scripts:
Code:
/system/etc/init.d/
/system/etc/services.d/
The init.d scripts are run early in the boot (when Magisk initializes). The scripts in /system/etc/services.d/ will run a bit "later", to be precise: when sys.boot_completed = true.
Important warrning: even when sys.boot_completed = true, this does NOT guarantee that /sdcard is mounted. Your script can "sleep" until /sdcard is mounted if it relies on things on /sdcard. See for example the code in /system/etc/services.d/LS99maxvolumewarning which will show how you can do that.
Scripts in init.d should NOT rely on any of the file systems being mounted !
The framework will run all scripts in parallel. So be careful that you do not write scripts which depend on eachother!
The framework will run all scripts as background processes so that they do not hinder the normal boot of your phone.
Prepare the basic setup
To use the scripts (or your own), you must first create the directories init.d and services.d; to do that open a linux shell and do:
Code:
> adb shell
$ su
# mount -o rw,remount /system
# mkdir /system/etc/init.d/
# mkdir /system/etc/services.d/
# chown 0.0 /system/etc/init.d
# chown 0.0 /system/etc/services.d
# chmod 755 /system/etc/init.d
# chmod 755 /system/etc/services.d
# sync; exit
Putting the scripts on your phone
Download the attached zip file (initd.zip); create a directory in your linux file system and unzip, e.g.
Code:
> mkdir mydir
> cd mydir
> unzip ~/initd.zip
> adb push init.d/ /sdcard/
> adb push services.d/ /sdcard/
> adb shell
$ su
# mount -o rw,remount /system
# mv /sdcard/LS00* /system/etc/init.d/
# mv /sdcard/LS99* /system/etc/services.d/
# chown 0.0 /system/etc/init.d/*
# chown 0.0 /system/etc/services.d/*
# chmod 755 /system/etc/init.d/*
# chmod 755 /system/etc/services.d/*
# sync
# exit
$ exit
Installing the magisk image on your phone
First important remark: I need to turn this really into a proper magisk "module" but I need to study that first. Open a linux shell and do:
Code:
> cd mydir
> gunzip magisk.img.gz
> adb push magisk.img /sdcard/
> adb shell
$ su
# cd /data/adb
# mv magisk.img magisk.img.orig
# cp /sdcard/magisk.img .
# chown 0.0 magisk.img
# chmod 644 magisk.img
# sync
# exit
$ exit
That's all !!! If you now reboot your phone your init.d and services.d scripts will run.
How can I tell this is working?
Each script has a log file in /data/; whose name is LS00 (for init.d) or LS99 (for services.d) appended with the name of the script. That log file is passed as "$1" into the script and the script code can write to this log file using:
Code:
LOGFILE=$1
echo "Hi I am writing to the log" | tee -a $LOGFILE
To check that the log files are there, open a linux shell and do:
Code:
> adb shell
$ su
# ls /data/LS*
And you should see something like:
Code:
16 /data/LS00blockdev 4 /data/LS99bootclean 4 /data/LS99maxvolumewarning 4 /data/LS99sysctl
4 /data/LS00governors 4 /data/LS99callrecording 4 /data/LS99network 4 /data/LS99trimcaches
4 /data/LS00kerneltweaks 4 /data/LS99cputweaks 4 /data/LS99overlays 4 /data/LS99turnoffnightmode
4 /data/LS00procgate 4 /data/LS99enablecallrecording 4 /data/LS99remounts 4 /data/LS99workqueue
4 /data/LS00readahead 4 /data/LS99hdparm 4 /data/LS99resetprop
4 /data/LS00resetprop 4 /data/LS99magiskhide 4 /data/LS99sqlite
To check the contents of the log files, do:
Code:
> adb shell
$ su
# cat /data/LS*
And you will see logging info:
Code:
>> Starting /system/etc/init.d/LS00procgate at 19700110-17:21:12
-- remounting: mount -o remount,hidepid=2,gid=3009 /proc
<< Ending /system/etc/init.d/LS00procgate at 19700110-17:21:12
>> Starting /system/etc/services.d/LS99maxvolumewarning at 20181201-07:34:00
-- slept for 4 seconds waiting for /sdcard/Android
-- disabling max volume warning
<< Ending /system/etc/services.d/LS99maxvolumewarning at 20181201-07:33:58
What's next
Write your own scripts (and share them). Note that scripts must be owned by root (chown 0.0) and have 755 linux permissions (chmod) to run.
How does it really work?
No secrets ... magisk.img is actually a magisk module which runs the scripts. To see the inner details, do the following after you have installed the magisk image and rebooted your phone:
Code:
> adb shell
$ su
# ls -l /sbin/.core/img/template/
total 12
0 -rw-r--r-- 1 root root 0 2018-03-12 21:19 auto_mount
4 -rw-r--r-- 1 root root 935 2018-08-06 17:59 post-fs-data.sh
4 -rwxr-xr-x 1 root root 498 2018-08-05 10:11 scriptwrapper*
4 -rw-r--r-- 1 root root 2750 2018-08-11 12:07 service.sh
Magisk will run the post-fs-data.sh first and service.sh later. Check the code of both of these files to understand how init.d and services.d are ran (using run-parts). If you want more details please read: https://topjohnwu.github.io/Magisk/guides.html#scripts.
Disable ALL scripts from running
If you want to disable any script from running do:
Code:
> adb shell
$ su
# touch /data/noinitrd
To undo this and get your scripts running again, do:
Code:
> adb shell
$ su
# rm /data/noinitrd
What do my init.d scripts do?
Code:
LS00blockdev: change properties of block devices (non rotational, no kernel io stats, ...)
LS00governors: set all CPU governers (to schedutil; which is actually the 6T default)
LS00kerneltweaks: a few basic kernel tweaks + stop debug of kernel modules
LS00procgate: protections against the procgate security vulnerability (thanks to @topjohnwu)
LS00readahead: change the readahead amount on logical disk devicesw
LS00resetprop: reset model, brand, manufacturer (only useful if you would want to get your phone appear externally as a Pixel; check the code)
What do my services.d scripts do?
Code:
LS99bootclean: clean junk and log files
LS99cputweaks: improve scaling governor
LS99enablecallrecording: enable call recording (must be done at every device boot)
LS99execonce: a whole series of settings; this is only executed ONCE
LS99hdparm: increase readahead on /system and /data
LS99magiskhide: hide some packages from seeing root
LS99maxvolumewarning: remove the high volume warning (I am not sure this will always work !!!)
LS99network: TCP transmit queue and congestion control
LS99overlays: enable all overlays automatically (if you use substratum then no need to enable them manually)
LS99remounts: improve file system performance of multiple partitions
LS99resetprop: increase memory used by dalvik
LS99sqlite: REINDEX and VACCUM sqlite database files (the script only runs every 3rd day)
LS99sysctl: optimize linux kernel settings and TCP/IP performance
LS99trimcaches: trim android cache files
LS99turnoffnightmode: reset the night mode to OFF (night mode conflicts with dark mode in newer Google apps)
LS99workqueue: tune kernel work queue
Thanks man I have been trying to get boot scripts to run.
jacksummers said:
Thanks man I have been trying to get boot scripts to run.
Click to expand...
Click to collapse
excuse me for the ignorance, but what is the use of this mod?
Sent from my [device_name] using XDA-Developers Legacy app
isoladisegnata said:
excuse me for the ignorance, but what is the use of this mod?
Sent from my [device_name] using XDA-Developers Legacy app
Click to expand...
Click to collapse
At the end of OP he's got a summary of what the different scripts do.
I am stuck here > unzip ~/initd.zip
It keeps saying:
1|OnePlus6T:/mydir # unzip /initd.zip
unzip: can't open /initd.zip[.zip]
Any ideas I extracted initd to the directory where my platform tools are and where I do my system updates am I supposed to extract it somewhere else? How do I create a directory in my linux shell using windows cmd promts?
kirschdog1 said:
I am stuck here > unzip ~/initd.zip
It keeps saying:
1|OnePlus6T:/mydir # unzip /initd.zip
unzip: can't open /initd.zip[.zip]
Any ideas I extracted initd to the directory where my platform tools are and where I do my system updates am I supposed to extract it somewhere else? How do I create a directory in my linux shell using windows cmd promts?
Click to expand...
Click to collapse
Looks like a simple typo "/initd.zip" implies that the file is located in the root directory. "~/initd.zip" would be in your "home" directory. Since I don't know if "/mydir" is defined as your home directory and presuming initd.zip is located there try "unzip /mydir/initd.zip" (no quotes).
Still not working
Base2 said:
Looks like a simple typo "/initd.zip" implies that the file is located in the root directory. "~/initd.zip" would be in your "home" directory. Since I don't know if "/mydir" is defined as your home directory and presuming initd.zip is located there try "unzip /mydir/initd.zip" (no quotes).
Click to expand...
Click to collapse
1|OnePlus6T:/ # cd mydir
OnePlus6T:/mydir # unzip ~/initd.zip
unzip: can't open //initd.zip[.zip]
1|OnePlus6T:/mydir # unzip /mydir/initd.zip
unzip: can't open /mydir/initd.zip[.zip]
Any ideas? How to get this working? I tried both commands to no avail.
kirschdog1 said:
I am stuck here > unzip ~/initd.zip
It keeps saying:
1|OnePlus6T:/mydir # unzip /initd.zip
unzip: can't open /initd.zip[.zip]
Any ideas I extracted initd to the directory where my platform tools are and where I do my system updates am I supposed to extract it somewhere else? How do I create a directory in my linux shell using windows cmd promts?
Click to expand...
Click to collapse
You have to create the directory mydir on your linux machine, not on your phone.
Base2 said:
Looks like a simple typo "/initd.zip" implies that the file is located in the root directory. "~/initd.zip" would be in your "home" directory. Since I don't know if "/mydir" is defined as your home directory and presuming initd.zip is located there try "unzip /mydir/initd.zip" (no quotes).
Click to expand...
Click to collapse
No, not a typo. mydir is on your PC, not on the phone !
foobar66 said:
No, not a typo. mydir is on your PC, not on the phone !
Click to expand...
Click to collapse
How do I create the directory? I'm using a windows device using adb command prompts?
kirschdog1 said:
How do I create the directory? I'm using a windows device using adb command prompts?
Click to expand...
Click to collapse
Search how to create directories in PowerShell ... I am not a Windows guru :crying:
foobar66 said:
Search how to create directories in PowerShell ... I am not a Windows guru :crying:
Click to expand...
Click to collapse
Ok thank you.ill hold off as it appears to be above my pay grade.
foobar66 said:
You have to create the directory mydir on your linux machine, not on your phone.
Click to expand...
Click to collapse
This won't work anymore as magisk doesn't use magisk.img anymore

How To Guide How to run a script at every boot using Magisk

How to run a script at every boot using Magisk
Note:
I tested the instructions below with Magisk 24.3 . They may or may not work with other versions of Magisk
Another very useful feature from Magisk that can also be used without creating a Magisk Module is the ability to start scripts after booting the phone:
To execute scripts after rebooting the phone just copy them to one of the directories
/data/adb/post-fs-data.d
/data/adb/service.d
on the phone, make the script executable (chmod +x scriptname) and reboot the phone.
(See also https://github.com/topjohnwu/Magisk/blob/master/docs/guides.md#boot-scripts)
Because the mapping will be done while booting the phone it will also survive updating the OS on the phone to a new version as long as the user data is not deleted and Magisk is installed.
To remove the script just delete the script and reboot the phone.
In case the phone does not boot anymore after adding the script just boot the phone from a recovery with adb support, for example from the TWRP:
Code:
# boot the phone into the bootloader and then do
sudo fastboot boot /data/backup/ASUS_ZENFONE8/twrp/twrp-3.6.1_12-1-I006D.img
Then connect via "adb shell" to the phone and delete the script .
I used this method to correct the SELinux context for the NFC device in the first version of AospExtended 9.0 for the ASUS Zenfone 8 (the device tree is recreated from scratch each time the phone boots so the change must be done after every reboot):
Code:
cat /data/adb/service.d/correct_dev_pn553.sh
#!/system/bin/sh
NFC_DEVICE="/dev/pn553"
echo ""
echo "The SELinux context for \"${NFC_DEVICE}\" is now:"
ls -lZ ${NFC_DEVICE}
echo ""
echo "Correcting the SELinux context for the NFC device \"${NFC_DEVICE}\" ..."
chcon -v u:object_r:nfc_device:s0 /dev/pn553
echo ""
echo "The SELinux context for \"${NFC_DEVICE}\" is now:"
ls -lZ ${NFC_DEVICE}
Again, if the script is tested and working you should create a Magisk module for it.
Update 06.06.2022 20:27
Corrected a minor typo
Update 18.06.2022
Corrected a typo : chmod -x must be chmod +x.
(Thanks to oldman20 for the hint)
​Update 26.06.2022​Fixed minor typos in the title of the post
Update 18.01.2023
See How to change any file or directory using Magisk for how to use this method change files on read-only mounted filesystems.
bnsmb said:
on the phone, make the script executable (chmod -x scriptname) and reboot the phone.
Click to expand...
Click to collapse
Correctly is chmod +x scriptname, right?
oldman20 said:
Correctly is chmod +x scriptname, right?
Click to expand...
Click to collapse
Yes, thanks for the hint . I corrected the post

How To Guide How to make files in /system writable

How to make files in /system writable
In Android 12 and newer /system is mounted read-only can not be remounted read-write anymore.
Sometimes it's useful that one or more files in /system are writable (for example for develop tasks or for testing)
This can be implemented using Magisk (see How to change files in the directory /system for more details)
Example :
Make the file /system/etc/vimrc writable
Note:
In Android 12 /etc is a symbolic link to /system/etc.
Open a (adb) shell as user root and do
Bash:
# create a dummy Magisk module
#
mkdir -p /data/adb/modules/writable_system/system/etc
# copy the file that should be writable to the Magisk module directory
#
cp /system/etc/vimrc /data/adb/modules/writable_system/system/etc/
# make the file in the Magisk module directory writable
#
chmod +w /data/adb/modules/writable_system/system/etc/vimrc
Now reboot the phone.
After the reboot the file /system/etc/vimrc is writable by the user root, Example:
Code:
ASUS_I006D:/ # id
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
ASUS_I006D:/ #
ASUS_I006D:/ # ls -l /system/etc/vimrc
-rw-r--r-- 0 root root 3350 2022-11-04 11:36 /system/etc/vimrc
ASUS_I006D:/ # tail -2 /system/etc/vimrc
\ | wincmd p | diffthis
endif
ASUS_I006D:/ #
ASUS_I006D:/ # echo '" Test Comment' >>/system/etc/vimrc
ASUS_I006D:/ #
ASUS_I006D:/ # tail -2 /system/etc/vimrc
endif
" Test Comment
ASUS_I006D:/ #
Only the user root can access the directory /data/adb. Therefor the files configured using this approach are only writable by the user root.
To make a file in /system writable for non-root users use this method:
Open a (adb) shell and execute as user shell:
Bash:
#
# create a directory that is writable for the user shell
#
mkdir /data/local/tmp/writable_system
mkdir /data/local/tmp/writable_system/etc
#
# copy the file that should be writable to that directory
#
cp /system/etc/vimrc /data/local/tmp/writable_system/etc
The next commands must be executed as user root:
Bash:
# create dummy Magisk module
#
mkdir -p /data/adb/modules/writable_system/system/etc
#
# create a symbolic link to the file in the writable directory in the directory with the dummy Magisk module
#
ln -s /data/local/tmp/writable_system/etc/vimrc /data/adb/modules/writable_system/system/etc
Now reboot the phone.
After the reboot the file /system/etc/vimrc is writable by the user shell, Example:
Code:
ASUS_I006D:/ $ id
uid=2000(shell) gid=2000(shell) groups=2000(shell),1004(input),1007(log),1011(adb),1015(sdcard_rw),1028(sdcard_r),1078(ext_data_rw),1079(ext_obb_rw),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats),3009(readproc),3011(uhid),3012(readtracefs) context=u:r:shell:s0
ASUS_I006D:/ $
ASUS_I006D:/ $ tail -2 /system/etc/vimrc
\ | wincmd p | diffthis
endif
ASUS_I006D:/ $
ASUS_I006D:/ $ echo '" Test Comment' >>/system/etc/vimrc
ASUS_I006D:/ $
ASUS_I006D:/ $ tail -2 /system/etc/vimrc
endif
" Test Comment
ASUS_I006D:/ $
Important:
The writable directory can also be in a sub directory in /sdcard. But be aware that /sdcard is mounted late in the boot process so it might be that the overwritten file in /system will be used by the OS when the bind mount points to a non-existent file if using a sub directory in /sdcard.
The changes to the file done using these methods are "persistent" as long as Magisk is installed in the boot partition.
To restore the file with the original contents after each new reboot of the phone without removing the writable config open a (adb) shell as user root and execute:
Bash:
#
# restore the file /data/adb/modules/writable_system/system/etc/vimrc from the original file /system/etc/vimrc
#
# this must be done before Magisk creates the bind mounts
#
echo "cp /system/etc/vimrc /data/adb/modules/writable_system/system/etc/vimrc">/data/adb/post-fs-data.d/restore_vimrc.sh
chmod 755 /data/adb/post-fs-data.d/restore_vimrc.sh
Now the file in the dummy Magisk module will be restored with the contents of the original file from /system after each reboot
To temporary access the original file from /system just stop the Magisk daemon, Example:
Code:
ASUS_I006D:/ # echo '"Test Test' >>/etc/vimrc
ASUS_I006D:/ #
ASUS_I006D:/ # tail -1 /etc/vimrc
"Test Test
ASUS_I006D:/ #
ASUS_I006D:/ # id
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
ASUS_I006D:/ #
ASUS_I006D:/ # magisk --stop
ASUS_I006D:/ #
ASUS_I006D:/ # id
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
ASUS_I006D:/ #
ASUS_I006D:/ # tail -1 /etc/vimrc
endif
ASUS_I006D:/ #
Note
Stopping the Magisk daemon will disable all bind mounts done by Magisk.
Restarting the Magisk daemon will not re-create the bind mount - to re-activate the bind mount for the writable file after stopping the Magisk daemon the phone must be rebooted.
To make more then one file writable in a sub directory in /system you can also replace the complete folder using these commands as user root:
Bash:
#
# make all files in /system/etc writable by the user root
#
mkdir -p /data/adb/modules/writable_system/system/etc/
cd /system/etc
find . | cpio -pdum /data/adb/modules/writable_system/system/etc/
touch /data/adb/modules/writable_system/system/etc/.replace
Now Magisk will replace the directory /system/etc with the directory /data/adb/modules/writable_system/system/etc after the next reboot
Notes
You should test these commands with a not important file like /system/etc/vimrc before changing important files.
It is NOT recommended to use this approach on productive phones.
See How to change any file or directory using Magisk for another approach to change files on read-only mounted filesystems.
Trouble Shooting
As always: If something does not work like expected check the Magisk log file /cache/magisk.log and also check the infos in this post.
Does this method require root on device?
FormulaSea said:
Does this method require root on device?
Click to expand...
Click to collapse
yes
Is there any method don't require root?
This looks interesting. Are you using OverlayFS for this? Looks like you did quite the research on this
Read-only is boring even as root. It's time for some RW baby
FormulaSea said:
Does this method require root on device?
Click to expand...
Click to collapse
I don't know a method to do this without root access.
But you can disable the root access in Magisk after implementing the changes . You could even uninstall tne Magisk app afterwards (but not the Magisk part from the boot partition)
regards
Bernd
lebigmac said:
This looks interesting. Are you using OverlayFS for this? Looks like you did quite the research on this
Read-only is boring even as root. It's time for some RW baby
Click to expand...
Click to collapse
I don't know what exactly you mean by "OverlayFS" - I use MagiskModules to modify files in /system and as far as I know Magisk used bind mounts to implement it.
>>Read-only is boring even as root.
Correct, but if you made the changes directly in /system, they would not survive the next OS upgrade.
One of the great advantages of this feature of Magisk is that it survives an OS upgrade - so as long as the change is compatible with the installed OS version, it only needs to be done once.
regards
Bernd
Thanks it worked on the audio folders on my 7t pro but didn't work on the boot animation folder. Both folders appear in the adb though with there files. Let me know op if you figure out how to do the boot animation folder it's moved to /my_product/ instead of /system/ I see that the my product folder and boot animation appear in the adb modules like the audio folder does and I swapped files the same way as with my audio modding but the changes for boot didn't take effect.
cbomb1337 said:
Thanks it worked on the audio folders on my 7t pro but didn't work on the boot animation folder. Both folders appear in the adb though with there files. Let me know op if you figure out how to do the boot animation folder it's moved to /my_product/ instead of /system/ I see that the my product folder and boot animation appear in the adb modules like the audio folder does and I swapped files the same way as with my audio modding but the changes for boot didn't take effect.
Click to expand...
Click to collapse
/my_product is not in the list of folders supported by Magisk so that may not work
Please post the output of these commands (executed as root user):
df -h
mount
ls -ald /*
ls -lZd /my_product
and a
ls -ldZ $( find /data/adb/modules/ )
and
cat /cache/magisk.log
(or attach the log file to the post if too big)
regards
Bernd
Here is this the correct log file. Thank you for responding to me.
cbomb1337 said:
Here is this the correct log file. Thank you for responding to me.
Click to expand...
Click to collapse
can you also post the output of the OS commands listed?
I Don't know how.
It didn't let me add the log here. Sorry that's it's cut and paste I tried a few termux commands to save a log but the were blank. I don't understand how to do it right.
Edit here I managed to upload the log to drive
https://drive.google.com/uc?id=1uWurf_462b5uLC_D21SFcgLcBWiXQZOn&export=download
bnsmb said:
can you also post the output of the OS commands listed?
Click to expand...
Click to collapse
Linefeeds are missing in that file so it's very hard to interpret the file contents correct
Can you do in a adb shell on the phone:
Bash:
(
set -x
set -v
su -
echo
df -h
echo
mount
echo
ls -ald /*
echo
ls -lZd /my_product
echo
ls -ldZ $( find /data/adb/modules/ )
echo
) > /sdcard/Download/oscmds.log 2>&1
then
Bash:
gzip /sdcard/Download/oscmds.log
and post / upload the file
/sdcard/Download/oscmds.log.gz
regards
Bernd
and
Here is the gzip I wasn't sure what was going on after entering that first command the termux was frozen for a few minutes. Also With the folders in the module folder and them being a copy of the original folder is it ok to delete them as a whole folder to remove the rw and revert it of needed. I tried it and didn't see any issues doing it but wanted to know if it reverted it properly and does deleting the module folders make me lose anything original that was in it or is my stock stuff safe because it's through magisk.
cbomb1337 said:
Here is the gzip I wasn't sure what was going on after entering that first command the termux was frozen for a few minutes. Also With the folders in the module folder and them being a copy of the original folder is it ok to delete them as a whole folder to remove the rw and revert it of needed. I tried it and didn't see any issues doing it but wanted to know if it reverted it properly and does deleting the module folders make me lose anything original that was in it or is my stock stuff safe because it's through magisk.
Click to expand...
Click to collapse
Looks like /my_product is a directory in the root filesystem but on the other hand there is a mount point called /mnt/vendor/my_product so I'm not sure about that.
If /my_product is really only a separate directory in the root filesystem the only method to change it is to manipulate the ramdisk used for booting the phone (only if the phone is using a ramdisk, of course).
Can you check if there are other directories called my_product:
find / -type d -name my_product 2>/dev/null
And, if there are any, compare the files in that directory with the files in the directory /my_product?
regards
Bernd
The only folder that has the same boot animation files is the /dev/ ones and the mnt one like you said.
It's all good if it can't be done i just found a magisk module before which works for flashing my boot animation
cbomb1337 said:
The only folder that has the same boot animation files is the /dev/ ones and the mnt one like you said.
Click to expand...
Click to collapse
Then it can't be done using the standard Magisk feature for making r/o mounted filesystems read-write.
cbomb1337 said:
It's all good if it can't be done i just found a magisk module before which works for flashing my boot animation
Click to expand...
Click to collapse
OK, do you have the URL?
And you could just check the contents of the zip file with the Magisk Module on how it's implemented
regards
Bernd
bnsmb said:
Then it can't be done using the standard Magisk feature for making r/o mounted filesystems read-write.
OK, do you have the URL?
And you could just check the contents of the zip file with the Magisk Module on how it's implemented
regards
Bernd
Click to expand...
Click to collapse
I read the module it mentions binding. I don't understand none of it :/ I upload the module here and removed the boot animation to make it small.
cbomb1337 said:
I read the module it mentions binding. I don't understand none of it :/ I upload the module here and removed the boot animation to make it small.
Click to expand...
Click to collapse
Cool -- that's the solution I also found in the meantime (and successfully tested it on my Zenfone 8)
In principle the module does for the bootanimation file what Magisk does if you replace some directories or files in /system
I will write a general HowTo how that works today or in the next days
regards
Bernd

Categories

Resources