Skip to content

eBPF-based security platform

infra: add a VM to try shirudo on macOS

Andrea Lattuada731e7434dc5c
diff --git a/Documentation/start/faq.rst b/Documentation/start/faq.rst
index 6534e01a..ac73b7bd 100644
--- a/Documentation/start/faq.rst
+++ b/Documentation/start/faq.rst
@@ -114,6 +114,13 @@ x86-64, arm64 and riscv64, at different stages: CI tests x86-64, the
test VM also runs on arm64, and no riscv64 target has booted yet.
:doc:`/contribute/arch-support` compares the three.
+Can I try shirudo on macOS?
+---------------------------
+
+Not natively: shirudo is Linux only. On an Apple M3 or later with macOS
+15 or later, :doc:`/start/quickstart-macos` runs the quickstart in a
+Lima VM, with the test VM nested inside it.
+
How much does shirudo cost on a target, and how far does it scale?
------------------------------------------------------------------
diff --git a/Documentation/start/index.rst b/Documentation/start/index.rst
index 54b10100..d1c4af08 100644
--- a/Documentation/start/index.rst
+++ b/Documentation/start/index.rst
@@ -21,5 +21,6 @@ attesting a target.
who-is-shirudo-for
how-it-works
install
+ quickstart-macos
guides/index
faq
diff --git a/Documentation/start/quickstart-macos.rst b/Documentation/start/quickstart-macos.rst
new file mode 100644
index 00000000..dc743f67
--- /dev/null
+++ b/Documentation/start/quickstart-macos.rst
@@ -0,0 +1,117 @@
+..
+ SPDX-License-Identifier: BSD-2-Clause
+ Copyright (c) 2026 Authors of shirudo
+
+:page-type: How-to
+:audience: First-time users
+
+Run the quickstart on macOS
+===========================
+
+shirudo builds and runs on Linux only, and its test VM needs KVM. On a
+Mac, a Lima VM takes the place of the Linux host the
+:doc:`/start/quickstart` asks for: it is the operator host, and the test
+VM, the target, runs inside it with nested virtualization.
+:src:`infra/lima/shirudo.yaml` sets that VM up.
+
+.. list-table::
+ :header-rows: 1
+ :widths: 30 70
+
+ * - Where
+ - What runs there
+ * - The Mac
+ - ``limactl``, and the checkout you start the VM from.
+ * - Lima VM, as the operator
+ - Ubuntu 26.04 on arm64 with clang and LLVM 23 and every package the
+ quickstart lists. It builds in your checkout, which it shares
+ with the Mac.
+ * - Test VM, as the target
+ - The bpf-next kernel and the runtime image, with a software TPM
+ (``swtpm``) inside the Lima VM. The Mac's own hardware takes no
+ part.
+
+Before you begin
+----------------
+
+- An Apple M3 or later running macOS 15 or later. Earlier Macs, Intel
+ ones included, offer no nested virtualization, and the test VM does not
+ boot without it.
+- Lima 2.2 or later (``limactl --version``), for instance from Homebrew
+ (``brew install lima``).
+- About 100 GiB of free disk and 8 GiB of memory for the VM.
+- A checkout of shirudo on the Mac.
+
+Create the VM
+-------------
+
+1. In the root of your checkout, create and start the VM. ``checkout``
+ names the checkout, which the VM shares at the same path:
+
+ .. code-block:: console
+
+ $ limactl start --name=shirudo-dev --param checkout="$PWD" infra/lima/shirudo.yaml
+
+ A git worktree keeps its repository outside the checkout, and the
+ build asks git which files to copy into its container. Share the
+ repository too:
+
+ .. code-block:: console
+
+ $ limactl start --name=shirudo-dev --param checkout="$PWD" \
+ --mount="$(git rev-parse --path-format=absolute --git-common-dir)" \
+ infra/lima/shirudo.yaml
+
+ The VM takes 8 GiB of memory and Lima's default of at most 4 CPUs.
+ More CPUs shorten the kernel build; add ``--cpus=<count>`` to the
+ command to give more.
+
+2. From your checkout, open a shell in the VM:
+
+ .. code-block:: console
+
+ $ limactl shell shirudo-dev
+
+ The shell opens in your checkout. An edit on the Mac shows up in the
+ VM at once, and the build writes its output, ``build/`` and
+ ``artifacts/`` among it, into the checkout. ``build/test-vm`` is a
+ link to the VM's own disk: QEMU and swtpm need Unix sockets, which
+ the shared checkout does not carry.
+
+3. Check that the VM can run the test VM. ``/dev/kvm`` must be readable
+ and writable, and the locked-memory limit must be ``unlimited``:
+
+ .. code-block:: console
+
+ operator$ test -r /dev/kvm && test -w /dev/kvm && echo kvm ok
+ kvm ok
+ operator$ ulimit -l
+ unlimited
+
+Continue with the quickstart
+----------------------------
+
+From here, follow the :doc:`/start/quickstart` from its section "Build a
+target kernel" in the VM shell. Every
+``operator$`` command runs in the Lima VM. The quick guides and
+:doc:`/contribute/code/develop-locally` work the same way; the VM has
+Docker for the registry and the collector of the latter.
+
+Delete the VM
+-------------
+
+When you are done, delete the VM and its disk from the Mac:
+
+.. code-block:: console
+
+ $ limactl delete --force shirudo-dev
+
+Troubleshooting
+---------------
+
+``limactl start`` fails with ``field `mounts[0].location` must be an absolute path``
+ The command did not pass ``--param checkout=<path>``.
+
+``limactl start`` fails on nested virtualization or on the probe for nested KVM
+ The Mac does not offer nested virtualization: it is older than an M3
+ or runs a macOS before 15.
diff --git a/Documentation/start/quickstart.rst b/Documentation/start/quickstart.rst
index 2b77d285..1bd31e94 100644
--- a/Documentation/start/quickstart.rst
+++ b/Documentation/start/quickstart.rst
@@ -20,7 +20,8 @@ Before you begin
----------------
- A Linux host on x86-64 or arm64 with KVM. ``/dev/kvm`` must be readable
- and writable.
+ and writable. On a Mac, :doc:`/start/quickstart-macos` sets up such
+ a host in a Lima VM.
- A locked-memory limit of ``unlimited`` (``ulimit -l``): the shirudo
binaries lock their memory and refuse to run without it. Root is not
needed; the test VM builds its initrd with dracut as you, without
diff --git a/infra/lima/shirudo.yaml b/infra/lima/shirudo.yaml
new file mode 100644
index 00000000..663297ce
--- /dev/null
+++ b/infra/lima/shirudo.yaml
@@ -0,0 +1,118 @@
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# A Lima VM on an Apple M3 or later Mac that plays the operator host of
+# Documentation/start/quickstart.rst, with nested KVM for the test VM.
+#
+# limactl start --name=shirudo-dev --param checkout="$PWD" infra/lima/shirudo.yaml
+
+minimumLimaVersion: 2.2.0
+
+base:
+- template:_images/ubuntu-26.04
+
+vmType: vz
+arch: aarch64
+nestedVirtualization: true
+memory: 8GiB
+disk: 100GiB
+
+param:
+ checkout: ""
+
+# The checkout is shared at the path it has on the Mac, so that limactl
+# shell opens in it and the build writes there.
+mounts:
+- location: "{{.Param.checkout}}"
+ writable: true
+
+containerd:
+ system: false
+ user: false
+
+provision:
+# A group added during provisioning does not reach the shells Lima has
+# already opened, so the socket is handed to the user instead.
+- mode: yq
+ path: /etc/systemd/system/docker.socket.d/override.conf
+ format: ini
+ expression: .Socket.SocketUser="{{.User}}"
+- mode: system
+ script: |
+ #!/bin/bash
+ set -eux -o pipefail
+ # The kernel build and the test VM's images use several GiB under /tmp,
+ # which Ubuntu 26.04 mounts as a tmpfs sized from the VM's memory.
+ if [ "$(findmnt -no FSTYPE /tmp)" = tmpfs ]; then
+ systemctl mask tmp.mount
+ umount -l /tmp
+ chmod 1777 /tmp
+ fi
+ printf '* - memlock unlimited\n' >/etc/security/limits.d/90-shirudo-memlock.conf
+ mkdir -p /etc/systemd/system.conf.d /etc/systemd/user.conf.d
+ printf '[Manager]\nDefaultLimitMEMLOCK=infinity\n' |
+ tee /etc/systemd/system.conf.d/90-shirudo-memlock.conf \
+ /etc/systemd/user.conf.d/90-shirudo-memlock.conf >/dev/null
+ printf 'KERNEL=="kvm", OWNER="{{.User}}", MODE="0660"\n' \
+ >/etc/udev/rules.d/90-shirudo-kvm.rules
+ udevadm control --reload
+ udevadm trigger --name-match=kvm
+ export DEBIAN_FRONTEND=noninteractive
+ apt-get update
+ apt-get install -y --no-install-recommends \
+ build-essential pkg-config python3 git curl ca-certificates gpg jq \
+ openssl libssl-dev libcurl4-openssl-dev libelf-dev libluajit-5.1-dev \
+ libtpms-dev libtss2-dev zlib1g-dev libzstd-dev \
+ autoconf autoconf-archive automake libtool libltdl-dev \
+ bc bison flex cpio debhelper dpkg-dev fakeroot kmod libdw-dev \
+ libncurses-dev pahole rsync xz-utils zstd \
+ qemu-system-arm qemu-utils swtpm swtpm-tools cloud-image-utils \
+ libguestfs-tools dracut-core cryptsetup-bin e2fsprogs file \
+ openssh-client iproute2 isc-dhcp-client docker.io
+- mode: system
+ script: |
+ #!/bin/bash
+ set -eux -o pipefail
+ sh "{{.Param.checkout}}/.github/scripts/install-clang.sh"
+ sh "{{.Param.checkout}}/.github/scripts/install-static-libcrypto-deps.sh"
+# The test VMs' TPM and console sockets cannot live on the shared checkout,
+# and Ubuntu's AppArmor profile lets swtpm write only under the home
+# directory, so build/test-vm points there.
+- mode: user
+ script: |
+ #!/bin/bash
+ set -eux -o pipefail
+ mkdir -p ~/test-vm "{{.Param.checkout}}/build"
+ if [ ! -e "{{.Param.checkout}}/build/test-vm" ]; then
+ ln -s ~/test-vm "{{.Param.checkout}}/build/test-vm"
+ fi
+
+probes:
+- description: nested KVM
+ script: |
+ #!/bin/bash
+ set -eux -o pipefail
+ test -c /dev/kvm
+ hint: |
+ /dev/kvm is missing. The test VM needs nested virtualization, which
+ Lima offers on an Apple M3 or later running macOS 15 or later.
+- description: clang 23
+ script: |
+ #!/bin/bash
+ set -eux -o pipefail
+ if ! timeout 1800s bash -c "until test -x /usr/bin/clang; do sleep 5; done"; then
+ echo >&2 "clang 23 is not installed yet"
+ exit 1
+ fi
+ hint: See /var/log/cloud-init-output.log in the guest.
+
+message: |
+ Build and boot the test target as Documentation/start/quickstart.rst
+ describes, in your checkout, which limactl shell opens in when you run
+ it from there:
+ ------
+ limactl shell {{.Name}}
+ make -C testing kernel
+ make && make shirudo-build
+ make -C testing vm VM_NAME=quickstart
+ ------