timebertt/pi-cloud-init

dhcpcd is still running.

geoff-coppertop opened this issue · 3 comments

Thanks for doing the work to get RaspiOS lite running with cloud-init! The 64-bit image is almost exactly what I need.

When trying to provision a unit with a static IP per your example I'm seeing the device get both a static IP and a dynamic one assigned, I saw this with ip address show. A little more digging shows that the dhcpcd service is still running and is why the second dynamic IP is being assigned. Locally I was able to stop this by running sudo systemctl stop dhcpcd and sudo systemctl mask dhcpcd to prevent the service from restarting, doing so forces network-config to be the sole source of configuration.

While I think you could add these commands in the user-data I think a more generalized answer would be good but I'm not quite sure where to add this in the scripts. I'd be happy to help test this further and will keep poking myself.

Hi @geoff-coppertop!
That's strange, I haven't encountered such an issue with dhcpd still running.
For reference, can you post your user-data and network-config?

You bet, here's network-config,

#cloud-config
# vim: syntax=yaml
#

# Set your hostname here, the manage_etc_hosts will update the hosts file entries as well
hostname: rpi-carbon-00
manage_etc_hosts: true
# don't write debian.org into apt mirrors
apt_preserve_sources_list: true

users:
- name: thomasga
  shell: /bin/bash
  sudo: ALL=(ALL) NOPASSWD:ALL
  groups: users,docker,adm,dialout,audio,plugdev,netdev,video
  lock_passwd: true
  ssh-authorized-keys:
  - ssh-rsa AAAAB3NzaC1yc...
  - ssh-rsa AAAAB3NzaC1yc...

package_update: true
package_upgrade: true

write_files:
  - content: |
      #!/bin/bash
      keys=$(wget -qO- https://github.com/geoff-coppertop.keys)
      echo "$keys" | while read -r key
      do
          if [ -f "/home/thomasga/.ssh/authorized_keys" ] && ! grep "$key" "/home/thomasga/.ssh/authorized_keys" &> /dev/null
          then
              echo "$key" >> "/home/thomasga/.ssh/authorized_keys"
          fi
      done
    path: /usr/bin/update-keys
    permissions: '0755'
  - content: "*/5 * * * * thomasga /usr/bin/update-keys\n"
    owner: root:root
    path: /etc/cron.d/update-keys
    permissions: '0644'

# These commands will be ran once on first boot only
runcmd:
# Pickup the hostname changes
- 'systemctl restart avahi-daemon'

And my network-config,

version: 2
ethernets:
  eth0:
    dhcp4: no
    dhcp6: no
    addresses:
      - 192.168.1.40/24
    gateway4: 192.168.1.1
    nameservers:
      search:
      - local
      addresses:
      - 1.1.1.1

For reference I'm using hypriot flash as a convenient method for mounting the boot partition of the image adding these two files and then upload it to the compute modules 3b+ with 32GB eMMC that I'm using for my cluster. I've gone over most of that script and can reason my way through it and since I see the effect of both configs I don't think that's the issue right now. If you look at one of your PIs with systemctl --type=service do you see the dhcpcd service running? I'm curious if it's potentially the package update/upgrade that I do that's causing the issue?

dhcpcd.service                                              loaded    active running dhcpcd on all interfaces  

When I run ip address show eth0 I see the following,

thomasga@rpi-carbon-00:~ $ ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b8:27:eb:9b:86:0f brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.40/24 brd 192.168.1.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 192.168.1.222/24 brd 192.168.1.255 scope global secondary dynamic noprefixroute eth0
       valid_lft 86382sec preferred_lft 75582sec
    inet6 fe80::ba27:ebff:fe9b:860f/64 scope link 
       valid_lft forever preferred_lft forever

I re-imaged the pi with package_update: false and package_upgrade: false and as expected that did not change the results of ip add show eth0.