[DEV] How Enabled Archos Gen9 To Run Scripts Into init.d - Gen9 Android Development

HI !
As you noticed , Archos didn't enabled run scripts into init.d directory !
Of course, there init.d directory into /system/etc/init.d with two scripts , but unfortunately never runs !
I found a way can be activated init.d directory allows scripts to automatically .
I know there are other ways for do this , but I really kept to run all script into init.d directory , and not elsewhere.
For this mechanism to work , device need to be rooted and busybox to be installed.
Now is very simple to add the following command :
> /system/bin/logwrapper /system/xbin/busybox run-parts /system/etc/init.d , that will allow scripts to run in directory init.d !
This command must be placed in your system initialization file !
regard,
surdu_petru

surdu_petru said:
Now is very simple to add the following command :
> /system/bin/logwrapper /system/xbin/busybox run-parts /system/etc/init.d , that will allow scripts to run in directory init.d !
Click to expand...
Click to collapse
Better way would be to enable init.d in kernel- sources are available- but I don't know if init.d also needs in-system support (sorry, I don't have time to play with sources, even no time to fix modded Desire kernel).
surdu_petru said:
This command must be placed in your system initialization file !
regard,
surdu_petru
Click to expand...
Click to collapse
In init.rc to be exact, putting it in initramfs won't do anything.
EDIT:
So only "standard" recovery and update.zip flashing is missing?

gen_scheisskopf said:
Better way would be to enable init.d in kernel- sources are available- but I don't know if init.d also needs in-system support (sorry, I don't have time to play with sources, even no time to fix modded Desire kernel).
In init.rc to be exact, putting it in initramfs won't do anything.
EDIT:
So only "standard" recovery and update.zip flashing is missing?
Click to expand...
Click to collapse
Hi!
For edit kernel work is almost "crazy"....have to be calm and have more free time.....it is not so easy .. many errors can occur during the process
I tried some time ago....but device just boot with custom boot animation , but that and nothing more !!!
I'll try in the future but I expect kernel version 3.x.y.z ICS....
Them as well so you say....we need just standard CWM Recovery for our devices !
Otherwise it looks good and beautiful !
Good Luck !

Is it just a case of adding that line to the end of the Init.RC rile?

theguy said:
Is it just a case of adding that line to the end of the Init.RC rile?
Click to expand...
Click to collapse
If you add this line as in init.rc, than the scripts in init.d will never run !!!
If you do not know how to use this command....then I think you don't need.....
Remember, this tutorial is the inscription [DEV] from developers !!!
Good luck !

Hi !
To help you, let me just say the next thing :
- putting this command in init.rc ( exec /system/bin/logrwapper /system/xbin/busybox run-parts /system/etc/init.d ) , normally expected to work ! , but unfortunately for me did not work. Well, now you must look for another initialization file system !!!
( Normally this command is part of a script recovery system and it was into
recovery.sh
...............................................................................................................
#!/system/bin/sh
..........
..........
/system/bin/logwrapper /system/xbin/busybox run-parts /system/etc/init.d
.........
.........
...............................................................................................................
@theguy.... I think you're happy now ....

I've just took a closer look into ICS, it seems that init.d is enabled (take a look at /etc/init.d/rcS).
A little edit should enable all scripts to be used:
Code:
#!/bin/sh
# Start all init scripts in /etc/init.d
# executing them in numerical order.
#
for i in /etc/init.d/* ;do /* was: /etc/init.d/S??* */
# Ignore dangling symlinks (if any).
[ ! -f "$i" ] && continue
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set start
. $i
)
;;
*)
# No sh extension, so fork subprocess.
$i start
;;
esac
done

Related

[Q] dsifix.ko applied to stock milestome froyo rom

hello, basically my question is that, how to apply the fix to a stock froyo rom...i think that it must be done trougth open recovery but i wanted to be sure. thankss
it can be done through the console of open recovery, or through a terminal editor if you have root.
edit: simpler way for stock roms
copy the dsifix.ko to your sdcard
mount the /system partition as read/write
run these commands:
Code:
cp /sdcard/dsifix.ko /system/lib/modules/dsifix.ko
chmod 644 /system/lib/modules/dsifix.ko
echo "insmod /system/lib/modules/dsifix.ko" >> /system/etc/rootfs/init.mapphone_umts.rc
correct me if im wrong, but the second directory, system/rootfs/, isnt that only for cyano based roms?? because in stock roms it doesnt exist. thanks for the reply.
ah you're right, sorry
hmm you could try using the 'install mods autostarts - not needed in many roms' script thats in androidiani openrecovery, and then running these commands:
Code:
cp /sdcard/dsifix.ko /system/lib/modules/dsifix.ko
chmod 644 /system/lib/modules/dsifix.ko
cd /system/etc/init.d
touch 1dsifix
echo "insmod /system/lib/modules/dsifix.ko" > 1dsifix
chmod 750 1dsifix
I'm not entirely sure this will work, but try it and see.
Hi,
to sum it up:
To use additional kernel modules (e.g. dsifix.ko) you need to tweak the startup scripts (e.g. init.mapphone_umts.rc)
To use tweaked startup scritps like modified init.mapphone_umts.rc you'll need a ROM that makes use of 2nd init process.
Stock ROMs do not use 2nd init, because it's a hacked feature and stock ROMs are usually not hacked
On stock ROM there's also no /system/etc/init.d nor /system/etc/rootfs directory, because they are no used there.
Hope this helps
P.S.: Don't know about this androidiani stuff ...
EDIT: Search button is so nice... http://forum.xda-developers.com/showthread.php?t=1003338
Regards,
scholbert
great i will try this evening, thanks for the repliess.
Sent from my Milestone using XDA App
the androidiani mod enables 2nd-init, which means it checks for scripts in the init.d folder
that link is only for the display update fix, which causes tearing, not for the kernel module fix thats popped up recently. However, we can modify coldsphinx's instructions to suit our purposes.
as usual, you'll need to move the dsifix to /system/lib/modules
Code:
cp /sdcard/dsifix.ko /system/lib/modules/dsifix.ko
chmod 644 /system/lib/modules/dsifix.ko
then rename the mot_boot_mode file to mot_boot_mode.bin
Code:
mv /system/bin/mot_boot_mode /system/bin/mot_boot_mode.bin
then create the file /system/bin/mot_boot_mode
and add this to the file:
Code:
#!/system/bin/sh
export PATH=/system/bin:$PATH
mot_boot_mode.bin
insmod /system/lib/modules/dsifix.ko
and then finally set the permissions
Code:
chmod 755 /system/bin/mot_boot_mode
it will work.
GReat! thanks!

[Q] Init.d under Cocore 6.2 dont working [SOLVED]

