Init.d as a substitute to @reboot in OpenWrt

I recently had a lot of trouble with a 4TB drive that my wife was using to back up her media files due to some corruption. After my effort with chkdsk and ntfsfix yielded only partial results, I decided that a better solution would be to make use of a NAS and had access to couple of used ZyXEL NSA310. I figured that I will format a drive with EXT4 and pop that in this box for some stable CIFS samba file acess. It turned out that the NSA310 does not recognise EXT4 (what can be more stupid that that!). And so after initial hesitation, I flashed it with OpenWRT 19x using a serial to USB cable. Due to my error, I ended up bricking the first flash but it truns out that they devices are brick proof and I was able to boot off from with the serial cable and flashed it correctly.

The box is pretty simple and we were off to races when the next demand came and that was once every three months she would like this NAS to sync with the 4TB drive as a second backup. The NSA would be mostly kept off and switched on periodically to siphon off some stuff from laptop.

I tried scheduled jobs with @reboot but it turned out that as per the @reboot is an extension to the BSD crond, not supported by Busybox crond. So that left me with two other options:

  1. Use the copy button and program that to "rsync -aqr --no-W" from internal hdd to usb hdd


  1. Hook up USB, switch on and let the box "rsync -aqr --no-W" from internal hdd to usb hdd.... say a minute after it boots up

I opted for the second option.... for now and will try and investigate the first option at a future date.

The current version (19x) uses /etc/init.d/ directory to enable services and so I created a file it that directory with nano /etc/init.d/atreboot and following content:

#!/bin/sh /etc/rc.common
# Example script
# Copyright (C) 2007
start() {        
        rsync -aqr --no-W /mnt/int-hdd/  /mnt/usb-hdd/
        # This is executed when this service is started either manually or upon boot

Then I chmod +x /etc/init.d/atreboot

then I enabled this service using /etc/init.d/atreboot enable

Voila, when I switched off and restarted the machine the desired result was observed.

I hope this recipe is useful and inspires more complex recipes.


I would love to find out how to check the log to see what happened to this command.


Why not to use the /etc/rc.local ?

Hi trendy

I did not know that and so I am going to use that. One of the side affect of using /etc/init.d/atreboot to rsync is that it is apparently operating at higher priority and making even the cli sluggish. So not a bright idea to use /etc/init.d if /etc/rc.local would be more friendly. I will report back.


Thanks trendy, yes rc.local has worked well and both luci and cli are reasonably responsive.

Thanks for the tip.


I don't think that the script is operating at high priority if you run it in init.d and it doesn't from rc.local.
You can always adjust the priority with nice in any case.
But better to keep it tidy and use the rc.local for scripts on boot and init.d for services that need to start/stop/restart.

1 Like

You can also use your init script with boot level; instead of start, it will be called only at boot time...
Try to replace the line :
With :

1 Like

This is very useful information. Thanks for sharing. Does rc.local get executed only at boot time.


cat /etc/rc.local 
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.

Thank you sir. I should have checked before trigger happy posting a question.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.