Sunday, October 25, 2015

Creating Script to Run on Startup for OpenWRT (Barrier Breaker) - kerem izzet atam

Today I wanted to create some script to mount my USB disk to my OpenWRT device on start up and run some script in it.  You might also need it if you have some huge binary to run on boot which is stored in your USB plugged in your OpenWRT device.

There is quite good source about it :
But if you are even lazy to read it, here is what work for me.

1- Create some file under /etc/init.d/ I have named mine as  ""

2- I have put my commands (in red)  under start function in my file :

#!/bin/sh /etc/rc.common
start() {
mkdir /mnt/usb
mount /dev/sda1 /mnt/usb/

START parameter defines the run order of your script among other init scripts. I have defined relatively bigger number (100) to the other scripts to make it safer (at least i hope that way). Check the source i gave above for further reading about it. You can simply look START values of other scripts with the command below :
root@OpenWrt:/# grep START= /etc/init.d/*

And you will likely to see output like this (You can see my at undermost) :

3- Give execute permission to your script :
root@OpenWrt:/# chmod +x /etc/init.d/

4- Run command below. It will create simlink in /etc/rc.d directory so it makes your script run on boot :
root@OpenWrt:/# /etc/init.d/ enable

Yeah, that is it. Hope it works.


Anonymous said...

kerem, how can I communicate with you, I am dragon
I sent an email for you, but you didn't check it,
are you using your email address now, right?

last time when I visited turkey my english speaking skill was not fluent to talk with but now I can speak what I want to say fluently. and you can remember that I will visit turkey again, 3 years later, I told you, and year 2016 is at that time.

please check your email or inform me how can I get along with you.

Qqwy said...

Hi there! Thank you for your post. It helped me get started with writing my own init script.

I do want to point out, to whomever it may concern, that because init scripts turn out to be ordered alphabetically, using a START number higher than 99 (or lower than 10) will not have the effect you expect. In the case of your example, your code will already run after any script with START 10.

Have a wonderful day :-)