Hi
Im using Galaxy S Advance with:
JB 4.1.2 and stock ROM
rooted
kernel Cocore 6.2
I tried to use script on boot from init.d directory, unfortunately not working.
To see if it works fine, I created /etc/init.d folder
with permissions 777, owner root
Inside init.d folder, I created simple script: testinit.sh also testinit
Code:
#!/system/bin/sh
echo init.d script is working > /storage/sdcard0/init.txt
file permissions 777, owner root
But after restart, file init.txt on sdcard0 isnt created,
so I suppose that script isnt running.
I created also another script follow Cocore thread
Code:
#!/system/bin/sh
insmod /lib/modules/logger.ko
for start logger. Logger didnt start also.
Both scripts started in console or adb works fine.
Tnx in advance
darcik said:
Hi
Im using Galaxy S Advance with:
JB 4.1.2 and stock ROM
rooted
kernel Cocore 6.2
I tried to use script on boot from init.d directory, unfortunately not working.
To see if it works fine, I created /etc/init.d folder
with permissions 777, owner root
Inside init.d folder, I created simple script: testinit.sh also testinit
Code:
#!/system/bin/sh
echo init.d script is working > /storage/sdcard0/init.txt
file permissions 777, owner root
But after restart, file init.txt on sdcard0 isnt created,
so I suppose that script isnt running.
I created also another script follow Cocore thread
Code:
#!/system/bin/sh
insmod /lib/modules/logger.ko
for start logger. Logger didnt start also.
Both scripts started in console or adb works fine.
Tnx in advance
Click to expand...
Click to collapse
Try this way: LINK.
Tnx for answer, atm I abandoned testinit script, this isnt important
and focused on start of logger .
I changed it to
Code:
#!/system/bin/sh
busybox mount -o remount,rw -t auto /system;
busybox insmod /lib/modules/logger.ko
but logger didnt start.
Does the system log, what happens when boot, I mean errors?
I have a habit of "big" Linux system
darcik said:
Tnx for answer, atm I abandoned testinit script, this isnt important
and focused on start of logger .
I changed it to
Code:
#!/system/bin/sh
busybox mount -o remount,rw -t auto /system;
busybox insmod /lib/modules/logger.ko
but logger didnt start.
Does the system log, what happens when boot, I mean errors?
I have a habit of "big" Linux system
Click to expand...
Click to collapse
I think log starts after script is executed, and it can't be executed during pre-boot. So maybe it only works when you get in system (booted). And then there is not much to show, try doing some thing while logcat is triggered. Like change governor, IO etc.
I am just gessing this, maybe I am wrong about that, but seams logical to me. :fingers-crossed:
Lol
Incidentally, I found the answer to my problem in this topic.
Save the script without any extensions (Yes, not even .sh extension).
Click to expand...
Click to collapse
So I renamed my script to logcat without sh extension and all works.
Anyway tnx for help.
Cocore 8.0 init.d not working
I make this init.d file for cocore 8.0:
#!/system/bin/sh
busybox mount -o remount,rw -t auto /system;
echo 12 > /sys/module/mxt224e/parameters/threshold_batt
echo init.d script is working > /storage/sdcard0/init.txt
echo "pegasusq" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo "sio" > /sys/block/mmcblk0/queue/scheduler
echo 100663296 > /sys/block/zram0/disksize
mkswap /dev/block/zram0
swapon /dev/block/zram0
echo 700 > /sys/kernel/abb-charger/max_ac_c
echo 0 > /sys/module/mali/parameters/mali_debug_level
Click to expand...
Click to collapse
placed in /system/etc/init.d with "logcat" name. This scirpt don't make the txt file. Why?
Permission 755 for script file. No .sh at the end - just filename.
That should help
Sent from my SGS Adv. using xda-developers app.
th3cr0w said:
Permission 755 for script file. No .sh at the end - just filename.
That should help
Sent from my SGS Adv. using xda-developers app.
Click to expand...
Click to collapse
The solution was i left some space after the command. Thank you!

[TEMPORARY FIX][TWEAK][MT6582] Xposed Installer Log File Gets Big

