[GUIDE] How To Add Init.d Support to Your Kernel & Rom

Search This thread

alireza7991

Senior Member
Sep 2, 2012
772
2,321
26
Shahrekord
alirezafn.net
What is init.d ?

Init.d is a feature which allows you to run brunch of scripts at boot . Thats really useful while you want to set values which reset at boot or run/do any thing at every boot or install tweaks , engines and....

There are some ways to add this feature to you rom but always best way is to add init.d support directly by your kernel . I want to help you to do this :)

Requirements

1- Ability to unpack boot.img & ramdisk
2- Some basic linux shell knowloedge
3- Having Busybox located in /system/bin/busybox at your rom

Step 1: Making kernel ready

1- Unpack kernel then ramdisk
2- Open Init.rc with a text editor
3- Add this codes at the end , before the paragraph which there is "stop bootanim" command in it :

Code:
service sysinit /system/bin/sysinit
oneshot

4- Save , Exit and repack ramdisk and boot.img

Step 2 : Making Rom Ready !

1- Open /system/bin/sysinit
2- Add this codes :

Code:
#!/system/bin/sh
export PATH=${PATH}:/system/bin:/system/xbin
chmod 777 /system/etc/init.d/*
logwrapper busybox run-parts /system/etc/init.d/

3- Set permissions of sysinit to 777 or 755 ( rwxrwxr-x | rwxrwxrwx )
4- Make a directory at system/etc and name it init.d

Now you have init.d support !
 

alireza7991

Senior Member
Sep 2, 2012
772
2,321
26
Shahrekord
alirezafn.net
Bull*hit. JUST INSTALL pimpmyrom and finish ..Easy.:victory:

Pimp uses one of the worst method to add this feature to your ROM ! it doesn't effect on kernel so : 1- running init.d is slower 2- init.d is not stable at all 3- not usable for ones want to add this feature to his/her kernel 4- not run init.d at end of boot so some script which needs some binaries that are not loaded yet doesn't work 5- Can not be used for room devs

This method is the official method which is used on most famous kernels such as brood kernel . and best for devs and users :)

any way that depends on users idea that this is good or not ;)
 

RobyRc

Senior Member
Feb 21, 2012
339
79
Nashville
Pimp uses one of the worst method to add this feature to your ROM ! it doesn't effect on kernel so : 1- running init.d is slower 2- init.d is not stable at all 3- not usable for ones want to add this feature to his/her kernel 4- not run init.d at end of boot so some script which needs some binaries that are not loaded yet doesn't work 5- Can not be used for room devs

This method is the official method which is used on most famous kernels such as brood kernel . and best for devs and users :)

any way that depends on users idea that this is good or not ;)

You are wrong. :confused:
 

alireza7991

Senior Member
Sep 2, 2012
772
2,321
26
Shahrekord
alirezafn.net
In init.rc file I haven't code "stop bootanim" why and where I put this code ?
And I haven't in /system/bin file "sysinit" ?

Place those codes on the middle of init.rc ; the only difference is execute order . if you put it at first init.d wont execute becuase we have'nt system mounted still and if you put it at the end you will stop at your homescreen for a few secound so its better to execute it while you are seeing bootanimation

make new file name it sysinit and put codes siad in OP inside it .
 

t-ryder

Senior Member
Feb 23, 2011
1,569
1,256
www.t-ryder.de
Google Pixel 6
Step 2 : Making Rom Ready !

1- Open /system/bin/sysinit
2- Add this codes :

Code:
#!/system/bin/sh
export PATH=${PATH}:/system/bin:/system/xbin
chmod 777 /system/etc/init.d/*
logwrapper busybox run-parts /system/etc/init.d/

Is this needed?
I've seen some ROMs not having /system/bin/sysinit but init.d kernel support, and I've tested a ROM myself not having this file, but the
99test init.d script gave some output to /data/tmp. So I guess it was executed properly.
 

alireza7991

Senior Member
Sep 2, 2012
772
2,321
26
Shahrekord
alirezafn.net
Step 2 : Making Rom Ready !

1- Open /system/bin/sysinit
2- Add this codes :

Code:
#!/system/bin/sh
export PATH=${PATH}:/system/bin:/system/xbin
chmod 777 /system/etc/init.d/*
logwrapper busybox run-parts /system/etc/init.d/

Is this needed?
I've seen some ROMs not having /system/bin/sysinit but init.d kernel support, and I've tested a ROM myself not having this file, but the
99test init.d script gave some output to /data/tmp. So I guess it was executed properly.

There are many ways to get init.d working , you may include sysinit in init.rc or you may completely remove it and use a direct code in init.rc to execute init.d scripts or ....

Here in this method , I used sysinit in user-space to let init.d be dynamicly modifed or removed without repacking the kernel
 

t-ryder

Senior Member
Feb 23, 2011
1,569
1,256
www.t-ryder.de
Google Pixel 6
There are many ways to get init.d working , you may include sysinit in init.rc or you may completely remove it and use a direct code in init.rc to execute init.d scripts or ....

Here in this method , I used sysinit in user-space to let init.d be dynamicly modifed or removed without repacking the kernel

So just the file
Code:
#!/system/bin/sh
export PATH=${PATH}:/system/bin:/system/xbin
chmod 777 /system/etc/init.d/*
logwrapper busybox run-parts /system/etc/init.d/

would make it run (having busybox in /xbin) without having to mess around in the kernel using e.g. virtous ten studio?
 

alireza7991

Senior Member
Sep 2, 2012
772
2,321
26
Shahrekord
alirezafn.net
So just the file
Code:
#!/system/bin/sh
export PATH=${PATH}:/system/bin:/system/xbin
chmod 777 /system/etc/init.d/*
logwrapper busybox run-parts /system/etc/init.d/

would make it run (having busybox in /xbin) without having to mess around in the kernel using e.g. virtous ten studio?

there are many strange and not suggested methods which add init.d without repacking kernel but the best method is using init.rc .

But I have some ideas on getting init.d working withouy messing around kernel . I am going to test them ;
 
Last edited:

GeyerA

Senior Member
Apr 6, 2009
979
1,586
Germany, Gerolzhofen
there are many strange and not suggested methods which add init.d without repacking kernel but the best method is using init.rc .

But I have some ideas on getting init.d working withouy messing around kernel . I am going to test them ;

Hi; I googled for a while to find a way to add init.d to my ROM and found your thread. Can you also explain how to adjust the source tree before compilation that I get the init.d? I am compiling AOSP with the stock kernel. I saw a few posts before that this method just works for a kernel which supports init.d. I have no clue if the stock kernel does. Thanks :)
 

Top Liked Posts

  • There are no posts matching your filters.
  • 68
    What is init.d ?

    Init.d is a feature which allows you to run brunch of scripts at boot . Thats really useful while you want to set values which reset at boot or run/do any thing at every boot or install tweaks , engines and....

    There are some ways to add this feature to you rom but always best way is to add init.d support directly by your kernel . I want to help you to do this :)

    Requirements

    1- Ability to unpack boot.img & ramdisk
    2- Some basic linux shell knowloedge
    3- Having Busybox located in /system/bin/busybox at your rom

    Step 1: Making kernel ready

    1- Unpack kernel then ramdisk
    2- Open Init.rc with a text editor
    3- Add this codes at the end , before the paragraph which there is "stop bootanim" command in it :

    Code:
    service sysinit /system/bin/sysinit
    oneshot

    4- Save , Exit and repack ramdisk and boot.img

    Step 2 : Making Rom Ready !

    1- Open /system/bin/sysinit
    2- Add this codes :

    Code:
    #!/system/bin/sh
    export PATH=${PATH}:/system/bin:/system/xbin
    chmod 777 /system/etc/init.d/*
    logwrapper busybox run-parts /system/etc/init.d/

    3- Set permissions of sysinit to 777 or 755 ( rwxrwxr-x | rwxrwxrwx )
    4- Make a directory at system/etc and name it init.d

    Now you have init.d support !
    10
    Bull*hit. JUST INSTALL pimpmyrom and finish ..Easy.:victory:

    Pimp uses one of the worst method to add this feature to your ROM ! it doesn't effect on kernel so : 1- running init.d is slower 2- init.d is not stable at all 3- not usable for ones want to add this feature to his/her kernel 4- not run init.d at end of boot so some script which needs some binaries that are not loaded yet doesn't work 5- Can not be used for room devs

    This method is the official method which is used on most famous kernels such as brood kernel . and best for devs and users :)

    any way that depends on users idea that this is good or not ;)
    6
    Bull*hit. JUST INSTALL pimpmyrom and finish ..Easy.:victory:

    Why are you so rude?
    There are ways and ways to express own opinions... And alireza has just explained you why this method is better then PIMPMYROM.

    Sent from my AriesVe using xda premium
    5
    Hello, noob here.

    I'm trying to do this without using busybox.

    I put a script named "init.d_support.sh" into the root of the ramdisk, with this content:
    Code:
    #!/system/bin/sh 
    export PATH=${PATH}:/system/bin:/system/xbin 
    mount -o remount rw /system 
    chmod 777 /system/etc/init.d/* 
    mount -o remount ro /system 
    for FILE in /system/etc/init.d/*; do 
      sh $FILE 
    done
    The script is successful when I run it from a terminal window, but I can't get the init.rc to run it.

    I tried adding this to init.rc:
    Code:
    ## init.d support
    service initd /init.d_support.sh
        class main
        user root
        oneshot
    But it didn't work, then i tried:
    Code:
    ## init.d support
    service initd /system/bin/sh /init.d_support.sh
        class main
        user root
        oneshot
    And still doesn't work.

    Also tried adding directly "sh /init.d_support.sh" at the end of "on boot", but nothing happens.

    Can anyone help me working this out?

    use this :

    Code:
    #!/system/bin/sh 
    export PATH=${PATH}:/system/bin:/system/xbin
    for FILE in /system/etc/init.d/*; do 
      sh $FILE
    done
    4
    After everything else failed I used this method to get init.d for my Huawei G510 U8951 stock kernel.

    1) I downloaded Android image kitchen (for Windows)
    and unpacked the boot.img I extracted from the ROM.

    2) went to /ramdisk in the folders of the unpacked kernel image

    3) Added to init.rc file

    Code:
    service usrinit /system/bin/sh /system/etc/usrinit.sh
        class main
        user root
        oneshot

    So I had

    Code:
    service flash_recovery /system/etc/install-recovery.sh
        class main
        oneshot
        
    [B]service usrinit /system/bin/sh /system/etc/usrinit.sh
        class main
        user root
        oneshot[/B]

    and saved the file, then repacked the image and renamed it to boot.img (output is "image-new.img")

    4) Made a UNIX text file with the content (using notepad++) - file name usrinit.sh

    Code:
    #!/system/bin/sh
    
    export PATH=${PATH}:/sbin:/system/sbin:/system/bin:/system/xbin
    /system/bin/logwrapper /system/xbin/busybox run-parts /system/etc/init.d

    and put it to my ROM in /system/etc/

    This file needs the permissions chmod 777



    You need busybox to use this method!


    Thanks to moddingg33k @ Android-Hilfe.de