Take the 2-minute tour ×
Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. It's 100% free, no registration required.

I have a rooted HTC Hero, and what I want to do is to enable the adbd to listen to a port at boot time.

I tried some code found here:

setprop service.adb.tcp.port 5555
stop adbd
start adbd

in an Android shell and it works great.

I tried to change the init.rc file. I added the above code in init.rc and I replaced it with the original file, through these commands:

adb push init.rc sdcard

adb shell
adb su
mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /
adb cp sdcard/init.rc /

The file is replaced successfully, but when I reboot my phone and try to connect through:

adb connect <IP>:5555

the connection is not being established.

Any ideas?

(PS. I don't want to use the remoteADB application and a shell command like am start -n ... )

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

The reason it does not work properly is this:

The init.rc script resides in within the RAMDisk attached to the boot image.

Hence the init.rc script that was edited and pushed across is now overwritten by the boot image's own script upon reboot - effectively changes are lost!

You need to extract the boot image, using every boot image has the kernel and the RAMDisk. The tools available to do this can be found here.

Extracting

When invoking the script split_bootimg.pl on a boot image it will recreate the following:

  • boot.kernel
  • boot.ramdisk.gz

The two files are obviously self-explanatory. To extract the ramdisk, create a directory called RAMDisk and from that directory, invoke this: gzip -dc | cpio -i, to recreate the directory structure that is used in the RAMDisk which gets flipped over to the live file-system upon boot. In there, the file that is of pertinent information is init.rc. Now that can be modified to your heart's content.

Putting it back together

Go back up a directory level, and issue this - mkbootfs ***RAMDisk*** | gzip > my_custom_ramdisk.gz.

Then, to "attach" the original kernel to the boot image, issue the following: mkbootimg -base 0x.... -kernel boot.kernel -ramdisk my_custom_ramdisk.gz -o my_custom_boot.img.

At this point now, a boot image has been constructed, then that boot image will now have to be flashed via fastboot flash boot my_custom_boot.img.

TL;DR

Changes are lost upon re-boot because the script is not properly edited which required extracting the boot image and modifying it and re-packing it. Once re-packed and then the boot image is re-flashed, the changes will be permanent.

This is done every-time the changes are needed.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.