It needs to remove /etc/config/network and reboot device to let network be generated according to board.json

Hi,

  1. I patch base-files/files/etc/board.d/00-default_network to remove wan port.
diff --git a/openwrt-dd/package/base-files/files/etc/board.d/99-default_network b/openwrt-dd/package/base-files/files/etc/board.d/99-default_network
index d70aa35..55d5d79 100755
--- a/openwrt-dd/package/base-files/files/etc/board.d/99-default_network
+++ b/openwrt-dd/package/base-files/files/etc/board.d/99-default_network
@@ -10,7 +10,6 @@ board_config_update
 json_is_a network object && exit 0

 ucidef_set_interface_lan 'eth0'
-[ -d /sys/class/net/eth1 ] && ucidef_set_interface_wan 'eth1'

 board_config_flush
  1. On device, board.json is generated without wan port.
{
        "network": {
                "lan": {
                        "ifname": "eth0",
                        "protocol": "static"
                }
        }
}
  1. However, /etc/config/network still has wan port.

  2. If I remove /etc/config/network and reboot the device, /etc/config/network is generated according to board.json without wan port.

  3. I add debug code to dump /etc/config/network before and after mount_root, it looks like there is a default /etc/config/network is existed in the generated rootfs.

  4. I check rootfs under staging_dir, there is no 'network' generated under directory '/etc/config'.

  5. Even though I add file 'network' to directory 'package/base-files/files/etc/config' on purpose, I can find this file under rootfs of staging_dir, but it will be replaced by the default /etc/config/network on device.

    Does any one know how the default /etc/config/network is generated?

Thanks.

On the fly at the first boot after flashing, but only if there is no existing network confgi from sysupgrade. If there is a network config file kept in sysupgrade, then that naturally overrides the defaults (and prevents creating a new config based on defaults).

You did not mention your device.
There may be a device-specific recipe for the network config.
For example, the recipes for routers in the ipq806x target:
https://github.com/openwrt/openwrt/blob/master/target/linux/ipq806x/base-files/etc/board.d/02_network

That /etc/board.d/02_network is the file that you should patch.
The exact file may vary a bit by target, but that is the file that creates the network config.

Ps.
you talk about patching 00-default_network, but your example patch is for 99-default_network

1 Like

Thanks for your reply.

  1. Yes. I also modify 02_network to remove wan port, otherwise the generated board.json will have wan port.
  2. Sorry, it is typo. I patch 02_network and 99-default_network. From generated board.json, I think these patches are working.
  3. I flash factory default image to my device, it is not sysupgrade.
  4. I dump /etc/config/network before and after mount_root of 'package/base-files/files/lib/preinit/80_mount_root':
    a. After first flash image to device, /etc/config/network will have default setting with wan port. Due to this file already existed, the device won't base on board.json to generate /etc/config/network.
    b. After removing /etc/config/network, the default file only existed before mount_root. Due to this file is not existed, the device will generate /etc/config/network based on board.json.
    c. Reboot device again. the default /etc/config/network still exists before mount_root. But after mount_root, it is replaced with the generated /etc/config/network based on board.json.

I wonder how this default /etc/config/network is generated? I can't fine it in rootfs of staging_dir, there must have some way to generate it when rootfs is finally created.

That 02_network is one of the scripts that contain the functions.

Here is the part where the config file is defined

1 Like

I know the way to generate network based on board.json. The process is executed after preinit. My issue is that there is an existed network file before mount_root of /lib/preinit/80_mount_root.

The default file can be replaced by the modified network after first boot. Due to this file existed for the first boot, the process to generate network based on board.json can't work.

Even though I add file 'network' to directory 'package/base-files/files/etc/config' on purpose, this file won't be replaced by the file I add.