From 1e6e7fb0b6c51999d2295c1c104bcfb1a79d7aab Mon Sep 17 00:00:00 2001 From: Moritz Sanft <58110325+msanft@users.noreply.github.com> Date: Tue, 19 Nov 2024 16:15:57 +0100 Subject: [PATCH] packages/boot-microvm: init This adds a little helper script to boot a Micro VM, as we build them for Kata bare-metal, via QEMU. --- packages/by-name/boot-microvm/package.nix | 36 +++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 packages/by-name/boot-microvm/package.nix diff --git a/packages/by-name/boot-microvm/package.nix b/packages/by-name/boot-microvm/package.nix new file mode 100644 index 000000000..416f82a26 --- /dev/null +++ b/packages/by-name/boot-microvm/package.nix @@ -0,0 +1,36 @@ +# Copyright 2024 Edgeless Systems GmbH +# SPDX-License-Identifier: AGPL-3.0-only + +{ + writeShellApplication, + qemu, + OVMF, +}: + +# Usage example: +# outPath=$(nix build .#kata.kata-image --print-out-paths); nix run .#boot-microvm -- "${outPath}/bzImage" "${outPath}/initrd" "${outPath}/image-podvm-gpu_1-rc1.raw" "$(nix eval --raw .#kata.kata-image.cmdline)" + +writeShellApplication { + name = "boot-microvm"; + runtimeInputs = [ qemu ]; + text = '' + if [ $# -ne 4 ]; then + echo "Usage: $0 "; + exit 1; + fi + + tmpFile=$(mktemp) + cp "$3" "$tmpFile" + + qemu-system-x86_64 \ + -enable-kvm \ + -m 3G \ + -nographic \ + -drive if=pflash,format=raw,readonly=on,file=${OVMF.firmware} \ + -drive if=pflash,format=raw,readonly=on,file=${OVMF.variables} \ + -kernel "$1" \ + -initrd "$2" \ + -append "$4" \ + -drive "if=virtio,format=raw,file=$tmpFile" + ''; +}