13 minutes
Running a native KVM VM on a Cisco Catalyst 9300
I have been running Docker containers on my Catalyst 9300 switches for a while using IOx application hosting. The switch is already in the data path, so I wondered how much of a small appliance it could replace. A firewall seemed like an interesting candidate, as it would mean functional internet connectivity from my home wifi could drop its dependency on my hypervisor server cluster being operational - instead requiring just the pair of Cisco switches (in fact, just one of the switches being up should suffice).
That meant running OpenBSD as a VM, which quickly led me into unsupported territory. Cisco’s IOS-XE application-hosting documentation says that application hosting on the Catalyst 9000 supports Docker applications only, and the IOx platform support matrix also lists the Catalyst platforms as Docker-only. The Catalyst 9000 application-hosting FAQ does mention KVM, but only for selected Cisco-curated applications. The only curated apps I’m aware of on Catalyst switches are ThousandEyes and ASAc, and I believe both are containers rather than KVM VMs.
My first implementation therefore put QEMU in a Docker container. It worked, but QEMU had to use TCG software emulation (because /dev/kvm is unavailable inside the container), and throughput was limited to roughly 100 Mbps.
I later discovered that the switch could launch a native IOx VM after all. Moving the same workload to KVM improved throughput significantly, with parallel TCP traffic reaching 933 Mbps - more or less the limit of the 1 Gbps AppGigabit Ethernet path.
This post covers the native VM mechanism: packaging it, working out what the resource values really mean, and getting back into a VM that has stopped responding. The OpenBSD image and PF configuration will be in a separate post.
The difference KVM made
To compare like with like, I ran the same two-vCPU, virtio-net OpenBSD guest as a router/firewall with PF translation and TCP iperf3 traffic through it. The test endpoints were the same for both runs.
The medians of three 30-second runs were:
| Test | QEMU with TCG | Native IOx KVM | Improvement |
|---|---|---|---|
| Forward, one stream | 98.3 Mbps | 562 Mbps | 5.7x |
| Reverse, one stream | 110 Mbps | 653 Mbps | 5.9x |
| Forward, four streams | 106 Mbps | 933 Mbps | 8.8x |
The switch used for these tests has a single 1 Gbps AppGigabit Ethernet application-hosting path, so 933 Mbps is close to the limit of that path rather than a limit of KVM itself. The C9300X provides a pair of 10 Gbps AppGigabit interfaces, but I don’t have access to one on which to repeat this test.
The observations described in this post come from a C9300-48UXM running IOS-XE 26.01.2, Cisco Application Framework (CAF) 2.16.0, libvirt 5.5, QEMU 4.1 and Docker 19.03.13-ce.
It is worth distinguishing between two differences here. One is Docker versus a native IOx VM application; the other is QEMU software emulation using TCG versus KVM hardware acceleration. The performance difference was TCG versus KVM, not simply the package type. A QEMU container on a platform that passes /dev/kvm through to containers could use KVM too (and would benefit from being able to use the latest versions of QEMU, as well as dropping many of the arbitrary restrictions on QEMU configurability) - but this one does not.
Before starting
On a Catalyst 9300, application-hosting packages use a Cisco USB SSD rather than the switch’s internal flash. IOS-XE presents the SSD as usbflash1:, formatted as EXT4. Cisco’s USB SSD guidance describes the supported hardware and preparation, and its application-hosting white paper summarises the available storage, CPU and memory by model.
I also needed:
- IOx application hosting enabled
- enough CPU, memory and SSD capacity for the VM
- an IOS-XE/IOx network attachment such as AppGigabit Ethernet or a Virtual Port Group
- a machine with
ioxclientand QEMU tools to prepare and package the image
Because my package was unsigned, I first had to tell IOx to allow it:
app-hosting verification disable
That is a privileged EXEC command rather than IOS-XE configuration, so it doesn’t appear in the running configuration. You can check the current setting with show app-hosting infra, which should report App signature verification: disabled. Cisco’s generic IOx documentation also describes a similar ioxclient platform signedpackages disable command.
With verification disabled, IOx will install any package regardless of who built it. That’s unavoidable for a home-built package, but it does mean you need to be confident about where your packages come from.
Building a native VM package
A native package is essentially an IOx descriptor plus a guest disk:
vm-package/
|-- package.yaml
`-- guest.qcow2
A raw disk can be converted, checked and packaged with:
qemu-img convert -c -O qcow2 guest.img vm-package/guest.qcow2
qemu-img check vm-package/guest.qcow2
ioxclient package --skip-signing --name example-vm vm-package
One important build constraint is that the IOx VM launcher uses QEMU’s pc-0.13 machine type with legacy BIOS. It does not provide a UEFI firmware option.
Cisco’s VM documentation exposes controls for the QEMU guest agent (QGA), CD-ROM, serial character devices, VNC graphics and some filesystem-style resources. I could not find descriptor fields for selecting the firmware, machine chipset, NIC model, boot flags or arbitrary QEMU arguments. On this platform those are down to the launcher, rather than anything I could change in the package.
Package, activation and IOS-XE configuration
It took me a while to separate these three layers. They are related, but each is responsible for something different:
| Layer | It defines |
|---|---|
| Package descriptor | The QCOW2 file, guest type, boot disks, QEMU guest agent setting, requested vNIC list and generic resource defaults |
| Activation payload | Per-instance resources and the mapping from package interfaces to IOx logical networks |
IOS-XE app-hosting configuration | Per-instance resources and app-vnic mappings when IOS-XE owns the instance configuration |
Cisco’s application networking documentation covers this: the package requests interfaces by name, and activation maps each one to a logical network provided by the platform.
Here is an example descriptor for a VM managed through the package and activation payload, rather than IOS-XE:
descriptor-schema-version: "2.9"
info:
name: example-vm
description: "Example x86-64 VM"
version: "1.0"
app:
type: vm
cpuarch: x86_64
resources:
profile: custom
cpu: 5550
memory: 568
disk: 1
vcpu: 2
network:
- interface-name: eth0
startup:
ostype: openbsd
disks:
- target-dev: hda
file: guest.qcow2
qemu-guest-agent: false
The activation payload then supplies a complete resource set and maps eth0:
{
"resources": {
"profile": "custom",
"cpu": 5550,
"memory": 568,
"disk": 1,
"vcpu": 2,
"network": [
{
"interface-name": "eth0",
"network-name": "mgmt-bridge300"
}
]
}
}
mgmt-bridge300 is the logical network that attaches the VM to the AppGigabit Ethernet path. The name would be meaningless on a different switch unless that switch’s IOS-XE and IOx configuration provided the same mapping. That said, the C9300 platform does not permit user-defined logical app-hosting networks, and I suspect the defined networks are identical across all switches of the same platform, at least (they certainly are on my two switches).
IOS-XE can instead own the per-instance settings, using an app-hosting appid stanza with its app-resource and app-vnic commands. That keeps the settings visible in the running configuration, which is useful for backups and auditing. It can’t replace package-only things such as the QCOW2 contents, boot disk or QEMU guest agent setting, and for the values both layers cover I would pick one or the other rather than mixing a partial activation payload with an IOS-XE stanza.
The resource values need interpreting
This was probably the biggest source of confusion. The field names suggest direct VM totals, but that isn’t quite what IOx does with them.
Package disk and IOS-XE persist-disk reserve persistent IOx application storage, separate from the VM itself. They don’t size the packaged QCOW2, the guest’s virtual disk or its filesystems: the VM booted with the same 5 GiB QCOW2 whether that reservation was 1 MB or 6000 MB. Larger values also pick up 5% of platform overhead, so 6000 MB became 6300 MB. I now use disk: 1, because zero is rejected and this VM doesn’t otherwise need CAF appdata storage.
Memory is different: roughly 10% comes off whatever you request. The values fit guest_MiB = ceil(requested_MiB * 0.9), so requesting 512 MB gave QEMU 461 MB (in the sense that the qemu-kvm process was launched with -m 461), while requesting 568 MB gave it 512 MB.
CPU units are a minimum guaranteed reservation rather than a hard limit. Cisco’s application resource profile documentation says an application can use more when the host is otherwise idle. On this switch, 5550 of 7400 units is 75%; IOS-XE’s cpu-percent 75 is the equivalent reservation and can be used instead of CPU units. Neither should be confused with vcpu, which selects how many virtual CPUs the guest sees.
So the profile above asks for 75% of the CPU (5550 units), 568 MB of memory to give the guest 512 MiB, the minimum 1 MB of IOx appdata storage, and two vCPUs.
Installing, activating and stopping the VM
With a switch profile configured in ioxclient, the main lifecycle was:
ioxclient --profile switch application install examplevm example-vm.tar
ioxclient --profile switch application activate --payload activation.json examplevm
ioxclient --profile switch application start examplevm
A small gotcha is that the application ID must be alphanumeric. A hyphen in the ID got as far as installation and then failed connector-ID validation, so the examples use examplevm.
Installation just places the package on the switch; it’s activation that commits the resources and network mappings. That means changes to the IOS-XE configuration for an existing app only take effect after you stop and deactivate it, then activate and start it again - saving a new stanza isn’t enough.
Stopping turned out to be graceful too: app-hosting stop triggers an ACPI shutdown in the OpenBSD VM, with no need for the QEMU guest agent.
What the guest actually sees
The package metadata is really only a request - it doesn’t tell you what virtual hardware the guest will actually get. The disk controller was the clearest example.
I tried changing the descriptor’s disk target from hda to sda and vda, hoping for a virtio disk. Both passed package validation and booted, but OpenBSD still saw an IDE boot disk:
pciide0 at pci0 dev 1 function 1 "Intel 82371SB IDE" rev 0x00
wd0 at pciide0 channel 0 drive 0: <QEMU HARDDISK>
wd0: 16-sector PIO, LBA48
So vda and sda didn’t get me a virtio or SCSI disk. The guest’s dmesg output is what tells you what you really have, and IDE is consistent with the pc-0.13 machine type anyway. Being stuck with IDE can even stop a guest booting: Alpine Linux stalled before init on this switch, which I put down to its lack of IDE disk support. The NIC was a different story - OpenBSD saw it as vio0, backed by virtio-net.
The launcher also exposes the VM’s IOx appdata directory to the guest, as a Virtio 9P device tagged shared_mount. OpenBSD detects the device (1af4:1009), but its kernel has no matching driver, so there is nothing to mount.
From a Debian 13 guest, on the other hand, I was able to read and write data in the CAF appdata location through that same device. CAF adds the share automatically, so no explicit filesystem declaration is needed.
A few other descriptor fields are worth a mention:
filesystemwith the documentedmounttype validated under schema 2.13, but CAF 2.16 rejected the package withInvalid configuration: mount. The relatedfile,blockandramtypes are LXC mechanisms; QEMU/KVM filesystem sharing still means 9P or virtiofs.host_mountsremains untested and looks oriented towards container-style host paths rather than OpenBSD VM storage.randomdev: truevalidated and installed, but activation rejected it as an invalid device type.
So, as with the disk controller, accepting a field in the schema tells you very little about what this IOx runtime will actually do with it.
Getting back into a broken VM
Sooner or later a firewall VM will stop answering on the network, so I wanted to know how I’d get back in. The route that worked was IOS-XE itself, which takes you straight to the live OpenBSD login prompt on com0:
app-hosting connect appid examplevm console
No package change was needed for this to work. To detach, press Ctrl-C three times - IOS prints the sequence when you connect. app-hosting connect appid examplevm session is for Docker applications and was rejected for a VM. The other options I tried did not work: ioxclient application console returned HTTP 501, application session returned 500, and Local Manager’s Application Exec Console/8445 path was absent or unreachable. Cisco does document Local Manager console access, but it seems unsupported on this platform, and I didn’t need it once the IOS command worked.
VNC looked promising from Cisco’s generic VM guidance, because it can be enabled in the package:
resources:
graphics:
vnc: true
The activation payload can then select a password and port:
{
"graphics": {
"vnc": true,
"vnc-password": "<password>",
"port": "6665"
}
}
The port can be allocated automatically or selected from the documented 5900-65535 range. On this platform I found that IOx accepted the descriptor, activation payload and explicit port mapping. QEMU launched with Cirrus VGA and VNC, CAF metadata recorded port 6665, and Local Manager reported a VNC Access field. A connection was still refused on every switch-owned address I tried, with no entry point through Local Manager either. The result was that I could not reach VNC from my PC and would not rely on it as a recovery console.
QGA would be another way for software outside the guest to run commands inside it, but it is not a console. Enabling it added a virtio-serial port named org.qemu.guest_agent.0. A Linux guest seemed to be able to make use of the guest agent, but OpenBSD could not (even after installing the qemu-ga package) due to lack of support for the transport stack, which is why I opted to disable the guest agent in the package descriptor.
I also tried booting an OpenBSD installation ISO through a CD-ROM descriptor. A newer schema version accepted and packaged it, but CAF 2.16 failed activation before a VM container was even created. I don’t think PXE is a viable fallback either: there’s no package-level boot-order setting, and I found nothing to suggest the launcher would fall through to the network if the local disk failed.
If recovery is not possible via console access, the remaining problem is that there is no supported way to export the VM’s QCOW2 disk image. ioxclient can export CAF datamount/appdata, but this release had no command to download, snapshot or restore the QCOW2.
The QCOW2 file does exist in one place: on the application-hosting SSD, under the IOx repository on /vol/usb1 (which corresponds to usbflash1:). It isn’t accessible from IOS-XE directly though, such as via dir commands.
I tested inserting that SSD into another Linux machine, modifying the QCOW2 offline, and putting the SSD back into the switch. It worked: IOx accepted the modified image and the VM booted with the change present. That is a useful last resort if the serial console can’t recover the VM, but it is disruptive - every IOx application has to be stopped while the SSD is out - and modifying the live VM image carries some risk.
Where this leaves me
For a home-network firewall, I think the native VM path is entirely viable. The performance is suitable, there’s a working serial console if something goes wrong, and the lack of Cisco support doesn’t worry me much - this is a home network, not an enterprise deployment where I’d expect a support contract.
My one remaining concern is about shutdown rather than normal operation. A VM running on a switch faces a greater risk of an unclean shutdown because, unlike a server, a switch is typically expected to cope with an abrupt power-off without any problems. OpenBSD can be particularly sensitive to an unclean filesystem shutdown, and may require manual intervention before it will boot again. That’s why this can’t just be a conventional OpenBSD VM image. In the next post I plan to cover the customisations I used to reduce filesystem risk and recover cleanly - central to which is a read-only root filesystem.
Supporting Cisco documentation
These are the Cisco pages I referred to along the way:
- Build a sample VM type IOx application
- Cisco Local Manager app console access
- IOx application resource profiles
- IOx application networking
- Managing IOx package signature validation
- IOS-XE 17.17 application hosting
- IOx platform support matrix
- Catalyst 9300 USB 3.0 SSD configuration
- Catalyst 9000 application-hosting overview
- Catalyst 9000 application-hosting FAQ