Auto configuration of core images

There are a few cases were having a device be operational on initial boot is greatly desirable.

In a cloud environment being able to spin up a new instance of the OS and not have to touch it’s configuration is required to have a dynamic load balanced environment.

In a manufacturing environment it is ideal to have as little manual interaction of the device as possible. In this particular instance network configuration. The desire is to be able to flash a device and have it be as close to “just works” as possible. The alternative requires someone to manually interact with a device which can be error prone and costly.

An example of this is network configuration. Having a network configuration that would be common per device requires being able to place these configurations on the core per device. Ideally these would be part of the image that is written to a drive so no work needs to be done when initially booting the device. As well as being able to place this configuration, the case of network configuration would also need console-conf and other first time setup to not launch on boot.

Here is an example of such a configuration to place in /etc/netplan :

network:
  version: 2
  renderer: networkd
  ethernets:
    renderer: networkd
    switchport0:
      match:
        name: eth0
    switchport1:
      match:
        name: eth1
    auxeths:
      match:
        name: eth2
      dhcp4: true
  bridges:
    renderer: networkd
    br0:
      interfaces:
        - switchport0
        - switchport1
      addresses:
        - 10.110.1.1/28
1 Like

As cloud-init is part of the Ubuntu Core images we have proper automatic configuration in a cloud environment today. AFAIK you need to activate cloud-init still manually once you’ve build an image with ubuntu-image.For that you need to drop /system-data/etc/cloud/cloud-init.disabled from the writable partition of your image. After that cloud-init will start on boot and attempt to configure your system.

You can easily place network configuration files in images generated with ubuntu-image. See here for an example. By adding a system-user assertion to the image you can also add default credentials you can log into the system afterwards. See here for further details.

3 Likes

Thanks Morphis. Those scripts would improve our current solution considerably. I was wondering if there was another solution though. I was talking to @niemeyer and @ogra, both of who made it sound like while using ubuntu-image works really well, it wasn’t desirable as it happens outside of the snapcraft system. I will move to similar scripts in the short term, but if they really aren’t desired I was hoping to start a longer term discussion.

I have to apologize too, that answers the use case as I posted very well, but I should have included more information. In addition to initial configuration, I can see the need to be able to continue to need to reconfigure while a device is in the field. Adding new features or services to an application snap might require configuration to a different snap or the system. For instance, if in the future a decision was made to change a network configuration internal to the device, enable or disable existing hardware, or any other place where system configuration might affect application behavior.

I am on my way out to the weekend but the network-setup-control interface allows you to rewrite netplan configuration files from a snap. You would generally implement a management snap which would consume all necessary interfaces to do what it has to do to change things in the future.