Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,729,823 Members 52,070 Now Online
XDA Developers Android and Mobile Development Forum

[HOW-TO] Run commands and persist settings after reboot - Updated

Tip us?
 
JoshMiers
Old
(Last edited by JoshMiers; 6th January 2011 at 06:07 PM.)
#1  
Member - OP
Thanks Meter 83
Posts: 52
Join Date: Feb 2010
Default [HOW-TO] Run commands and persist settings after reboot - Updated

Here is an easy way to run commands after each boot.

In the init.rc file, the file /system/bin/clrbootcount.sh always gets run after a successful boot. Since it isn't trivial to change the init.rc file, we will use clrbootcount.sh to run commands after a boot. Since people are having issues with modifying clrbootcount.sh, we will choose a safer method.

clrbootcount.sh will always attempt to call /data/boot_complete_hook.sh, which doesn't exit. We are going to create this file and use that to run commands.

Create a file named boot_complete_hook.sh with the following contents (On Windows, use Notepad++):
Code:
#!/system/bin/sh
##################################################################################
#
# File          boot_complete_hook.sh
# Description	Run any commands that you want to be run after boot
#
## 
setprop persist.service.mount.umsauto 0
echo 68000,1024/70/200/40,600/10/11/10 > /sys/devices/omapdss/display0/timings
Save and close.

Now, execute the following commands to put the file on your nook:
Code:
adb push boot_complete_hook.sh /data/boot_complete_hook.sh
adb shell chmod 755 /data/boot_complete_hook.sh
Note:
Before you reboot verify that the file will run properly. Open up a shell via adb shell. Inside that run the following:
Code:
setprop persist.service.mount.umsauto 1
getprop persist.service.mount.umsauto
You should see 1 as the output. Now run:
Code:
sh /system/bin/clrbootcount.sh
You should see an output similar to:
Code:
4+0 records in
4+0 records out
4 bytes transferred in 0.010 secs (400 bytes/sec)
Now run:
Code:
getprop persist.service.mount.umsauto
If 0 is printed out, exit the shell.

If 0 is not printed out, something went wrong and the file will not be run properly on the next boot. If you do reboot in this state 8 times, the boot count won't be reset and you will hit the factory reset. While you are trying to get the script working, you could always manually reset the boot count by executing (from a shell):

Code:
dd if=/dev/zero of=/rom/devconf/BootCnt bs=1 count=4

Now reboot:

Code:
adb shell reboot
As you are rebooting, run:
Code:
adb shell getprop persist.service.mount.umsauto
It will return 1 since the init.rc file sets it to 1 explicitly. However, once you are fully booted it will return 0.
The Following 3 Users Say Thank You to JoshMiers For This Useful Post: [ Click to Expand ]
 
>DARKMAN<
Old
#2  
>DARKMAN<'s Avatar
Senior Member
Thanks Meter 22
Posts: 154
Join Date: Dec 2010
Location: Chisago City, MN
Didn't work for me.
 
docfreed
Old
#3  
docfreed's Avatar
Senior Member
Thanks Meter 140
Posts: 766
Join Date: Jun 2009
Quote:
Originally Posted by JoshMiers View Post
Here is an easy way to run commands after each boot.

In the init.rc file, the file /system/bin/clrbootcount.sh will always gets run after a successful boot. Since it isn't trivial to change the init.rc file, we will use clrbootcount.sh to run commands after a boot.

