Skip to content

Commit f45d6b0

Browse files
committed
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
1 parent 3ac3f41 commit f45d6b0

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ Cargo.lock
1515

1616
# .tgz Files are used for creating the image and are auto generated by the script
1717
azure-init.tgz
18+
19+
# Don't check in local tweaks to the mkosi configuration
20+
mkosi.local.conf
21+
.mkosi/

mkosi.conf

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# A basic configuration to test azure-init
2+
#
3+
# Currently, this only works when used from an Azure VM since it relies on the
4+
# Azure-provided IMDS and Wireserver instances. In the future we can provide stubs
5+
# so it's easy to test locally or in GitHub actions. We can also add configurations
6+
# for additional distributions.
7+
#
8+
# To use this:
9+
# - Install mkosi
10+
# - Run `mkosi -d fedora` or `mkosi -d debian`
11+
# - Run `sudo mkosi -d fedora boot`
12+
#
13+
# The repository is available under /work
14+
[Output]
15+
BuildDirectory=.mkosi/builddir
16+
CacheDirectory=.mkosi/cache
17+
Format=directory
18+
19+
[Content]
20+
Autologin=yes
21+
22+
Packages=
23+
curl
24+
gdb
25+
sudo
26+
systemd
27+
util-linux
28+
29+
[Host]
30+
# Build an image with `genisoimage -udf -o target/image.iso ovf` where ovf is a
31+
# directory with a valid `ovf-env.xml` file in it. Then uncomment below to add
32+
# the ISO as a CD-ROM in the virtual machine.
33+
#
34+
# This only works with a bootable image.
35+
#QemuArgs=-cdrom target/image.iso
36+
37+
# Boot to a temporary snapshot of the image - changes won't be persisted to the
38+
# image.
39+
Ephemeral=true
40+
# Perform an incremental rebuild of the image
41+
Incremental=true
42+
# Make the source available at runtime
43+
RuntimeBuildSources=yes

mkosi.conf.d/10-debian.conf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[Match]
2+
Distribution=|debian
3+
4+
[Output]
5+
OutputDirectory=.mkosi/debian-output
6+
7+
[Content]
8+
Packages=
9+
apt
10+
dbus-broker
11+
dbus-user-session
12+
openssh-client
13+
openssh-server
14+
passwd

mkosi.conf.d/10-fedora.conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[Match]
2+
Distribution=|fedora
3+
4+
[Output]
5+
OutputDirectory=.mkosi/fedora-output
6+
7+
[Content]
8+
Packages=
9+
dnf
10+
openssh
11+
shadow-utils

mkosi.postinst.chroot

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
set -e
3+
4+
SUDO_GROUP=$(grep -oP "^%\K\w+" /etc/sudoers)
5+
6+
cat >/etc/systemd/system/azure-init.service <<EOF
7+
[Unit]
8+
Description=azure-init
9+
After=network-online.target
10+
Wants=network-online.target
11+
12+
[Service]
13+
Type=oneshot
14+
Environment="AZURE_INIT_LOG=debug"
15+
Environment="AZURE_INIT_USER_GROUPS=${SUDO_GROUP}"
16+
ExecStart=/work/src/target/debug/azure-init
17+
18+
[Install]
19+
WantedBy=default.target
20+
EOF
21+
22+
cat >/usr/lib/systemd/system-preset/1-azure-init.preset <<EOF
23+
enable azure-init.service
24+
EOF

0 commit comments

Comments
 (0)