Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make persistent changes to init.rc

I want to change the init.rc file of an android pad. But after I change it and reboot the system, the original init.rc comes back.

How can I make the change to the init.rc persistently without rebuild the system (since I don't have the source code of the system)? Or is there any way to work around?

like image 499
user1278251 Avatar asked Mar 19 '12 09:03

user1278251


People also ask

What is init rc in Android?

It is a program to initialize the elements of the Android system. Unlike Linux, Android uses its own initialization program. This Android init program processes 2 files, and it executes the commands it finds in both programs.

How does init rc work?

rc file and is loaded by the init executable at the beginning of its execution. It is responsible for the initial set up of the system. Init loads all of the files contained within the /{system,system_ext,vendor,odm,product}/etc/init/ directories immediately after loading the primary /system/etc/init/hw/init.


2 Answers

Unpack the uramdisk using following command in host PC(Linux)

mkdir /tmp/initrc cd /tmp/initrd sudo mount /dev/sdb1 /mnt           

sdb1 is partion where uramdisk/uInitrd resides.

dd bs=1 skip=64 if=/mnt/uInitrd of=initrd.gz gunzip initrd.gz 

At this point running the command file initrd should show:

mkdir fs cd fs cpio -id < ../initrd 

Make changes to init.rc

Pack uramdisk using following commands:

find ./ | cpio -H newc -o > ../newinitrd cd .. gzip newinitrd mkimage -A arm -O linux -C gzip -T ramdisk -n "My Android Ramdisk Image" -d newinitrd.gz uInitrd-new 
like image 70
tripler Avatar answered Sep 28 '22 08:09

tripler


A number of Android devices include code to prevent root modifications to the system files. The way this is done is by using the recovery partition. On reboot, they basically restore the system partition using the recovery image. If your system is doing that then you cannot make persistent changes - the best you could do would be to hook up something to run after reboot to re-apply your change. In CyanogenMod they had hooks in the init.rc to run sdcard scripts if found. Perhaps you can create an app or widget to then launch a script to make the mods required using a setuid root script from the data partition. Without building your own ROM you are quite restricted in this area.

Possibly you could fetch the recovery image and try unpacking that, making your changes and repacking and flashing it. But make sure you can recover with fastboot before you try this.

like image 43
patthoyts Avatar answered Sep 28 '22 09:09

patthoyts