diff --git a/README.md b/README.md index ee2ba0859f..dbab3b55cd 100644 --- a/README.md +++ b/README.md @@ -212,6 +212,10 @@ The following environment variables are supported: If set, use this directory path as the location of scripts to run when generating images. An absolute or relative path can be given for a location outside the pi-gen directory. + * `ENABLE_CLOUD_INIT` (Default: `1`) + + If set to `1`, cloud-init and netplan will be installed and configured. This will allow you to configure your Raspberry Pi using cloud-init configuration files. The cloud-init configuration files should be placed in the bootfs or by editing the files in `stage2/04-cloud-init/files`. Cloud-init will be configured to read them on first boot. + A simple example for building Raspberry Pi OS: ```bash diff --git a/build.sh b/build.sh index 4d55b5281e..736bfbb4e8 100755 --- a/build.sh +++ b/build.sh @@ -241,6 +241,8 @@ export QUILT_NO_DIFF_INDEX=1 export QUILT_NO_DIFF_TIMESTAMPS=1 export QUILT_REFRESH_ARGS="-p ab" +export ENABLE_CLOUD_INIT=${ENABLE_CLOUD_INIT:-1} + # shellcheck source=scripts/common source "${SCRIPT_DIR}/common" # shellcheck source=scripts/dependencies_check diff --git a/export-image/01-user-rename/01-run.sh b/export-image/01-user-rename/01-run.sh index aa5dd94102..5897e5b212 100755 --- a/export-image/01-user-rename/01-run.sh +++ b/export-image/01-user-rename/01-run.sh @@ -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 diff --git a/stage2/01-sys-tweaks/01-run.sh b/stage2/01-sys-tweaks/01-run.sh index 961daed748..81324d3b52 100755 --- a/stage2/01-sys-tweaks/01-run.sh +++ b/stage2/01-sys-tweaks/01-run.sh @@ -1,6 +1,9 @@ #!/bin/bash -e -install -m 755 files/resize2fs_once "${ROOTFS_DIR}/etc/init.d/" +if [ "${ENABLE_CLOUD_INIT}" != "1" ]; then + # if cloud-init is enabled, it will take care of resizing the rootfs + install -m 755 files/resize2fs_once "${ROOTFS_DIR}/etc/init.d/" +fi install -m 644 files/50raspi "${ROOTFS_DIR}/etc/apt/apt.conf.d/" @@ -37,10 +40,6 @@ if [ "${USE_QEMU}" = "1" ]; then systemctl disable resize2fs_once EOF echo "leaving QEMU mode" -else - on_chroot << EOF -systemctl enable resize2fs_once -EOF fi on_chroot <