Hi All,
I am a happy user of Xposed Installer and using Modules.
However, one day my friend asked me if I could help him to fix the logging problems of Xposed because it almost ate like ~500MB of his internal space without him knowing it. So, I made this simple script to make a temporary fix (although I can still make this a little more flexible by checking the log file instead of running it on a fixed interval). I hope this helps and I hope Xposed dev can make an option to cleanup the logs generated by the modules.
More power
The script - I found that (not really proven, but as observed) looping scripts in the init.d are not very well handled so I did a workaround. I have the main script (cleaner) inside data and one script (trigger) in init.d. So here are they:
The main script - I placed on /data/Tweaks/scripts:
Code:
#!/system/bin/sh
# Name: 50_XposedCleanLog
# Date: 10/27/2014
# Author: Arsie Organo Jr. - [email protected]
# Link:
# About: This will clean up Xposed Installer app generated
# logs every X minutes.
# 1. Rooted
# 2. Busybox is installed.
####################################################
# Interval between 50_XposedCleanLog runs, in seconds, 18000=.5hour
XPOSEDLOGS=/data/data/de.robv.android.xposed.installer/log/error.log
a=0
sleepme=18000
while [ $a -ge 0 ]
do
busybox rm -f $XPOSEDLOGS
busybox touch $XPOSEDLOGS
chown root:root $XPOSEDLOGS
echo "Xposed Logs Cleanup Started $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $XPOSEDLOGS;
echo "Cleanup will run again in the next $(expr $sleepme / 60) min" | tee -a $XPOSEDLOGS;
echo $a
a=`expr $a + 1`
echo "Xposed Logs cleaner completed at $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $XPOSEDLOGS;
sleep $sleepme
done
# END
And the trigger is placed in /system/etc/init.d - 10_DONOTDELETE:
Code:
#!/system/bin/sh
# Name: 10_DONOTDELETE
# Date: 10/28/2014
# Author: Arsie Organo Jr. - [email protected]
# Link:
# About: This script is needed to run all the tweaks
# and looping scripts.
# You will need your device to be:
# 1. Rooted
# 2. Busybox is installed.
####################################################
datalog=/data/Tweaks/logs/10_DONOTDELETE.log
busybox rm -f $datalog
busybox touch $datalog
# Xposed logs cleaner
/system/bin/sh /data/Tweaks/scripts/50_XposedCleanLog.sh > /dev/null 2>&1 &
if [ `busybox ps -ef | grep Tweaks | grep 50_XposedCleanLog.sh | wc -l` -eq 1 ] ;
then
echo "$( date +"%m-%d-%Y %H:%M:%S" ) Xposed logs cleaner initiated" | tee -a $datalog;
else
echo "$( date +"%m-%d-%Y %H:%M:%S" ) Xposed logs cleaner initialization FAILED" | tee -a $datalog;
fi;
So this simply means that the main script will be called upon restart and then loop it in the background checking the log file every 30min.
Note: Phone needs to be rooted and must have busybox installed. Tested on MediaTek MT6582 (MP Agua Rio) JB version.
I have attached a flashable here.. direct flash only and there is no need to wipe your cache.
This will work ONLY if your phone supports init.d and the generated Xposed log file is located here - /data/data/de.robv.android.xposed.installer/log/error.log
Wow very nice keep it up sir. :good:
Rovo89 set limit for log file to 5 MB. https://github.com/rovo89/XposedBridge/commit/afcc3e1e788ea44bfd00245a24b5dfe6c86aa3d0
Cool!
pyler said:
Rovo89 set limit for log file to 5 MB. https://github.com/rovo89/XposedBridge/commit/afcc3e1e788ea44bfd00245a24b5dfe6c86aa3d0
Click to expand...
Click to collapse
That's cool, however using the latest Xposed (experimental version) we've seen the error.log can go more than 500mb.
You can check the ridiculous size of the error.log below. So to aid this, I made this looping script.
eyesfortech said:
That's cool, however using the latest Xposed (experimental version) we've seen the error.log can go more than 500mb.
You can check the ridiculous size of the error.log below. So to aid this, I made this looping script.
Click to expand...
Click to collapse
Yes, this change is not part of 2.7 exp1.
too bad but there is always hope
pyler said:
Yes, this change is not part of 2.7 exp1.
Click to expand...
Click to collapse
yeah... I guess so, but there's always hope
huge issue
I check and mine is 7gb but when I check application manager it says xposed is using 11gb why?
manual Clear logs
bigchuk00 said:
I check and mine is 7gb but when I check application manager it says xposed is using 11gb why?
Click to expand...
Click to collapse
Hi,
have you tried manually clearing the logs from Xposed Logs options?
No. I didn't. The flash able zip was what I used n it worked fine . thank you.
Cool! I guess the permanent solution will be provided in the next update of Xposed (hopefully!)
It's just absurd that these 'error logs' rack up over a 100mb per day. The Xposed chappies say look at the log to see what module is causing the problem - well, I can't make head nor tail of the logs. Should be a better way of dealing with it.
eyesfortech said:
Cool! I guess the permanent solution will be provided in the next update of Xposed (hopefully!)
Click to expand...
Click to collapse
I admire your genius in setting up cron & it works flawlessly on my device, please would be able to create a flashable script or cron that will make @zeppelinrox sclean(wipe dalvik & reboot) script to run once each week?
slimcyril said:
I admire your genius in setting up cron & it works flawlessly on my device, please would be able to create a flashable script or cron that will make @zeppelinrox sclean(wipe dalvik & reboot) script to run once each week?
Click to expand...
Click to collapse
Unfortunately I am currently swamped with my day job and I cannot promise anything sooner. Can you give me the link the one you wanted me to try? And on what device? Currently I am no longer using MTK so testing it will also be a problem.
Thanks.
eyesfortech said:
Unfortunately I am currently swamped with my day job and I cannot promise anything sooner. Can you give me the link the one you wanted me to try? And on what device? Currently I am no longer using MTK so testing it will also be a problem.
Thanks.
Click to expand...
Click to collapse
Thanks for your response I later found what I was looking here http://forum.xda-developers.com/showthread.php?t=2700146

