Commands to copy overlay to extroot during first boot OpenWrt/Domoticz build (Solved)

To whom it may concern :slight_smile:,

I'm trying to automate below actions using uci-defaults so that i don't have todo these commands manually every time i try a new image.
I'm currently keep building images to make a very cheap openwrt domoticz solution and i am even creating a new circuit board which will include 433,92 Mhz sender and receiver, and if it all works out i'm gonna try to expand it with zwave, zigbee and other hardware solutions that can directly be inserted in this openwrt router.

Todo all this i'm currently adding usb support to the router and then copy the overlay to the usb mount it reboot the router then install the domoticz package etc etc etc.

To simplify this process would it be possible to;

Copy the overlay to the usb using uci-default commands?
If not, what is the easiest way todo this automaticly during first boot?

copy domoticz package from any location during first boot and install it.
What is the easiest way todo this automaticly during first boot?

And last question for now.
which packages are best to add support for 433,92 Mhz transmitter/receiver connected to GPIO pin ( 1 datapin is used for transmitter and 1 for receiver).

Thanks in advance for your time and answers.

Run-once-until-done shell script in /etc/uci-defaults (Yes, "normal" shell scripts are OK there).

It will be a bit tricky as the overlay

UCI doesn't deal with the file system in general, though it does read/save its values in files.

lol between my post and your reply the wiki has been changed :face_with_monocle:

I managed to add the usb and mount it as overlay so if i understand you correctly.


mount /dev/sda1 /mnt
tar -C /overlay -cvf - . | tar -C /mnt -xf -
umount /mnt

should copy the overlay to the usb?
if this file is saved in uci-defaults.

Since all i could find was indeed saving to config files.
The only other thing i found that came closest was using Luci commands but havn't figured out yet how to call those from shell.

I'd probably call it as #!/bin/sh -e so that it exits on error. Otherwise the mount or tar might fail but the script succeed.

using normall scripts in uci-default seems to work fine.

I did run into another thing and that is a reboot after the files in uci-default have run.
calling another sh file that removes the uci-default file and reboots openwrt doesn't seem to work and turns out to create a loop on rebooting.

#!/bin/sh -e
rm /etc/uci-defaults/99_reboot
/bin/sleep 15
exit 0

And anyone perhaps know what the best way is to the below question?

which packages are best to add support for 433,92 Mhz transmitter/receiver connected to GPIO pin ( 1 datapin is used for transmitter and 1 for receiver).

uci-defaults scripts are automatically removed in the active overlay when they run successfully. You probably need to “remove” this one, and perhaps others on your “new” overlay as well.

Hi Jeff,

I tried that but somehow it ends up in a reboot loop.....

When i make a reboot command inside the uci-default folder like;

#!/bin/sh -e
exit 0

It won't delete the file so it keeps rebooting, i think because it waits for the reboot to complete :zipper_mouth_face:

I need the reboot so the overlay will be activated on the mounted usb.

Thats why i tried to call another script from outside the uci-default folder that first deletes the file in the uci-default folder and then reboots..... But even then i get a loop in rebooting.

The example of the explanation above;

Uci-default script;

#!/bin/sh -e
sh /some/path/to/rebootscript
exit 0

Called script outside uci-default folder;

#!/bin/sh -e
rm /etc/uci-defaults/99_reboot
/bin/sleep 15
exit 0

So the problem now is that you have to manually reboot the router for the changes to be applied.

Any ideas on how to solve this?

Why use a reboot to mount? mount works quite well. You can also mount an overlay over an overlay.

Be careful with order of execution. Your "copy" script will remove itself from the "current" overlay the way the script last appeared.

You might want to consider why you're doing the copying at all, rather than just mounting the USB before uci_defaults run.

I believe, you need to mount extroot during the preinit stage, otherwise it doesn't mount properly and can't see the additional space.

Invoke reboot only if the extroot is not mounted.

This may be due to jffs2 initialization and, if so, could also be handled with the script.

This is not a jffs2-specific issue:

