Develop locally#
This page sets up both roles on one machine, so that you can change
shirudo and see the result end to end. Your host is the operator: it
runs shirudo and shirudo-build from your checkout, a local OCI
registry and a local OpenTelemetry Collector. The test VM is the target:
it boots from your checkout the way a production target boots. You then
take one package through its whole life: write it, publish it, install
it, watch its data arrive in the collector, update it and remove it. The
last section shows how to rebuild after a change to shirudo itself.
The plain HTTP registry and collector of this page are the shortest way
to see a package arrive; Run a local development stack runs the TLS registry,
collector and ClickHouse the end-to-end tests use instead.
Where |
What runs there |
|---|---|
Host, as the operator |
|
Test VM, as the target |
The runtime image built from the checkout. It reaches the host
as |
Before you begin#
A checkout that builds, as Work from a checkout describes.
The test VM’s prerequisites and root on the host, as Quickstart lists them. Run every host command on this page as root, in the root of your checkout.
Docker, for the registry and the collector.
Two terminals on the host, one of them for the collector’s output.
Set up the operator shell#
Build
shirudoand the helper:operator$ make operator$ make shirudo-build
Put both on the
PATHof this shell, and name the helper:operator$ export PATH="$PWD:$PWD/tools/shirudo-build:$PATH" operator$ export SHIRUDO_BUILD="$PWD/tools/shirudo-build/shirudo-build"
Make a directory for your work. Git ignores
build/, and the test VM sees it as/workspace/shirudo/build/dev:operator$ DEV=$PWD/build/dev operator$ mkdir -p "$DEV"
Start the registry and the collector#
Run a registry on the host’s loopback interface:
operator$ docker run -d --name shirudo-registry -p 127.0.0.1:5000:5000 docker.io/library/registry:3
Write
build/dev/otelcol.yaml, a collector configuration that prints every record it receives:receivers: otlp: protocols: http: endpoint: 0.0.0.0:4318 exporters: debug: verbosity: detailed service: pipelines: logs: receivers: [otlp] exporters: [debug] metrics: receivers: [otlp] exporters: [debug]
Run the collector on the host’s loopback interface:
operator$ docker run -d --name shirudo-otelcol -p 127.0.0.1:4318:4318 -v "$DEV/otelcol.yaml:/etc/otelcol-contrib/config.yaml:ro" docker.io/otel/opentelemetry-collector-contrib:0.164.0
In the second terminal, follow what the collector receives:
operator$ docker logs -f shirudo-otelcol
Both containers speak plain HTTP, which is safe only on your own host. A production target speaks HTTPS with TLS 1.3 and a hybrid ML-KEM key exchange, see Monitor and export telemetry.
Boot the target#
Boot a test VM named
devwithout the local-stack config:operator$ make -C testing vm VM_NAME=dev LOCAL_STACK=0
The first run builds the kernel, the disk image and the bundle, which takes a while. Run and write tests describes the test VM. Without
LOCAL_STACK=0the VM activates theconfig-local-stackimage, which points the export and the upatch tree at the TLS stack of Run a local development stack, not at the registry and collector of this page, and the next section would copy that config.Name the bundle’s signing key in the operator shell:
operator$ KEYS=/tmp/shirudo-test-vm-private-$(id -u)/operator-keys/keys
The test VM trusts this key for upatches and config images. The bundle generates a new one every time it is rebuilt.
Open a root shell on the target:
operator$ make -C testing vm-ssh VM_NAME=dev
Make
shirudoname the trusted binary in this shell:target# alias shirudo=shirudo-runtime
shirudo-runtimeruns the binary on the runtime image, the only one the target lets read and change shirudo’s state, see Run shirudo on the target.
Connect the target to the registry and the collector#
A target reads its repositories and its export destination from the signed config image, not from files on its root file system (see Deliver packages). Build a config that adds both, starting from the config the target runs, and activate it.
On the target, copy the running config into the VM’s result share:
target# mkdir /mnt/shirudo-out/config-root target# cp -a /run/shirudo/config/etc /run/shirudo/config/keys /mnt/shirudo-out/config-root/
The host sees the share as
build/test-vm/vms/dev/result/.On the host, take the copy as the source of the new config:
operator$ cp -a build/test-vm/vms/dev/result/config-root "$DEV/config-root"
Send the map exports and keepalives to the collector:
operator$ printf '%s\n' 'map_export.otel_endpoint = http://10.0.2.2:4318' 'map_export.otel_insecure = true' >> "$DEV/config-root/etc/shirudo/shirudo.conf"
map_export.otel_insecureallows cleartext OTLP to a host other than the target itself.Register the registry as the repository
dev, with the certificate whose key signs its index:operator$ mkdir -p "$DEV/config-root/etc/shirudo/bpm/registries.d" "$DEV/config-root/etc/shirudo/bpm/keys" operator$ printf '%s\n' 'endpoint = oci://10.0.2.2:5000' 'index_repository = dev/bpm-index' 'key_file = /etc/shirudo/bpm/keys/dev.der' > "$DEV/config-root/etc/shirudo/bpm/registries.d/dev.conf" operator$ cp "$KEYS/cert.der" "$DEV/config-root/etc/shirudo/bpm/keys/dev.der"
Build and sign the config image, and verify it:
operator$ tools/gen-image/shirudo-gen-image --source "$DEV/config-root" --output "$DEV/config-1" --keys-dir "$KEYS" --kind config --builder "$SHIRUDO_BUILD" bcca2bcd9661e77b094bd4197b335482a3a168ef693e2fc6706a37b62d0bcce9 operator$ shirudo image verify "$DEV/config-1" --cert "$KEYS/cert.der" bcca2bcd9661e77b094bd4197b335482a3a168ef693e2fc6706a37b62d0bcce9
Both commands print the config’s root hash.
On the target, activate the config:
target# shirudo image update /workspace/shirudo/build/dev/config-1 target# shirudo image status Config root hash: bcca2bcd9661e77b094bd4197b335482a3a168ef693e2fc6706a37b62d0bcce9 PCR: 14 Sequence: 2 TPM reset count: 1 Restart count: 0 Pending: no Consistent: yes target# shirudo bpm config register list Registered sources: dev
Config root hashis the hash the host printed,PendingisnoandConsistentisyes.Let the target’s package commands and services reach the registry over plain HTTP:
target# mkdir -p /etc/shirudo/bpm target# echo BPM_OCI_SCHEME=http > /etc/shirudo/bpm/environment target# export BPM_OCI_SCHEME=http
The services read
/etc/shirudo/bpm/environment. Your shell needs the variable as well.Check the collector’s terminal. Every minute, the target’s keepalive timer sends a record with
EventName: shirudo.keepalive.
Write a package#
The package exec-count counts program executions by command name. A
Lua decoder turns the map into the record the target exports, the same
way a real upatch’s data reaches a collector.
Make the package directory, with links to the checkout’s headers:
operator$ mkdir -p "$DEV/exec-count/decoders" operator$ ln -s "$PWD/vendor" "$DEV/exec-count/vendor" operator$ ln -s "$PWD/bpf" "$DEV/exec-count/bpf"
shirudo-buildcompiles in the package directory. It takes the libbpf headers andvmlinux.hfromvendor/anddecoder.hfrombpf/lib/. An installed operator package brings its own copies and needs no links.Write
build/dev/exec-count/exec-count.bpf.c:// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause #include "vmlinux.h" #include <bpf/bpf_helpers.h> #include <bpf/bpf_tracing.h> #include "decoder.h" char _license[] SEC("license") = "Dual BSD/GPL"; struct { __uint(type, BPF_MAP_TYPE_HASH); __uint(max_entries, 1024); __type(key, char[16]); __type(value, __u64); } execs SEC(".maps"); const struct decoder_manifest execs_decoder SEC(".rodata") = { .magic = DECODER_MANIFEST_MAGIC, .version = UPATCH_DECODER_VERSION, .language = UPATCH_DECODER_LANG_LUA, .api_version = 1, .input_format = UPATCH_DECODER_INPUT_MAP_V1, .export_signal = UPATCH_DECODER_EXPORT_LOG, .upatch = "exec-count", .map = "execs", .source = "decoders/execs.lua", .entrypoint = "decode", }; SEC("tp_btf/sched_process_exec") int BPF_PROG(count_exec, struct task_struct *p, pid_t old_pid, struct linux_binprm *bprm) { char comm[16] = {}; __u64 zero = 0, *n; bpf_get_current_comm(comm, sizeof(comm)); n = bpf_map_lookup_elem(&execs, comm); if (!n) { bpf_map_update_elem(&execs, comm, &zero, BPF_NOEXIST); n = bpf_map_lookup_elem(&execs, comm); } if (n) __sync_fetch_and_add(n, 1); return 0; }
The program runs at every successful
execve(2)and adds one to the entry of the new command’s name in the hash mapexecs. The manifest in.rodatanames the Lua decoder for the map and the signal it produces, a log record. Write a Lua decoder explains each field. A upatch that keeps records rather than counters keeps them in an arena with a serializer, see Maps, arenas and serializers.Write
build/dev/exec-count/decoders/execs.lua:-- SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause local function command(hex) local name = {} for i = 1, #hex - 1, 2 do local byte = tonumber(hex:sub(i, i + 1), 16) if byte == 0 then break end name[#name + 1] = string.char(byte) end return table.concat(name) end function decode(input) local execs = {} for _, entry in ipairs(input.data.entries) do execs[#execs + 1] = { command = command(entry.key_hex), count = tonumber(shirudo.hex_u64(entry.value_hex, 0)), } end table.sort(execs, function(a, b) return a.count > b.count end) return { execs = execs } end
The target calls
decodewith a snapshot of the map, each entry’s key and value in hex. It returns the counts by name, which become the body of the log record.Write
build/dev/exec-count/Beefile:[package] name = "exec-count" description = "Counts program executions by command name" license = "GPL-2.0 OR BSD-2-Clause" [[upatches]] source = "exec-count.bpf.c"
Write
build/dev/exec-count/README.md, whichshirudo bpm infoprints for whoever inspects the package:# exec-count Counts program executions by command name. A Lua decoder exports the counts as the body of one OTLP log record per snapshot of the execs map.
Build and publish it#
Build version 1.0.0:
operator$ (cd "$DEV" && shirudo bpm build exec-count --version 1.0.0 --keys-dir "$KEYS") wrote /tmp/shirudo-bpm-build.<random>/0.upatch (insns=1664 sig=4853 data=5104 sections=3 maps=2 progs=1 decoders=1 name=exec-count) wrote /tmp/shirudo-bpm-build.<random>/0.unload.upatch (insns=1320 sig=4853 data=2808 sections=2 maps=1 progs=1 decoders=0 name=exec-count UNLOAD) <checkout>/build/dev/exec-count-1.0.0.bee
<random>is the suffix of a temporary directory and<checkout>your checkout. The builder compiles and signs the upatch with its decoder (decoders=1), signs an unload directive for it and writesbuild/dev/exec-count-1.0.0.bee.Push it to the registry and add it to the registry’s signed index:
operator$ BPM_OCI_SCHEME=http shirudo bpm push "$DEV/exec-count-1.0.0.bee" oci://127.0.0.1:5000/dev/exec-count --keys-dir "$KEYS" --new-index oci://127.0.0.1:5000/dev/exec-count:1.0.0
--new-indexstarts the registry’s index with this first package; later pushes to the namespace leave it out.The index holds one package per version. A package built again under a version the index lists already is refused with
bpm push: the repository index already lists exec-count 1.0.0 with different content, and every build differs, since every signature does. Give every change a new version.
Install it#
On the target, fetch the repository’s index:
target# shirudo bpm repo update dev
The command prints nothing when it succeeds.
Install the package from the repository:
target# shirudo bpm install dev/exec-count upatch load: --no-precheck, pre-flight state check skipped upatch load: signed loader accepted, keyring 335804852, 208 instructions upatch load: loader ran, 2 maps and 1 programs upatch load: program 0 (raw_tracepoint) pinned at /run/shirudo/bpffs/upatches/exec-count/link upatch load: map 0 (execs) pinned at /run/shirudo/bpffs/upatches/exec-count/maps/execs upatch load: exec-count loaded, 1 programs, keyring 335804852 upatch load: exec-count measured, register 23d80b8e3a30de1d5a556616d9d3eb388bbdb4bbc97f4e9fa81311909a3437ca
The target checks the package against the signed index, requires its certificate to match the target’s, and loads the upatch. The kernel checks the signature, and the target measures the load.
List the installed packages and the loaded upatches:
target# shirudo bpm list Installed packages: NAME VERSION SOURCE exec-count 1.0.0 dev target# shirudo upatch list Archived upatches (/var/lib/shirudo/upatches): NAME LOADED TYPE KIND PAYLOAD exec-count yes load bpf 00357162c0dfd6dc..
Watch the data#
Run a few commands on the target:
target# date; uname -a; id
Check the collector’s terminal. Every five seconds, the target’s map-export timer reads the map, runs the decoder and sends a record:
LogRecord #0 ObservedTimestamp: 2026-10-29 23:29:10.608332126 +0000 UTC Timestamp: 2026-10-29 23:29:10.608332126 +0000 UTC SeverityText: INFO SeverityNumber: Info(9) EventName: shirudo.bpf.map.snapshot Body: Map({"execs":[{"command":"modprobe","count":19},{"command":"9","count":17},{"command":"shirudo-runtime","count":16},{"command":"shirudo","count":16},{"command":"date","count":8},{"command":"uname","count":7},...]}) Attributes: -> shirudo.upatch.name: Str(exec-count) -> shirudo.upatch.location: Str(tracing/btf_trace_sched_process_exec) -> shirudo.map.name: Str(execs) -> shirudo.map.type: Str(hash) -> shirudo.map.max_entries: Int(1024) -> shirudo.map.n_entries: Int(50) -> shirudo.map.n_cpus: Int(1) -> shirudo.map.serialized: Bool(false) -> shirudo.map.truncated: Bool(false)The body is what the decoder returned, shortened here. It counts every execution on the guest, the target’s own timers included, so your counts differ. The attributes name the upatch, its attach point and the map, see Map logs and metrics.
While you work on a decoder, run it by hand against the live map:
target# shirudo upatch map exec-count execs --json --peek {"execs":[{"command":"modprobe","count":16},{"command":"shirudo","count":11},{"command":"shirudo-runtime","count":11},{"command":"date","count":8},...]}
The command prints the decoder’s result as one JSON document, shortened here, or the decoder’s error.
--peekleaves a serializer-backed map undrained; a hash map is never drained.
Update it#
Change the decoder to report the total as well. Replace
decodeinbuild/dev/exec-count/decoders/execs.lua:function decode(input) local execs, total = {}, 0 for _, entry in ipairs(input.data.entries) do local count = tonumber(shirudo.hex_u64(entry.value_hex, 0)) execs[#execs + 1] = { command = command(entry.key_hex), count = count } total = total + count end table.sort(execs, function(a, b) return a.count > b.count end) return { total = total, execs = execs } end
Build and push version 1.1.0:
operator$ (cd "$DEV" && shirudo bpm build exec-count --version 1.1.0 --keys-dir "$KEYS") operator$ BPM_OCI_SCHEME=http shirudo bpm push "$DEV/exec-count-1.1.0.bee" oci://127.0.0.1:5000/dev/exec-count --keys-dir "$KEYS" oci://127.0.0.1:5000/dev/exec-count:1.1.0
On the target, fetch the index and upgrade:
target# shirudo bpm repo update dev target# shirudo bpm upgrade upatch unload: --no-precheck, pre-flight state check skipped upatch unload: signed loader accepted, keyring 335804852, 165 instructions upatch unload: exec-count carries the directive's payload upatch unload: exec-count measured, register 422dadf3d3e5b1abbc6a9257ccaabecc5259998ad2ace271b52c62a85e728602 upatch unload: exec-count detached and unpinned upatch load: --no-precheck, pre-flight state check skipped upatch load: signed loader accepted, keyring 335804852, 208 instructions upatch load: loader ran, 2 maps and 1 programs upatch load: program 0 (raw_tracepoint) pinned at /run/shirudo/bpffs/upatches/exec-count/link upatch load: map 0 (execs) pinned at /run/shirudo/bpffs/upatches/exec-count/maps/execs upatch load: exec-count loaded, 1 programs, keyring 335804852 upatch load: exec-count measured, register 5d01da4114c32805d9863fb76cf7d760c1d86a1839ef4d5f79b41685b833d46b target# shirudo bpm list Installed packages: NAME VERSION SOURCE exec-count 1.1.0 dev
upgradeunloads the old version with its signed unload directive and loads the new one, and restores the old one if the new one fails to load. The two commands act at once: from building the new version to running it on the target takes a few seconds. The target’s package timer does the same by itself about a minute after each of its runs, which is what a production target relies on;journalctl -u shirudo-bpm-repo-update.serviceon the target shows its runs.Check the collector’s terminal. The records now carry
total, and the counts start again from zero, since the new version has a new map.
Remove it#
Uninstall the package on the target:
target# shirudo bpm uninstall exec-count upatch unload: --no-precheck, pre-flight state check skipped upatch unload: signed loader accepted, keyring 335804852, 165 instructions upatch unload: exec-count carries the directive's payload upatch unload: exec-count measured, register 2bf2d8fda256c469544e6d33638bb23fc0801e650bba4068411a779c698ab131 upatch unload: exec-count detached and unpinned
The target runs the package’s signed unload directive, measures the unload and deletes the package.
shirudo bpm listandshirudo upatch listprintnone.Check the collector’s terminal. The map records stop, and the keepalives go on.
The registry keeps every version you pushed. bpm upgrade only
upgrades installed packages, so it does not bring the package back. To
start over with an empty registry, remove the container as Clean up
shows and start it again.
Change shirudo#
The host runs the operator commands from your checkout, so a change to them takes effect as soon as you rebuild. The target runs the runtime image of the bundle the VM booted with, so a change to anything the target runs takes a new bundle and a new VM.
After a change to an operator command,
shirudo-buildor the package tools, rebuild:operator$ make && make shirudo-build
After a change to the target side, such as a
builtin-*.ccommand the target runs,util/, the BPF programs underbpf/or the boot integration, replace the VM:operator$ make -C testing vm-clean VM_NAME=dev operator$ make -C testing vm VM_NAME=dev LOCAL_STACK=0
make -C testing vmrebuilds the bundle from your checkout and boots a new VM, which takes about two minutes once the kernel and the disk image exist. It refuses a name that still has state, hencevm-clean.shirudo statuson the target then prints a newVersion ID. The target accepts only the binary on its authenticated runtime image, so there is no faster way to run changed target code. The rebuilt bundle has a new signing key, so repeat this page from Boot the target with an empty registry: remove and startshirudo-registryagain, build a new config, and build and push your packages again.Test what you can on the host first. The unit tests and the operator tests run in seconds without a VM:
operator$ make -C testing unit operator$ make -C testing functional/<family> VM=0
Then run the target tests your change touches by hand in the VM, and the whole family for a verdict, as Run and write tests describes.
Clean up#
Stop the VM and remove its state:
operator$ make -C testing vm-clean VM_NAME=dev
Remove the containers:
operator$ docker rm -f shirudo-registry shirudo-otelcol
Next steps#
Write a Lua decoder for decoders and metrics
Maps, arenas and serializers for upatches that keep records
Deliver packages and Monitor and export telemetry for the production setup this page reproduces
Run and write tests to write and run tests