DieterReuter / image-builder-rpi64

Build SD card image for Raspberry Pi 3 64bit
MIT License
156 stars 38 forks source link

Bring wpa_supplicant.conf back to place on boot #33

Closed renevo closed 4 years ago

renevo commented 6 years ago

Because of the order of operations, if you attempt to boot a raspberry pi with wifi only using cloud-init and the current write_files and runcmd options, it will actually be too late to install core dependencies.

The "good" order of operations would be to copy wpa_supplication.conf from /boot if it exists and then add the wlan0 file to interfaces.d.

While on the surface it "looks" like it works, it actually fails a lot of cloud-init due to not having internet connection until later in the post.

renevo commented 6 years ago
Cloud-init v. 0.7.9 running 'modules:config' at Sat, 04 Nov 2017 20:50:43 +0000. Up 36.46 seconds.
Err:1 http://deb.debian.org/debian stretch InRelease
  Temporary failure resolving 'deb.debian.org'
Err:2 http://security.debian.org stretch/updates InRelease
  Temporary failure resolving 'security.debian.org'
Err:3 http://deb.debian.org/debian stretch-updates InRelease
  Temporary failure resolving 'deb.debian.org'
Reading package lists...
W: Failed to fetch http://deb.debian.org/debian/dists/stretch/InRelease  Temporary failure resolving 'deb.debian.org'
W: Failed to fetch http://security.debian.org/dists/stretch/updates/InRelease  Temporary failure resolving 'security.debian.org'
W: Failed to fetch http://deb.debian.org/debian/dists/stretch-updates/InRelease  Temporary failure resolving 'deb.debian.org'
W: Some index files failed to download. They have been ignored, or old ones used instead.

Logs from this cloud-init:

#cloud-config
# vim: syntax=yaml
#
hostname: rpi3-wifi
manage_etc_hosts: true

users:
  - name: pirate
    gecos: "Pirate"
    sudo: ALL=(ALL) NOPASSWD:ALL
    shell: /bin/bash
    groups: users,docker,video
    plain_text_passwd: hypriot
    lock_passwd: false
    ssh_pwauth: true
    chpasswd: { expire: false }

locale: "en_US.UTF-8"
timezone: "America/Los_Angeles"

package_update: true
package_upgrade: true
package_reboot_if_required: true

packages:
  - ntp

write_files:
  - path: "/etc/docker/daemon.json"
    owner: "root:root"
    content: |
      {
        "labels": [ "os=linux", "arch=arm64" ],
        "experimental": true
      }
  - path: /etc/network/interfaces.d/wlan0
    content: |
      allow-hotplug wlan0
      iface wlan0 inet dhcp
      wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
      iface default inet dhcp

  - path: /etc/wpa_supplicant/wpa_supplicant.conf
    content: |
      ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
      update_config=1
      network={
        ssid="YOURS"
        psk=YOURS
        proto=RSN
        key_mgmt=WPA-PSK
        pairwise=CCMP
        auth_alg=OPEN
      }

runcmd:
  - ["systemctl","restart","avahi-daemon"]
  - ["ifup","wlan0"]
firecyberice commented 6 years ago

Do you have an idea how to solve this? Maybe pushing wifi configuration to upstream cloud-init because it is a default network setup task?

renevo commented 6 years ago

I think in the long term, that is ideal, in the short term, copy in chroot and then in network-config file it can be configured, default could be if empty and wpa_supplicant.conf exists on /boot, then setup the wlan0 interface inside a default network-config.

Just tossing out ideas.