
Recall first from Milestones, testing and debugging
- DRIVER_OK records driver readiness and must be followed by an I/O test.
- A raw write and readback test verifies bytes before a filesystem adds more variables.
- The kvm_exit tracepoint and the VMM's KVM_RUN counters measure different events.
Script a repeatable boot
3 min readThe last lesson finished the project. This lesson answers how to turn it into a demo: a scripted boot, the device in action, and the exit breakdown.
Linux can reach an initramfs shell even when the data disk is missing. The shell runs from the unpacked initramfs, and the separate filesystem comes into use when you mount it. That gives the demo two distinct milestones. First, show that the VMM boots the guest kernel and hands you a console. Then show that the guest discovers the virtio block device and can use the filesystem on it. Begin with a short claim the audience can check: “This VMM boots Linux and serves reads and writes to a virtio disk.”
Put the working VMM launch command in a host script. Use the arguments your project already accepts to select the guest kernel, the initramfs, the writable disk image, and the serial console settings. Resolve asset paths from a known directory so the script behaves the same when launched from another terminal. Have it check that the VMM is executable and that the inputs are readable before starting. Print the selected paths at launch so you can identify the exact files in the recording.
Keep a clean, preformatted ext4 image and copy it to a fresh writable file for each run. The example in this lesson assumes ext4 occupies the whole virtio disk and that Linux registers it as /dev/vda. If your image has a partition table, use the confirmed partition in the mount command. Give each run its own directory for the writable image, console log, device trace, and perf data. Keep the serial console interactive and preserve its transcript using your existing console capture. Rehearse the guest shutdown and verify that the VMM exits cleanly before starting another run.
Once the guest shell appears, show the relevant kernel messages. This filter includes the virtio block driver name and the disk name used here. Use the actual disk name if your layout differs.
dmesg | grep -E 'virtio|vda'
Keep the full guest log available and point to the line from virtio_blk that identifies the disk. The transport may produce additional messages, and the details depend on the guest kernel and device configuration. Read the actual probe result from your run. Tell the audience what the line establishes: Linux bound its block driver and registered the disk. The mount and file test will show whether it can use that disk. Check during rehearsal that the guest shell can read dmesg, that the device node exists, and that the initramfs includes the filesystem support and commands used in the demo.
Show a write and a readback
3 min readUse one short workload with a visible success condition. The commands below run as root in the guest and assume GNU dd with conv=fsync and iflag=direct. Include that implementation in the initramfs if its existing dd lacks those options. The guest also needs cmp and a writable /tmp with room for the source and readback files. Prepare the source before tracing the workload so its creation sits outside the capture window.
mkdir -p /mnt/demo
mount -t ext4 /dev/vda /mnt/demo
dd if=/dev/urandom of=/tmp/demo.source bs=1M count=4
Check each command's status before proceeding. In your guest script, stop on failure and print a success message only after the file comparison passes. Say aloud which path is on the virtio disk. The source and readback stay in the initramfs, and /mnt/demo/demo.bin is the file on the mounted filesystem. A successful mount already exercises reads, so waiting until after the mount to start the workload capture makes the file test easier to identify.
dd if=/tmp/demo.source of=/mnt/demo/demo.bin bs=1M conv=fsync &&
dd if=/mnt/demo/demo.bin of=/tmp/demo.readback bs=1M iflag=direct &&
cmp /tmp/demo.source /tmp/demo.readback
The first dd writes four MiB and asks Linux to synchronize the output file before finishing. Treat success as evidence for the running guest's file test. A claim about persistence through power loss would require evidence about how the VMM backend handles flushes and how the host stores data. The second dd opens the mounted file for direct I/O to avoid serving the read from the guest page cache. The transfer size is chosen for this ext4 example. Rehearse it on the actual image because direct I/O has filesystem and alignment requirements. If it fails, preserve the error and fix the setup before presenting the run. A successful cmp returns status zero and normally prints nothing.
Show the VMM's block request trace beside the guest console. Use the existing request logging and rehearse with it enabled. For the narration, select a completed write and a completed read from the workload window. Identify the direction, starting sector, length in the units your logger uses, and completion status. If the logger emits separate submission and completion lines, match them using the request identifier it records. For example, point to a write completed while the first dd was running, then to a read completed during direct readback. Show actual rows from the session.
A filesystem can issue extra requests for its own metadata, and Linux can split or combine I/O before it reaches the device. Expect several trace rows and explain the two you selected in terms of their direction and timing. The byte comparison establishes that the guest read back the expected file contents. The completed requests establish that the VMM handled both directions of block I/O during the test. Save the command output and full trace before unmounting and shutting down. Unmount after the capture if the reported window is meant to cover the file test alone.
Explain the recorded KVM exits
3 min readUse perf kvm stat on the host running the VMM. Rehearse on that host with a working perf installation and sufficient access to the KVM tracepoints. In a VM, verify nested KVM and the tracepoints in the Ubuntu environment that actually runs the mini-VMM. Begin the capture once the guest has booted and the mount and source file are ready. This makes the report about the workload window, which also includes any guest activity and idle time between starting and stopping recording.
In a second host terminal, set vmm_pid to the running VMM's process ID. Confirm it belongs to the current run and that the guest's vCPU threads already exist. If the launch script starts a wrapper or a console logger, use the VMM's PID. From the run directory, record against that process, run the file test at the guest console, and stop recording with Ctrl+C in the host recording terminal after the comparison finishes.
sudo perf kvm stat record -p "$vmm_pid" -o demo-perf.data
sudo perf kvm stat report -i demo-perf.data --event=vmexit
Show the exit reason with the most samples, its count or share, and the mean time shown for it if available. Read the report headings aloud when the distinction matters. A count says how often a reason was sampled. A time share describes the measured intervals for that reason as a fraction of the measured intervals in the report. On this x86 capture, perf kvm stat uses KVM exit and entry events to measure time between leaving and re-entering the guest. That interval can include kernel handling, userspace handling, or waiting. Describe the maximum or mean in those terms if an audience member asks what the time represents.
KVM exit reasons can differ across processors and runs. Use the reason names printed by your host. Some exits are handled within KVM, and a userspace return from KVM_RUN has its own API exit reason. A block request can involve multiple observed events, and the report aggregates exits across the capture. Use the VMM trace when you want to identify a write or read completion. Use the perf report when you want to describe the exit mix observed on the host. If an exit reason looks unrelated to storage, check how much time the guest spent waiting at the console before and after the test. For a short workload, those pauses can have a visible effect on the distribution.
End the live run with one sentence for each observation. Show the guest probe line and name the disk it registered. Give the comparison result and show the two completed block requests. State the capture window and report the leading reason using the values from that run. Save a rehearsal run as a fallback and label it as a rehearsal if you need to show it. If the live run stops early, name the last milestone you observed and resume the presentation with the saved evidence.
The next lesson, “The review checklist and code review,” explains how to review the implementation behind the behavior you just demonstrated.
Key takeaways
- The guest boot log shows driver discovery and disk registration.
- A flushed file write and direct readback provide a functional test of the mounted virtio disk.
- VMM request logs and host KVM exit statistics describe different events.
- The timing and scope of the perf capture determine which exits appear in the report.
Reflect
- Explain to a colleague, in two sentences: launch the VMM with a scripted kernel, initramfs, and disposable disk image
- Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
- What surprised you when you ran the commands yourself?
On a real board
Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.
References and further reading
- Man pagemount(8): attach a filesystem
- Man pageopen(2): direct I/O and alignment
- Man pageperf-kvm(1): KVM event recording and reporting
- Kernel documentationThe KVM API
Official documentation first. Links checked when the lesson was published.