init.d is a traditional service management package for Linux that runs a bunch of code during booting process. What it does in an Android is that, it runs codes that are placed inside /system/etc/init.d/ folder. As Android uses Linux kernel it can also support init.d. ROMs by default do not have init.d support, however custom ROMs can have native init.d support. There are basically two ways to enable init.d in Android.
- Native init.d support that is init.d support in kernel
- Utilizing install-recovery.sh file for init.d support
(not all but most of android devices have install-recovery.sh file that executes during booting process. Create a full nandroid backup before preceding any steps.)
So here we are talking about adding init.d support in Android kernel.
Requirements
- A rooted mobile,
- A PC / Linux or Windows,
- Little knowledge about terminal/cmd,
- And little brain.
Before starting to patch kernel you may want to check if your Android device supports init.d by default or not.
To check if int.d is working..
- Check for /system/etc/init.d/ folder using a file manager. You need root access to browse /system/.
- If there is /system/etc/init.d/ folder then you have high chance to have init.d support already. To confirm this, download this zip file, extract the file 00test from zip and copy 00test to system/etc/init.d folder. And change permission to 755.
- Reboot your mobile, check for file Test.log inside /data folder. If it was there with following Ryuinferno @ XDA 2012, init.d is working, then you have already init.d support.
If you don’t have init.d support then we are going to patch kernel.
Add init.d support in kernel..
You need boot.img of your current ROM. If you don’t have, here is how backup boot.img using TWRP.
Get boot.img
- reboot to recovery
- backup boot partition
- the backed up boot partition may be an archive or .img file. But TWRP always saves with .win format.
- To check the file type (in Linux) open terminal and type file boot.emmc.win it will show the file type.
- If it is archive simply extract it with corresponding archive type. Or if it is bootimg then proceed to patching step.
- In windows simply use 7z, winrar to open boot.emmc.win. If it can’t open then it is bootimg so proceed to patching step.
There is also many options to backup boot.img using adb or app, just search for it. I can’t describe all these here.
Extract boot.img
To extract boot.img you need a special tool. Here are some links to find these tools. Some devices have special packaging so you have to search for tool that works for your device.
- MTK Tools by bgcngm – for MTK device
- BootImg Tool – other than MTK
- One Script Unpack Repack – I don’t know if it works or not. Just try.
- Android Kitchen – It can unpack repack roms and kernels(bootimg) of many devices including MTK, Samsung etc.. Large in size.
Edit init.rc
Inside /ramdisk folder open init.rc and after bootanimation process add these lines. (trick: search for ‘bootanim’ or similar)
#added init.d support
service sysinit /system/bin/sysinit
user root
oneshot
Save the file and repack boot.img.
What happens here? While booting all commands inside init.rc runs as programmed. Starts service sysinit located on /system/bin/sysinit. user root – Converts user to root before executing. oneshot – only execute service once.
Create sysinit
Then make a file, sysinit (no extension) in /system/bin/ and put this
#!/system/bin/sh
#added init.d support
export PATH=${PATH}:/system/bin:/system/xbin
mount -o remount,rw -t auto /system
chmod -R 755 /system/etc/init.d
mount -o remount,ro -t auto /system
logwrapper busybox run-parts /system/etc/init.d/
And save with permission 755.
What happens here? Sets PATH environment variable, where shell searches for binary when code is executed. Mounts /system as read/write. Changes folder and inside files permission to 755. Again mounts /system as read only. Then finally runs all the script one by one inside int.d/ using BusyBox run-parts command.
Create init.d folder
Create init.d folder inside /system/etc/. That is you have directory /system/etc/init.d/. Put files with script inside it to run in booting process. try putting 00test file you have downloaded earlier.
Links
- Android Init Language – if you want to know more about init.rc
- Term Init – if you want init.d without modifying kernel