-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cloud-Init support #797
Draft
paulober
wants to merge
5
commits into
RPi-Distro:arm64
Choose a base branch
from
paulober:arm64
base: arm64
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Cloud-Init support #797
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,21 @@ | ||
#!/bin/bash -e | ||
|
||
if [[ "${DISABLE_FIRST_BOOT_USER_RENAME}" == "0" ]]; then | ||
# with cloud-init enabled this will throw an error | ||
# when run more than once, as the service will be deleted | ||
on_chroot <<- EOF | ||
SUDO_USER="${FIRST_USER_NAME}" rename-user -f -s | ||
EOF | ||
|
||
# delete userconfig service as cloud-init will take care of launching it | ||
rm -f "${ROOTFS_DIR}/lib/systemd/system/userconfig.service" | ||
else | ||
rm -f "${ROOTFS_DIR}/etc/xdg/autostart/piwiz.desktop" | ||
|
||
# if cloud-init enabled disable setup wizard launch completely | ||
if [[ "${ENABLE_CLOUD_INIT}" == "1" ]]; then | ||
on_chroot <<- EOF | ||
touch /var/lib/userconf-pi/deactivate | ||
EOF | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
python3-yaml | ||
netcat-openbsd | ||
netplan.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash -e | ||
|
||
if [ "${ENABLE_CLOUD_INIT}" != "1" ]; then | ||
log "Skipping cloud-init stage" | ||
exit 0 | ||
fi | ||
|
||
install -v -D -m 644 -t "${ROOTFS_DIR}/etc/cloud/cloud.cfg.d/" files/99_raspberry-pi.cfg | ||
|
||
# install meta-data file for NoCloud data-source to work | ||
install -v -m 755 files/meta-data "${ROOTFS_DIR}/boot/firmware/meta-data" | ||
install -v -m 755 files/user-data "${ROOTFS_DIR}/boot/firmware/user-data" | ||
install -v -m 755 files/network-config "${ROOTFS_DIR}/boot/firmware/network-config" | ||
|
||
# setup default netplan config which will instruct netplan to pass control over to network-manager | ||
# at boot time. This will make NetworkManager manage all devices and by default. | ||
# Any Ethernet device will come up with DHCP, once carrier is detected | ||
install -v -D -m 600 -t "${ROOTFS_DIR}/usr/lib/netplan/" files/00-network-manager-all.yaml | ||
|
||
# still does not solve the conflict, maybe some kind of race cond. | ||
# make sure config stage is run before userconfig service | ||
#sed -i '/^\[Unit\]/a Before=userconfig.service' "${ROOTFS_DIR}/lib/systemd/system/cloud-config.service" | ||
|
||
install -v -m 755 files/cloud-init-custom.deb "${ROOTFS_DIR}/tmp/cloud-init.deb" | ||
|
||
# remove cloud-init if already installed for rebuild support while working with custom deb | ||
on_chroot << EOF | ||
SUDO_USER="${FIRST_USER_NAME}" dpkg -i /tmp/cloud-init.deb || true | ||
SUDO_USER="${FIRST_USER_NAME}" apt-get install -f -y | ||
EOF | ||
|
||
rm -f "${ROOTFS_DIR}/tmp/cloud-init.deb" | ||
|
||
# userconfig service is deleted in export-image/01-user-rename stage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Cloud-init support for Raspberry Pi OS | ||
|
||
TODO: add reference to official documentation for the custom modules when merged | ||
|
||
- files/network-config is required because otherwise imager would fail to create the correct filesystem entry | ||
|
||
- files/user-data same reason and to include some example configurations | ||
|
||
- files/meta-data Cloud-init instance configuration | ||
|
||
- files/cloud-init-custom.deb A custom cloud-init build until included apt repositories | ||
|
||
- files/99_raspberry-pi.cfg Cloud-init datasource configuration | ||
|
||
- files/00-network-manager-all.yaml Example form netplan docs/ubuntu for handing over control from | ||
netplan to NetworkManager by default. | ||
|
||
Packages: | ||
- netplan is installed to provide for advanced options like "wifis" in the network-config v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
network: | ||
version: 2 | ||
renderer: NetworkManager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# configure cloud-init with NoCloud | ||
|
||
datasource_list: [ NoCloud, None ] | ||
datasource: | ||
NoCloud: | ||
fs_label: bootfs |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# This is the meta-data configuration file for cloud-init. Please refer to the | ||
# cloud-init documentation for more information: | ||
# | ||
# https://cloudinit.readthedocs.io/ | ||
|
||
# Set the datasource mode to "local". This ensures that user-data is acted upon | ||
# prior to bringing up the network (because everything about the datasource is | ||
# assumed to be local). If you wish to use an HTTP datasource instead, you can | ||
# change this to "net" or override it on the kernel cmdline (see README). | ||
dsmode: local | ||
|
||
# Specifies the "unique" identifier of the instance. Typically in cloud-init | ||
# this is generated by the owning cloud and is actually unique (to some | ||
# degree). Here our data-source is local, so this is just a fixed string. | ||
# Warning: changing this will cause cloud-init to assume it is running on a | ||
# "new" instance, and to go through first time setup again (the value is | ||
# compared to a cached copy). | ||
instance_id: rpios-image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# This file contains a netplan-compatible configuration which cloud-init will | ||
# apply on first-boot (note: it will *not* update the config after the first | ||
# boot). Please refer to the cloud-init documentation and the netplan reference | ||
# for full details: | ||
# | ||
# https://netplan.io/reference | ||
# https://cloudinit.readthedocs.io/en/latest/topics/network-config.html | ||
# https://cloudinit.readthedocs.io/en/latest/topics/network-config-format-v2.html | ||
# | ||
# Please note that the YAML format employed by this file is sensitive to | ||
# differences in whitespace; if you are editing this file in an editor (like | ||
# Notepad) which uses literal tabs, take care to only use spaces for | ||
# indentation. See the following link for more details: | ||
# | ||
# https://en.wikipedia.org/wiki/YAML | ||
# | ||
# Additionally, please be aware that if your boot sequence depends on active | ||
# networking (e.g. if your cloud-init configuration pulls packages or SSH | ||
# keys from the network), you *must* mark at least one interface as required | ||
# ("optional: false") below. Otherwise, particularly on faster boards, | ||
# cloud-init will start attempting to use the network before it is ready | ||
|
||
# Some additional examples are commented out below | ||
|
||
network: | ||
version: 2 | ||
|
||
ethernets: | ||
eth0: | ||
dhcp4: true | ||
optional: true | ||
|
||
# wifis: | ||
# wlan0: | ||
# dhcp4: true | ||
# optional: true | ||
# access-points: | ||
# myhomewifi: | ||
# password: "S3kr1t" | ||
# myworkwifi: | ||
# password: "correct battery horse staple" | ||
# workssid: | ||
# auth: | ||
# key-management: eap | ||
# method: peap | ||
# identity: "[email protected]" | ||
# password: "passw0rd" | ||
# ca-certificate: /etc/my_ca.pem | ||
|
||
# regulatory-domain: GB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#cloud-config | ||
|
||
# This is the user-data configuration file for cloud-init. By default this sets | ||
# up an initial user called "ubuntu" with password "ubuntu", which must be | ||
# changed at first login. However, many additional actions can be initiated on | ||
# first boot from this file. The cloud-init documentation has more details: | ||
# | ||
# https://cloudinit.readthedocs.io/ | ||
# | ||
# Please note that the YAML format employed by this file is sensitive to | ||
# differences in whitespace; if you are editing this file in an editor (like | ||
# Notepad) which uses literal tabs, take care to only use spaces for | ||
# indentation. See the following link for more details: | ||
# | ||
# https://en.wikipedia.org/wiki/YAML | ||
# | ||
# Some additional examples are provided in comments below the default | ||
# configuration. | ||
|
||
# disable_piwiz: fase | ||
|
||
# Setup default user | ||
# rpi_userconf: | ||
# password: my-hashed-passwd | ||
# user: myusername | ||
|
||
## Set the system's hostname. Please note that, unless you have a local DNS | ||
## setup where the hostname is derived from DHCP requests (as with dnsmasq), | ||
## setting the hostname here will not make the machine reachable by this name. | ||
## You may also wish to install avahi-daemon (see the "packages:" key below) | ||
## to make your machine reachable by the .local domain | ||
#hostname: raspberrypi | ||
|
||
## Set up the keyboard layout. See localectl(1), in particular the various | ||
## list-x11-* sub-commands, to determine the available models, layouts, | ||
## variants, and options | ||
#keyboard: | ||
# model: pc105 | ||
# layout: gb | ||
# variant: | ||
# options: ctrl:nocaps | ||
|
||
# Controls password authentication with the SSH daemon; the default here | ||
# prevents logging into SSH with a password. Changing this is a security risk | ||
# and you should at the very least ensure a different default password is | ||
# specified above | ||
ssh_pwauth: false | ||
|
||
## On first boot, use ssh-import-id to give the specific users SSH access to | ||
## the default user | ||
#ssh_import_id: | ||
#- lp:my_launchpad_username | ||
#- gh:my_github_username | ||
|
||
## Add users and groups to the system, and import keys with the ssh-import-id | ||
## utility | ||
#groups: | ||
#- robot: [robot] | ||
#- robotics: [robot] | ||
#- pi | ||
# | ||
#users: | ||
#- default | ||
#- name: robot | ||
# gecos: Mr. Robot | ||
# primary_group: robot | ||
# groups: users | ||
# ssh_import_id: foobar | ||
# lock_passwd: false | ||
# passwd: $5$hkui88$nvZgIle31cNpryjRfO9uArF7DYiBcWEnjqq7L1AQNN3 | ||
|
||
## Update apt database and upgrade packages on first boot | ||
#package_update: true | ||
#package_upgrade: true | ||
|
||
## Install additional packages on first boot | ||
#packages: | ||
#- avahi-daemon | ||
#- rng-tools | ||
#- python3-gpiozero | ||
#- [python3-serial, 3.5-1] | ||
|
||
## Write arbitrary files to the file-system (including binaries!) | ||
#write_files: | ||
#- path: /etc/default/console-setup | ||
# content: | | ||
# # Consult the console-setup(5) manual page. | ||
# ACTIVE_CONSOLES="/dev/tty[1-6]" | ||
# CHARMAP="UTF-8" | ||
# VIDEOMODE= | ||
# FONT="Lat15-Terminus18x10.psf.gz" | ||
# FONTFACE= | ||
# FONTSIZE= | ||
# CODESET="Lat15" | ||
# permissions: '0644' | ||
# owner: root:root | ||
#- encoding: gzip | ||
# path: /root/Makefile | ||
# content: !!binary | | ||
# H4sICF2DTWIAA01ha2VmaWxlAFNWCM8syVBILMjPyU/PTC1WKMlXiPB2dlFQNjSx5MpNteLi | ||
# dLDiSoRQxYl5KeWZyRkgXrSCkoqKRmaKgm6pppKCbmqhgoFCrIKamkK1QmpyRr6Ckn92YqWS | ||
# NdC80uQMBZhOa4VahZoaqIrwjMQSewXfxOxUhcwShcr80qLi1Jw0RSUuAIYfEJmVAAAA | ||
# owner: root:root | ||
# permissions: '0644' | ||
|
||
## Run arbitrary commands at rc.local like time | ||
#runcmd: | ||
#- [ ls, -l, / ] | ||
#- [ sh, -xc, "echo $(date) ': hello world!'" ] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't be relevant when we update the package in our repo, so this is just a general heads up. Instead of using
dpkg -i
and following it up withapt
, you could useapt-get install -y /tmp/cloud-init.deb
directly and that will resolve dependencies and install the relevant packages in one step. The trick is that apt-get assumes that you're giving it package names unless it detects that you're giving it a path. I'm guessing it's checking for the presence of a/
character, so if the file is in the current directory you'd use./file.deb
.You could probably even just put '/tmp/cloud-init.deb' in
02-packages
, but I haven't tried that, so I'm not sure.As is, using
|| true
means you ignore potential legitimate errors. Also, we normally nudge people towardsapt
rather thanapt-get
because it's more user friendly and handles some things automatically whichapt-get
doesn't, but in non-interactive scripts such as this one,apt-get
is still the way to go. In other words,apt-get
for scripting andapt
otherwise.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, thanks for explaining. I'll update this for the current state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tried it and when using
apt-get install -y /tmp/cloud-init.deb
I got a messageNote: using cloud-init instead of /tmp/cloud-init.deb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing the package was updated without bumping the version number? We normally add
+rpt1
to the version string to signify that it contains our patches.