Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3146f54994
|
||
|
|
eb8e4b440a
|
No files matched your search
@@ -1,4 +1,2 @@
|
|||||||
mkosi.output/
|
mkosi.output/
|
||||||
mkosi.key
|
mkosi.key
|
||||||
test.qcow2
|
|
||||||
vars.fd
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# mkosi container
|
||||||
|
#
|
||||||
|
# Builds and boots a test VM where the host has no systemd, such as a dev
|
||||||
|
# container (README.md). mkosi vm needs systemd to run qemu in a scope, so
|
||||||
|
# systemd runs as init here and mkosi runs through podman exec.
|
||||||
|
FROM registry.fedoraproject.org/fedora:45
|
||||||
|
RUN dnf install -y --setopt=install_weak_deps=False mkosi dbus-broker \
|
||||||
|
qemu-kvm-core edk2-ovmf /usr/bin/systemd-repart openssh-clients && \
|
||||||
|
dnf install -y --setopt=install_weak_deps=False $(mkosi dependencies) && \
|
||||||
|
dnf clean all
|
||||||
|
CMD ["/sbin/init"]
|
||||||
@@ -27,16 +27,21 @@ mkosi genkey # local test only, CI uses the SECUREBOOT_KEY secret
|
|||||||
mkosi build
|
mkosi build
|
||||||
```
|
```
|
||||||
|
|
||||||
`mkosi.output/` then holds the disk image (`agent_<version>.raw`) and the UKI and root partitions that make up an update. To boot it with Secure Boot (needs `qemu-kvm-core edk2-ovmf`):
|
`mkosi.output/` then holds the disk image (`agent_<version>.raw`) and the UKI and root partitions that make up an update.
|
||||||
|
|
||||||
|
To build and boot a test VM with Secure Boot (needs `qemu-kvm-core edk2-ovmf`):
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
qemu-img create -f qcow2 -F raw -b $PWD/mkosi.output/agent_<version>.raw test.qcow2 40G
|
mkosi -f vm
|
||||||
cp /usr/share/edk2/ovmf/OVMF_VARS.fd vars.fd
|
|
||||||
qemu-kvm -m 8G -cpu host -nographic -nic user,model=virtio-net-pci,hostfwd=tcp::2222-:22 -drive file=test.qcow2,if=virtio \
|
|
||||||
-machine q35,smm=on -global driver=cfi.pflash01,property=secure,value=on \
|
|
||||||
-drive if=pflash,format=raw,readonly=on,file=/usr/share/edk2/ovmf/OVMF_CODE.secboot.fd -drive if=pflash,format=raw,file=vars.fd \
|
|
||||||
-smbios type=11,value=io.systemd.credential:agent.password=test \
|
|
||||||
-smbios type=11,value=io.systemd.credential.binary:agent.ssh-key=$(base64 -w0 ~/.ssh/id_ed25519.pub)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The credentials answer the setup, so it boots straight to a login (root, password `test`) on the serial console. Ctrl-a x quits. Then `ssh -p 2222 claude@localhost`.
|
The `[Runtime]` section of `mkosi.conf` answers the setup, so it boots straight to a login (root, password `test`). Then `ssh -p 2222 claude@localhost` with your own key (`mkosi.credentials/agent.ssh-key`).
|
||||||
|
|
||||||
|
`mkosi vm` needs systemd on the host. Without it, such as in a dev container, run mkosi in a container with systemd ([Containerfile](Containerfile)):
|
||||||
|
|
||||||
|
```sh
|
||||||
|
podman build -t mkosi-vm .
|
||||||
|
podman run -d --name mkosi --systemd=always --privileged --device /dev/kvm -v .:/repo -v ~/.ssh:/root/.ssh:ro -w /repo mkosi-vm
|
||||||
|
podman exec -it mkosi mkosi -f vm
|
||||||
|
podman exec -it mkosi ssh -p 2222 claude@localhost # in another terminal
|
||||||
|
```
|
||||||
+14
@@ -138,3 +138,17 @@ RemoveFiles=
|
|||||||
SecureBoot=yes
|
SecureBoot=yes
|
||||||
SecureBootKey=mkosi.key
|
SecureBootKey=mkosi.key
|
||||||
SecureBootCertificate=mkosi.crt
|
SecureBootCertificate=mkosi.crt
|
||||||
|
|
||||||
|
[Runtime]
|
||||||
|
# For testing with mkosi vm. It does the setup itself (the agent.* credentials,
|
||||||
|
# mkosi.extra/usr/libexec/agent-setup). Its console is hvc0, which the UKI
|
||||||
|
# doesn't use: with Secure Boot, systemd-stub ignores the console= mkosi
|
||||||
|
# passes. So the serial port joins that console, and replaces mkosi's network
|
||||||
|
# to forward ssh to port 2222. Ephemeral boots a copy, so test runs don't
|
||||||
|
# change the built image.
|
||||||
|
Ephemeral=yes
|
||||||
|
RAM=8G
|
||||||
|
RuntimeSize=40G
|
||||||
|
RuntimeNetwork=none
|
||||||
|
QemuArgs=-serial chardev:console -nic user,model=virtio-net-pci,hostfwd=tcp::2222-:22
|
||||||
|
Credentials=agent.password=test agent.hostname=agent-test mkosi.credentials/
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# SSH key for mkosi vm
|
||||||
|
#
|
||||||
|
# mkosi vm runs this and passes what it prints as the credential agent.ssh-key
|
||||||
|
# (mkosi.conf), so you can ssh into the test VM with your own keys.
|
||||||
|
cat ~/.ssh/*.pub 2>/dev/null || true
|
||||||
@@ -8,8 +8,8 @@
|
|||||||
# boot.
|
# boot.
|
||||||
#
|
#
|
||||||
# With the credential agent.password, it asks nothing and takes the answers
|
# With the credential agent.password, it asks nothing and takes the answers
|
||||||
# from the credentials agent.password, agent.hostname and agent.ssh-key, such
|
# from the credentials agent.password, agent.hostname and agent.ssh-key. mkosi
|
||||||
# as for a test VM (README.md).
|
# vm passes them (mkosi.conf).
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
cred() { cat "${CREDENTIALS_DIRECTORY:-/nonexistent}/agent.$1" 2>/dev/null; }
|
cred() { cat "${CREDENTIALS_DIRECTORY:-/nonexistent}/agent.$1" 2>/dev/null; }
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user