Problem adding custom file to image

Hello all,
I'm trying to add my custom "network" file to my image. I followed the instructions form openwrt's manual

build system - custom files

I have created a directory in my source code root (/home/openwrt):

/home/openwrt/files/etc/config

I placed my custom network file in the above directory and used the following command in order to compile the source code:

make -j8 V=sc defconfig download clean world

I expect to have my custom network file in /etc/config of the newly built image but the default network files is there.

Any ideas about this problem?

On first boot all defaults are generated using files in openwrt/package/base-files/files/etc/uci-defaults/

Network configurations must be added as UCI commands to a file named XX-name with XX being the order of execution. File should be named something like 99-custom in order to run after defaults have been created.

Add 'exit 0' to the end of the file to remove after execution, or your network config will continuously be overwritten.

See https://openwrt.org/docs/guide-developer/uci-defaults
And https://openwrt.org/docs/guide-user/base-system/uci

For detailed information.

1 Like

Not true.

Most settings are in ready UCI config files in/etc/config in the image.
Some settings, like "system" and "network" are generated on the fly at the first boot, based on board detection, but only in case those config files do not exist.

Uci-defaults scripts can be used tweaking settings or e.g. for migration between versions, but they have no major role in generating the normal system defaults.

Interesting. What version would this be? When building 21.02 stable there are no configuration files to begin with. Unless this is specific to my device(rpi4b)?

/etc/config doesn't exist in build directory.

All OpenWrt versions, at least since Kamikaze 8.09 in 2008...

Most settings are in respective packages, and placed into /etc/config in the image compilation phase by the Makefiles of each package.
Some settings, like network, are generated on the fly at boot, if missing. E.g. network for ipq806x routers

It does. After the compilation...
The whole root file system is initialised and prepared, and files are gathered there.
Note also the how etc/ includes also two "custom files" from me: Compile_info.txt and HNsettings.r7800-041221.cpt

This is from my build system after the compilation:

perus@ub2110:/Openwrt/r7800$ ls build_dir/target-arm_cortex-a15+neon-vfpv4_musl_eabi/root-ipq806x/etc/
adblock                      hosts                 qosify
applyHNsettings.sh           hotplug.d             rc.button
backup.stats                 hotplug.json          rc.common
banip                        hotplug-preinit.json  rc.d
banner                       init.d                rc.local
banner.failsafe              inittab               resolv.conf
board.d                      iproute2              restoreStats.sh
build.config                 lan-repeater.sh       saveHNsettings.sh
build.feeds                  localtime             services
build.version                luci-uploads          shadow
capabilities                 modules-boot.d        shells
checksettings.sh             modules.d             shinit
Compile_info.txt             mtab                  sqm
config                       odhcp6c.user          ssl
crontabs                     odhcp6c.user.d        storeStats.sh
device_info                  openwrt_release       sysctl.conf
diag.sh                      openwrt_version       sysctl.d
dnsmasq.conf                 opkg                  syslog.conf
dropbear                     opkg.conf             sysupgrade.conf
ethers                       os-release            TZ
filesystems                  passwd                uci-defaults
firewall.user                ppp                   udhcpc.user
fstab                        preinit               udhcpc.user.d
group                        profile
HNsettings.r7800-041221.cpt  protocols

perus@ub2110:/Openwrt/r7800$ ls build_dir/target-arm_cortex-a15+neon-vfpv4_musl_eabi/root-ipq806x/etc/config/
adblock   ddns       firewall    luci_statistics  sqm
banip     dhcp       fstab       nlbwmon          ucitrack
bcp38     dropbear   irqbalance  qosify           uhttpd
collectd  etherwake  luci        rpcd             upnpd

Note that /etc/config is still missing

  • system and network: generated by board detection at boot, if missing
  • wireless: generated by wifi detection at boot, if missing.
1 Like

It should work.

Works for me. See example below. Both network and fstab are copied properly into the new root file system:

perus@ub2110:/Openwrt/r7800$ ls files/etc/config/
fstab  network

perus@ub2110:/Openwrt/r7800$ cat files/etc/config/network 
***
*** GARBAGE as demo
***

perus@ub2110:/Openwrt/r7800$ ls build_dir/target-arm_cortex-a15+neon-vfpv4_musl_eabi/root-ipq806x/etc/config/
adblock   ddns       firewall    luci_statistics  rpcd      upnpd
banip     dhcp       fstab       network          sqm
bcp38     dropbear   irqbalance  nlbwmon          ucitrack
collectd  etherwake  luci        qosify           uhttpd

perus@ub2110:/Openwrt/r7800$ cat build_dir/target-arm_cortex-a15+neon-vfpv4_musl_eabi/root-ipq806x/etc/config/network 
***
*** GARBAGE as demo
***
1 Like

Very detailed response, thanks! This makes more sense, I got my understanding from reading. Evidently not enough reading done xD

It would appear my network files are compiled at boot, this explains things.

If you are planning multiple build targets, check out ./scripts/env which will allow you to keep multiple files/ trees depending on the build target.

1 Like