[SOLVED] Cannot change LMK minfree values with script in /magisk/.core/service.d

Dear Community, dear Developers outside..
I'm using Magisk 14.0 on a Redmi Note 4 Snapdragon and super satisfied with it.
I just want to make simple changes like changing the lowmemorykiller minfree parameters - just like an init.d script in Kernel Adiutor..
Most of the commands are effective - but some of them are not..
This is what I want to apply for example:
chmod 666 /sys/module/lowmemorykiller/parameters/minfree
chown root /sys/module/lowmemorykiller/parameters/minfree
echo '7283,14566,21849,28928,36415,43698' > /sys/module/lowmemorykiller/parameters/minfree
..but does not work..
But these, for example.. these are working just fine:
echo '30' > /proc/sys/vm/swappiness
echo '0' > /sys/module/lowmemorykiller/parameters/enable_adaptive_lmk
echo '80' > /proc/sys/vm/overcommit_ratio
echo '400' > /proc/sys/vm/vfs_cache_pressure
echo '2430' > /proc/sys/vm/extra_free_kbytes
echo '4096' > /proc/sys/kernel/random/write_wakeup_threshold
echo '1024' > /sys/block/mmcblk0/queue/read_ahead_kb
echo '0' > /sys/block/mmcblk0/queue/iostats
echo '1' > /sys/block/mmcblk0/queue/add_random
echo '1024' > /sys/block/mmcblk1/queue/read_ahead_kb
echo '0' > /sys/block/mmcblk1/queue/iostats
echo '1' > /sys/block/mmcblk1/queue/add_random
swapoff /dev/block/zram0 > /dev/null 2>&1
echo '1' > /sys/block/zram0/reset
echo '0' > /sys/block/zram0/disksize
echo '1' > /sys/block/zram0/max_comp_streams
echo '524288000' > /sys/block/zram0/disksize
mkswap /dev/block/zram0 > /dev/null 2>&1
swapon /dev/block/zram0 > /dev/null 2>&1
echo '4096' > /proc/sys/kernel/random/read_wakeup_threshold
echo '4096' > /proc/sys/vm/min_free_kbytes
echo '0' > /proc/sys/vm/oom_kill_allocating_task
echo '90' > /proc/sys/vm/dirty_ratio
echo '70' > /proc/sys/vm/dirty_background_ratio
I do know that all I have to do is to put my script to one of these dirs - depending on when I want to run the scripts:
/magisk/.core/service.d
/magisk/.core/post-fs-data.d
But, as I mentioned - most of them has effect, some of them has no..
Any comment, any suggestion is more than appreciated.
Thank you!
[SOLVED] - solution is in post #5
Desperate bump..
I searched for help docs for service.d and post-fs-data.d but counldn't find them, can I ask you when each folder is executed, also does the scripts inside them must have .sh extension or not ?
I want to restart my systemui after boot complete, can you tell me if this script is ok ?
Code:
#!system/bin/sh
sleep 20
su
pkill -l TERM -f com.android.systemui
ps : the pkill command works fine after an "su" in terminal emulator
sorry for the offtopic !
@sheraro
https://github.com/topjohnwu/Magisk/blob/master/docs/README.MD
First of all: the solution for my issue was a simple sleep 30 in the services.sh to delay the start.. and I used an auxiliary file as well to make the changes (called from services.sh with 30sec delay, copied with the update-binary file directly, set permission to 0777 via config.sh) after that is all started working..
sheraro said:
I searched for help docs for service.d and post-fs-data.d but counldn't find them, can I ask you when each folder is executed, also does the scripts inside them must have .sh extension or not ?
I want to restart my systemui after boot complete, can you tell me if this script is ok ?
Code:
#!system/bin/sh
sleep 20
su
pkill -l TERM -f com.android.systemui
ps : the pkill command works fine after an "su" in terminal emulator
sorry for the offtopic !
Click to expand...
Click to collapse
So, second thing, @sheraro, I think you should delete the command su from your script because Magisk scripts are running as root anyway and if you issue su command it will start a shell with elevated privileges - an interactive shell, not what you want here, a sudo like command.. it works in the terminal because it is interactive but in the shell script if you start su it starts an interactive shell and it halts your script because it won't exit the shell you started.. and the next command will never run.. if you know what I mean.. but you don't need it anyway, because - as I mentioned - it is running as root anyway. +1: The syntax of the shebang is bad in your example, it is missing an exclamation mark. Can you re-test it like this:
Code:
#!/system/bin/sh
sleep 20
pkill -l TERM -f com.android.systemui
exit 0
.sh extension is not needed, the thing is: you have to set the correct permission in the config.sh like this:
Code:
set_permissions() {
# Default permissions, don't remove them
set_perm_recursive $MODPATH 0 0 0777 0777
[..omitted..]
Thing is: the files must have execute priv. and you can execute them like
Code:
$MODDIR/./desiredfilename
in the services.sh script.
Hope this helps.
crok.bic said:
.sh extension is not needed, the thing is: you have to set the correct permission in the config.sh like this:
Code:
set_permissions() {
# Default permissions, don't remove them
set_perm_recursive $MODPATH 0 0 0777 0777
[..omitted..]
Thing is: the files must have execute priv. and you can execute them like
Code:
$MODDIR/./desiredfilename
in the services.sh script.
Hope this helps.
Click to expand...
Click to collapse
I'm just pasting my script in service.d only, set permissions manually to 0777, corrected !#/system typo, removed su command, but no luck...
Where's services.sh and config.sh ?
sheraro said:
I'm just pasting my script in service.d only, set permissions manually to 0777, corrected !#/system typo, removed su command, but no luck...
Where's services.sh and config.sh ?
Click to expand...
Click to collapse
Reading your comment I think you are not developing a Magisk module, do you?
I do and this is why you have no idea where is config.sh, services.sh and the others I think.
If you just want to have some kind of "init.d script" support and run the script in your own phone *only* then your script should be in the folder /magisk/.core/service.d and it should have execute permission. That's all what you need - probably the sleep 20 is not enough, increase it to sleep 30 for instance.
If this is still not enough info I would suggest to read the Magisk documentation thoroughly (linked in post #4) and if you still stuck I suggest you to open your own thread, describe your problem thoroughly (what is your goal? what would you like to achive? how did you already try? what is happening but should not or not happening but you think it should happen? you know what I mean..) and ask the community. Probably you will be able to solve your issue in minutes/hours.
I changed it to sleep 100, same problem, you're right I should create a new thread for this.
I have a theme installed that mimics oreo style, but the systemUI is not themed until it's restarted, so I thought about a script executed after boot, anyway thanks for your help
It seems that sleep will delay the run of other modules' service.sh. is there any solution that will not affect other module?
nicorg3221 said:
It seems that sleep will delay the run of other modules' service.sh. is there any solution that will not affect other module?
Click to expand...
Click to collapse
I don't experience this behavior - what you described is the post-fs-data behavior.
I did the trick with a separate ("auxiliary") file and tried to explain how in post #5 but let me try again:
- created a file in the module's common folder (I gave the name `tweak`)
- this file starts with a shebang (it's a script..) and continues with a sleep 30 then comes my commands..
- then copied the file from the module to the Magisk module directory into /magisk/$MODDIR with the module file META-INF/com/google/android/update-binary (I added it to the copy section, manually.. I know, I know, it should work automagically anyway, but did not work and I was fed up with the coding, so hardcoded it.. sorry)
- I set the default file permission to 0777 in config.sh (yes, 0777, this is loose AF but works.. and I don't really care, the file contains code that can make the device *better* and has no suid bit set, so there is only little to no room to harm anything..)
- then I included a call in my module's common/service.sh like $MODDIR/./tweak to start my script
- when the tweak script starts it will start with the sleep 30 so implements the delay.. BUT!
- Because services.sh files from the modules are called parallelly by Magisk (by default, by it's nature, by it's code.. you got it) my module does not delays others - but still has the delay.
Hope this helps.
sheraro said:
I changed it to sleep 100, same problem, you're right I should create a new thread for this.
I have a theme installed that mimics oreo style, but the systemUI is not themed until it's restarted, so I thought about a script executed after boot, anyway thanks for your help
Click to expand...
Click to collapse
Pleased to help you - but honestly, if the only task you need is to kill and restart systemUI then I would do it via init.d script run by an app that mimics init.d scripting, or using a kernel that supports init.d scripts (if only you want to use that theme). It's just less complex for you I think, but honestly, a simple script file that has execute permission in /magisk/.core/services.d/ gives you 100% the same solution.
crok.bic said:
I don't experience this behavior - what you described is the post-fs-data behavior.
I did the trick with a separate ("auxiliary") file and tried to explain how in post #5 but let me try again:
- created a file in the module's common folder (I gave the name `tweak`)
- this file starts with a shebang (it's a script..) and continues with a sleep 30 then comes my commands..
- then copied the file from the module to the Magisk module directory into /magisk/$MODDIR with the module file META-INF/com/google/android/update-binary (I added it to the copy section, manually.. I know, I know, it should work automagically anyway, but did not work and I was fed up with the coding, so hardcoded it.. sorry)
- I set the default file permission to 0777 in config.sh (yes, 0777, this is loose AF but works.. and I don't really care, the file contains code that can make the device *better* and has no suid bit set, so there is only little to no room to harm anything..)
- then I included a call in my module's common/service.sh like $MODDIR/./tweak to start my script
- when the tweak script starts it will start with the sleep 30 so implements the delay.. BUT!
- Because services.sh files from the modules are called parallelly by Magisk (by default, by it's nature, by it's code.. you got it) my module does not delays others - but still has the delay.
Hope this helps.
Click to expand...
Click to collapse
I have my script in starting in .Core. Maybe that's the problem
nicorg3221 said:
I have my script in starting in .Core. Maybe that's the problem
Click to expand...
Click to collapse
..then it is in the wrong dir.. it is clearly described in the Magisk documentation.
I have researched a bit. I think you can use getprop sys.boot_completed to check if boot is completed. We should run init.d scripts after boot is completed instead of just wait for 30/100 seconds.
I place all my init.d scripts I want to run in /magisk/.core/service.d/init.d.
Then, I have a service.d script [exec_init_d.sh] in /magisk/.core/service.d. Magisk will run exec_init_d.sh when boot.
exec_init_d.sh will wait for sys.boot_completed and run all the files in /magisk/.core/service.d/init.d after boot completed
exec_init_d.sh
Code:
#!/system/bin/sh
# Please don't hardcode /magisk/modname/... ; instead, please use $MODDIR/...
# This will make your scripts compatible even if Magisk change its mount point in the future
MODDIR=${0%/*}
# This script will be executed in late_start service mode
# More info in the main Magisk thread
if [ "$1" != "1" ]; then
$0 1 &
log -p i -t Magisk "start new instance to let Magisk boot stages proceed"
exit
fi
#param
RUNLOG=0
RETRY_INTERVAL=5 #in seconds
MAX_RETRY=60
EXEC_WAIT=3 #in seconds
INIT_D_DIR=$MODDIR/init.d
LOG_PATH=$MODDIR/debug.log
#init
retry=${MAX_RETRY}
#wait for boot completed
log -p i -t Magisk "wait for boot completed"
while (("$retry" > "0")) && [ "$(getprop sys.boot_completed)" != "1" ]; do
sleep ${RETRY_INTERVAL}
((retry--))
done
if (("$retry" == "0")); then
log -p i -t Magisk "boot not completed within maximum number of retry"
else
log -p i -t Magisk "boot completed"
fi
sleep ${EXEC_WAIT}
log -p i -t Magisk "init.d execution started from ${INIT_D_DIR}"
if (("${RUNLOG}" == "1")); then
/data/magisk/busybox run-parts $INIT_D_DIR &> $LOG_PATH
log -p i -t Magisk "init.d execution output written to $LOG_PATH"
else
/data/magisk/busybox run-parts $INIT_D_DIR
fi
log -p i -t Magisk "init.d execution completed"

[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

Categories

Resources