Skip to content

Commit 5c6aae1

Browse files
committed
ephemeral: Add guest journal streaming for debugging
Automatically stream the guest VM's systemd journal to the host for easier debugging of boot failures and systemd service issues. Assisted-By: Claude Code (Sonnet 4.5) Signed-off-by: Colin Walters <[email protected]>
1 parent bb81005 commit 5c6aae1

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

crates/kit/src/run_ephemeral.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,35 @@ WantedBy=local-fs.target
893893
let default_wantsdir = format!("{target_unitdir}/default.target.wants");
894894
fs::create_dir_all(&default_wantsdir)?;
895895

896+
// Create systemd unit to stream journal to virtio-serial device
897+
let journal_stream_unit = r#"[Unit]
898+
Description=Stream systemd journal to host via virtio-serial
899+
DefaultDependencies=no
900+
After=systemd-journald.service dev-virtio\x2dports-org.bcvk.journal.device
901+
Requires=systemd-journald.service dev-virtio\x2dports-org.bcvk.journal.device
902+
903+
[Service]
904+
Type=simple
905+
ExecStart=/usr/bin/journalctl -f -o short-precise --no-pager
906+
StandardOutput=file:/dev/virtio-ports/org.bcvk.journal
907+
StandardError=file:/dev/virtio-ports/org.bcvk.journal
908+
Restart=always
909+
RestartSec=1s
910+
911+
[Install]
912+
WantedBy=sysinit.target
913+
"#;
914+
let journal_unit_path = format!("{target_unitdir}/bcvk-journal-stream.service");
915+
tokio::fs::write(&journal_unit_path, journal_stream_unit).await?;
916+
debug!("Created journal streaming unit at {journal_unit_path}");
917+
918+
// Enable the journal streaming unit
919+
let sysinit_wantsdir = format!("{target_unitdir}/sysinit.target.wants");
920+
tokio::fs::create_dir_all(&sysinit_wantsdir).await?;
921+
let journal_wants_link = format!("{sysinit_wantsdir}/bcvk-journal-stream.service");
922+
tokio::fs::symlink("../bcvk-journal-stream.service", &journal_wants_link).await?;
923+
debug!("Enabled journal streaming unit in sysinit.target.wants");
924+
896925
match opts.common.execute.as_slice() {
897926
[] => {}
898927
elts => {
@@ -1095,6 +1124,10 @@ Options=
10951124
.set_kernel_cmdline(kernel_cmdline)
10961125
.set_console(opts.common.console);
10971126

1127+
// Add virtio-serial device for journal streaming
1128+
qemu_config.add_virtio_serial_out("org.bcvk.journal", "/run/journal.log".to_string(), false);
1129+
debug!("Added virtio-serial device for journal streaming to /run/journal.log");
1130+
10981131
if opts.common.ssh_keygen {
10991132
qemu_config.enable_ssh_access(None); // Use default port 2222
11001133
debug!("Enabled SSH port forwarding: host port 2222 -> guest port 22");

docs/src/man/bcvk-ephemeral-run.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,28 @@ Development workflow example:
175175

176176
# DEBUGGING
177177

178-
When troubleshooting ephemeral VM issues, bcvk provides debugging logs that can be accessed from within the container.
178+
When troubleshooting ephemeral VM issues, bcvk provides several debugging logs that can be accessed from within the container.
179+
180+
## Guest Journal Log
181+
182+
The systemd journal from the guest VM is automatically streamed to `/run/journal.log` inside the container. This log captures all boot messages, service startup events, and system errors from the VM's perspective.
183+
184+
To view the journal log:
185+
186+
# For a running detached VM
187+
podman exec <container-id> tail -f /run/journal.log
188+
189+
# View specific systemd service messages
190+
podman exec <container-id> grep "dbus-broker" /run/journal.log
191+
192+
# Save journal for offline analysis
193+
podman exec <container-id> cat /run/journal.log > guest-journal.log
194+
195+
The journal log is particularly useful for:
196+
- Diagnosing boot failures and systemd service issues
197+
- Investigating permission denied errors
198+
- Understanding VM initialization problems
199+
- Debugging network and device configuration
179200

180201
## Virtiofsd Logs
181202

0 commit comments

Comments
 (0)