Do:
Code:
adb pull /system/bin/clrbootcount.sh .
Open the file (on Windows, don't use Notepad) and you should see:
Code:
#!/system/bin/sh
##################################################################################
#
# File          clrbootcount.sh
# Description	Clear the bootcount variable to 0 on successful boot
#
## 
# Run potential hook first.
/data/boot_complete_hook.sh
# Zero the boot count
dd if=/dev/zero of=/rom/devconf/BootCnt bs=1 count=4
Add the following to the end of the file:
Code:
#run other commands
setprop persist.service.mount.umsauto 0
Save and close.

Now, execute the following commands to put the file back on your nook:
Code:
adb shell mount -o rw,remount -t ext2 /dev/block/mmcblk0p5 /system 
adb push clrbootcount.sh /system/bin/clrbootcount.sh
adb shell chmod 755 /system/bin/clrbootcount.sh
adb shell mount -o ro,remount -t ext2 /dev/block/mmcblk0p5 /system 
adb shell reboot
As you are rebooting, run:
Code:
adb shell getprop persist.service.mount.umsauto
It will return 1 since the init.rc file sets it to 1 explicitly. However, once you are fully booted it will return 0.
Wouldn't this screw up the 8X "back to stock firmware" sequence since that depends on having the boot counter increment up to 8?
 
JoshMiers
Old
#4  
Member - OP
Thanks Meter 83
Posts: 52
Join Date: Feb 2010
Quote:
Originally Posted by docfreed View Post
Wouldn't this screw up the 8X "back to stock firmware" sequence since that depends on having the boot counter increment up to 8?
The script file is already there and already being called after each successful boot. The 8x boot counter logic happens with 8 failed boots. Regardless, the instructions just show you how to append a custom command to be run after the stock commands run, no other booting logic is affected.

Quote:
Originally Posted by >DARKMAN< View Post
Didn't work for me.
What didn't work? Run the following and paste your output:
Code:
adb shell cat /system/bin/clrbootcount.sh
Code:
adb shell ls -l /system/bin/clrbootcount.sh
 
khaytsus
Old
#5  
Senior Member
Thanks Meter 1059
Posts: 6,817
Join Date: Apr 2008
Location: Central Kentucky
Awesome, thanks for the tip! Been wondering how to put in my own stuff into the init, I'd love to modify the path but I suspect this won't be the way, but regardless it's good info.

BTW, I have found that disabling this USM property seems to disable the SD card automounting but the Nook itself might still automount... But that's for another thread I suppose
AT&T LG G2 - 4.3, AOKP
Samsung Note i717 - 4.2.2, Unofficial AOKP
Nexus 7 Wifi 2012 - 4.4.2, Stock Rooted (m-kernel)
Try my Alternative XDA CSS Themes (including 2010!)

--
http://theblackmoor.net
http://unlimitedphoto.com
 
alphahere
Old
#6  
Senior Member
Thanks Meter 33
Posts: 256
Join Date: Nov 2010
Worked perfectly

This is exactly what I was looking for.

Thanks

Sent from my LogicPD Zoom2
 
JoshMiers
Old
#7  
Member - OP
Thanks Meter 83
Posts: 52
Join Date: Feb 2010
There seems to be a little confusion over at the refresh rate thread http://forum.xda-developers.com/showthread.php?t=901294.


To be explicit, if you want to disable auto-mounting as well as change the refresh rate, you would edit clrbootcount.sh to have the following contents:
Code:
#!/system/bin/sh
##################################################################################
#
# File          clrbootcount.sh
# Description	Clear the bootcount variable to 0 on successful boot
#
## 
# Run potential hook first.
/data/boot_complete_hook.sh
# Zero the boot count
dd if=/dev/zero of=/rom/devconf/BootCnt bs=1 count=4
#run other commands
setprop persist.service.mount.umsauto 0
echo 68000,1024/70/200/40,600/10/11/10 > /sys/devices/omapdss/display0/timings
If you don't want to disable auto-mounting, just remove the line with
Code:
setprop persist.service.mount.umsauto 0
 
>DARKMAN<
Old
#8  
>DARKMAN<'s Avatar
Senior Member
Thanks Meter 22
Posts: 154
Join Date: Dec 2010
Location: Chisago City, MN
I ran what was posted and it still returns 1.

Sent from my HAXSUNG Moment
 
jleecong
Old
(Last edited by jleecong; 6th January 2011 at 08:14 PM.)
#9  
Member
Thanks Meter 33
Posts: 60
Join Date: Aug 2007
Quote:
Originally Posted by JoshMiers View Post
What didn't work? Run the following and paste your output:
Code:
adb shell cat /system/bin/clrbootcount.sh
Code:
adb shell ls -l /system/bin/clrbootcount.sh
Screen shot attached (1.0.1 Auto-Nooter 2.12.25).
Attached Thumbnails
Click image for larger version

Name:	adb.jpg
Views:	88
Size:	64.8 KB
ID:	482296  
 
>DARKMAN<
Old
#10  
>DARKMAN<'s Avatar
Senior Member
Thanks Meter 22
Posts: 154
Join Date: Dec 2010
Location: Chisago City, MN
# cat /system/bin/clrbootcount.sh
cat /system/bin/clrbootcount.sh
#!/system/bin/sh
################################################## ##############################
##
#
# File clrbootcount.sh
# Description Clear the bootcount variable to 0 on successful boot
#
##
# Run potential hook first.
/data/boot_complete_hook.sh
# Zero the boot count
dd if=/dev/zero of=/rom/devconf/BootCnt bs=1 count=4
#

# ls -l /system/bin/clrbootcount.sh
ls -l /system/bin/clrbootcount.sh
-rwxr-xr-x root root 338 2011-01-06 19:50 clrbootcount.sh
#

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


XDA PORTAL POSTS

Samsung Gear Live Unboxed the XDA Way – XDA Developer TV

XDA Developer TV Producer AdamOutleris known for his XDA Unboxingseries where … more

Make Your Own DIY Capacitive Stylus

The XDA Portal is a place where we like to talkabout things that are interesting, fun, and sometimes … more