Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

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

OP JoshMiers

6th January 2011, 01:22 AM   |  #1  
OP Member
Thanks Meter: 83
 
52 posts
Join Date:Joined: Feb 2010
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.
Last edited by JoshMiers; 6th January 2011 at 07:07 PM.
The Following 3 Users Say Thank You to JoshMiers For This Useful Post: [ View ]
6th January 2011, 02:12 AM   |  #2  
>DARKMAN<'s Avatar
Senior Member
Flag Chisago City, MN
Thanks Meter: 22
 
154 posts
Join Date:Joined: Dec 2010
More
Didn't work for me.
6th January 2011, 02:36 AM   |  #3  
docfreed's Avatar
Senior Member
Thanks Meter: 142
 
780 posts
Join Date:Joined: Jun 2009
Quote:
Originally Posted by JoshMiers

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?
6th January 2011, 04:30 AM   |  #4  
OP Member
Thanks Meter: 83
 
52 posts
Join Date:Joined: Feb 2010
Quote:
Originally Posted by docfreed

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<

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
6th January 2011, 01:12 PM   |  #5  
Senior Member
Flag Central Kentucky
Thanks Meter: 1,117
 
7,011 posts
Join Date:Joined: Apr 2008
More
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
6th January 2011, 02:43 PM   |  #6  
Senior Member
Thanks Meter: 42
 
291 posts
Join Date:Joined: Nov 2010
Worked perfectly

This is exactly what I was looking for.

Thanks

Sent from my LogicPD Zoom2
6th January 2011, 06:40 PM   |  #7  
OP Member
Thanks Meter: 83
 
52 posts
Join Date:Joined: 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
6th January 2011, 08:38 PM   |  #8  
>DARKMAN<'s Avatar
Senior Member
Flag Chisago City, MN
Thanks Meter: 22
 
154 posts
Join Date:Joined: Dec 2010
More
I ran what was posted and it still returns 1.

Sent from my HAXSUNG Moment
6th January 2011, 09:12 PM   |  #9  
Member
Thanks Meter: 33
 
60 posts
Join Date:Joined: Aug 2007
Quote:
Originally Posted by JoshMiers

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:	95
Size:	64.8 KB
ID:	482296  
Last edited by jleecong; 6th January 2011 at 09:14 PM.
7th January 2011, 02:57 AM   |  #10  
>DARKMAN<'s Avatar
Senior Member
Flag Chisago City, MN
Thanks Meter: 22
 
154 posts
Join Date:Joined: Dec 2010
More
# 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
#

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes