From f45d6b07891d0a0f1e39d9148d041b82abbbe7b6 Mon Sep 17 00:00:00 2001 From: Jeremy Cline Date: Tue, 16 Jul 2024 11:55:29 -0400 Subject: [PATCH] Add an initial mkosi config This is still a work-in-progress. It still needs: - A stubbed out Wireserver and IMDS instance To try it out as-is, you can build and then boot the image with: $ mkosi -d fedora $ sudo mkosi boot The version of azure-init in target/debug/ will be run as part of the image startup. You can inspect the result with "systemctl status azure-init". Run "systemctl poweroff" to leave the environment. This needs to be done in an Azure VM since it relies on talking to a real Wireserver and IMDS. Refer to mkosi docs[0] for installation options [0] https://github.com/systemd/mkosi?tab=readme-ov-file#installation --- .gitignore | 4 ++++ mkosi.conf | 43 +++++++++++++++++++++++++++++++++++++ mkosi.conf.d/10-debian.conf | 14 ++++++++++++ mkosi.conf.d/10-fedora.conf | 11 ++++++++++ mkosi.postinst.chroot | 24 +++++++++++++++++++++ 5 files changed, 96 insertions(+) create mode 100644 mkosi.conf create mode 100644 mkosi.conf.d/10-debian.conf create mode 100644 mkosi.conf.d/10-fedora.conf create mode 100755 mkosi.postinst.chroot diff --git a/.gitignore b/.gitignore index 5635d235..f47553b3 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,7 @@ Cargo.lock # .tgz Files are used for creating the image and are auto generated by the script azure-init.tgz + +# Don't check in local tweaks to the mkosi configuration +mkosi.local.conf +.mkosi/ diff --git a/mkosi.conf b/mkosi.conf new file mode 100644 index 00000000..5c6d9c86 --- /dev/null +++ b/mkosi.conf @@ -0,0 +1,43 @@ +# A basic configuration to test azure-init +# +# Currently, this only works when used from an Azure VM since it relies on the +# Azure-provided IMDS and Wireserver instances. In the future we can provide stubs +# so it's easy to test locally or in GitHub actions. We can also add configurations +# for additional distributions. +# +# To use this: +# - Install mkosi +# - Run `mkosi -d fedora` or `mkosi -d debian` +# - Run `sudo mkosi -d fedora boot` +# +# The repository is available under /work +[Output] +BuildDirectory=.mkosi/builddir +CacheDirectory=.mkosi/cache +Format=directory + +[Content] +Autologin=yes + +Packages= + curl + gdb + sudo + systemd + util-linux + +[Host] +# Build an image with `genisoimage -udf -o target/image.iso ovf` where ovf is a +# directory with a valid `ovf-env.xml` file in it. Then uncomment below to add +# the ISO as a CD-ROM in the virtual machine. +# +# This only works with a bootable image. +#QemuArgs=-cdrom target/image.iso + +# Boot to a temporary snapshot of the image - changes won't be persisted to the +# image. +Ephemeral=true +# Perform an incremental rebuild of the image +Incremental=true +# Make the source available at runtime +RuntimeBuildSources=yes diff --git a/mkosi.conf.d/10-debian.conf b/mkosi.conf.d/10-debian.conf new file mode 100644 index 00000000..68d8e40b --- /dev/null +++ b/mkosi.conf.d/10-debian.conf @@ -0,0 +1,14 @@ +[Match] +Distribution=|debian + +[Output] +OutputDirectory=.mkosi/debian-output + +[Content] +Packages= + apt + dbus-broker + dbus-user-session + openssh-client + openssh-server + passwd diff --git a/mkosi.conf.d/10-fedora.conf b/mkosi.conf.d/10-fedora.conf new file mode 100644 index 00000000..6e861bb0 --- /dev/null +++ b/mkosi.conf.d/10-fedora.conf @@ -0,0 +1,11 @@ +[Match] +Distribution=|fedora + +[Output] +OutputDirectory=.mkosi/fedora-output + +[Content] +Packages= + dnf + openssh + shadow-utils diff --git a/mkosi.postinst.chroot b/mkosi.postinst.chroot new file mode 100755 index 00000000..8f90c3b5 --- /dev/null +++ b/mkosi.postinst.chroot @@ -0,0 +1,24 @@ +#!/bin/bash +set -e + +SUDO_GROUP=$(grep -oP "^%\K\w+" /etc/sudoers) + +cat >/etc/systemd/system/azure-init.service </usr/lib/systemd/system-preset/1-azure-init.preset <