# mount /dev/sdb /overlay
# mount -t overlay overlayfs:/overlay -o rw,noatime,lowerdir=/,upperdir=/overlay/upper,workdir=/overlay/work /
# mount | grep -e overlay
/dev/loop0 on /overlay type f2fs (rw,lazytime,noatime,background_gc=on,no_heap,user_xattr,inline_xattr,inline_data,inline_dentry,flush_merge,extent_cache,mode=adaptive,active_logs=6)
overlayfs:/overlay on / type overlay (rw,noatime,lowerdir=/,upperdir=/overlay/upper,workdir=/overlay/work)
/dev/sdb on /overlay type ext4 (rw,relatime,data=ordered)
overlayfs:/overlay on / type overlay (rw,noatime,lowerdir=/,upperdir=/overlay/upper,workdir=/overlay/work)
# df -h | grep -e overlay
/dev/loop0               19.1G      8.4G      9.7G  46% /overlay
overlayfs:/overlay      251.6M     47.9M    133.7M  26% /
/dev/sdb                 19.1G      8.4G      9.7G  46% /overlay
overlayfs:/overlay      251.6M     47.9M    133.7M  26% /

I'd appreciate to see it.

as shown in the wiki;[]=extroot

Note that only /overlay has grown but not the /
Final steps

Reboot the device
Verify that the partitions were mounted properly:
via LuCI
System - Software should show free space of overlay partition
System - Mount Points should show USB partition mounted as overlay
via CLI
mount should show USB partition mounted as /overlay

Simply put the reboot script in a detached shell and prepend the reboot command with a sleep command. Then the calling script does not wait for the reboot script to complete (which it naturally never does, as the router reboots immeaditely before the script reaches its end...)

in the calling script

( /some/path/to/rebootscript )&
exit 0

In the reboot script

sleep 75

I have no extroot experience, and I just wonder how well the "create extroot from uci-defaults" actually goes. You need to ensure that the extroot overlay's /etc/uci-defaults does not contain the extroot creation & this reboot uci-defaults scripts. You may need to delete them in the overlay file-copy script (which you probably run before you run the reboot script).

i think the cleaner route is to

  1. initialise non-extrooted first
  2. handle copy using temporary paths
  3. then reboot with appropriate /usb/etc/config/fstab in place

so 99-romcopy-genextrootfstabreboot - possibly not even as a uci-default... if further initialisation needs to take place.... first boot is a DOTHIS or don't.... once.... i'd kinda like to have more leeway with re-initialising / fault handling.

Sorry for the late reply, but since the default downloadable domoticz package didnt update in the download section because of boost update.....
There is a patch in github for 8 days now for it but that isn't applied yet.
I had to learn how to compile the package with openwrt.
I got that covered now...

Creating the extroot using uci-default actually works pretty well :slight_smile:

Althoug the wiki containing the explanation did change several times since my initial post and this reply and not everything in there is correct as i had to make some changes to make it work well.

If anyone is interested i can post a complete howto in here after i got everything working and well tested.

As of now i'm struggling on 1 part and that is adding a 433,92 Mhz receiver and transmitter using gpio. Since there isn't much user lvl documentation on this part for making that work under openwrt that is my last puzzle to make everything work.

What i got now is;

~10 dollar equipment (excluding usb drive)
Openwrt running stable under latest version build with all patches on 3-5-2019
Domoticz running stable with motherboad sensors and weatherstation.
I got 2 gpio's left on the router but somehow i can't make the receiver and/or transmitter been seen by either openwrt or domoticz.
If anyone has any clues on this i would be thankfull

I think (correct me if i'm wrong) that i'm following step 1,2,3 within the uci-defaults.

Could you perhaps be more clear on the path you mean by not using uci-defaults?

If there is a better way i would be stupid not to follow it..

Thanks in advance

1 Like

If your problem is solved, please consider marking this topic as [Solved]. (Click the pencil behind the topic...)

...a different issue that wants to be discussed in a new topic.

is it i2c?... generally python / c is used ... the latter being more lightweight.

you could also interface via a micro-over-usb-serial. this has the advantage of many many more gpio... but the middleware can be time consuming. or pcf then 433... works nicely too.

here is an example of python i2c

According to Tmomas i made a new topic about that bit here.

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