Repository navigation
Description
Summary
Add a --qcow2 option to kerf load so a spawn kernel can be started directly from a VM image:
kerf load vm1 --qcow2=fedora-cloud.qcow2
Today kerf load accepts two rootfs sources, --image (Docker) and --rootfs-dir. Both end in the same place: a directory tree packed into a daxfs image by create_daxfs_image(). A qcow2 image is a third way to obtain that tree, and it can also supply the kernel.
Proposed behavior
--qcow2=<path>is mutually exclusive with--imageand--rootfs-dir.- The root filesystem of the image becomes the daxfs root of the instance.
- The kernel is taken from the image by default. The image is assumed to ship a multikernel-capable kernel.
--kernelbecomes optional with--qcow2and overrides the image's kernel when given. - The entrypoint defaults to
/sbin/init, since a VM image has no Docker-style ENTRYPOINT.--entrypointoverrides it. - The initramfs inside the image is not used, because it is built to find a disk root. daxfs is expected to be built into the image's kernel;
--initrdremains the override for a modular build, as today.
Design
No external commands (qemu-nbd, guestmount, qemu-img) and no new filesystem-parsing dependency. kerf decodes the qcow2 container itself and lets the host kernel read the guest filesystem:
- Decode the qcow2 into a sparse raw temporary file. The format is a header plus two levels of lookup tables (L1/L2). zlib clusters are handled by the standard library; zstd clusters need the
zstandardmodule before Python 3.14. - Attach the raw file to a loop device with partition scanning, through ioctls.
- Mount the root partition read-only with
mount(2), using the same ctypes pattern already inmkdaxfs.py. - Pass the mountpoint to
create_daxfs_image()unchanged. - Open the kernel while the image is still mounted, then unmount and detach the loop device.
Locating the kernel
/boot is often a separate partition, so the search is:
/lib/modules/<version>/vmlinuzon the root (Fedora and RHEL family)./boot/vmlinuz-*on the root (Debian and Ubuntu).- The remaining partitions of the image, scanned for
vmlinuz-*.
With several kernels installed, the highest version is picked. A specific one can be chosen with --kernel.
fstab
The spawn kernel never sees a block device, so the image's /etc/fstab entries for root, /boot and swap refer to devices that do not exist in the instance. kerf should replace fstab with an empty file in the daxfs copy, using the existing per-file override mechanism of DaxfsBuilder (the one that injects kerf-init).
Non-goals
- Persistence. Writes go to the daxfs overlay and are lost on unload; nothing is written back to the qcow2.
- Serving the qcow2 as a live disk to the instance. That would need a block transport such as virtio-blk and is a separate feature. This proposal does not require virtio-blk.
- LVM-based images and qcow2 encryption or backing files, at least initially.
Open questions
- Root partition selection for images with several Linux partitions, and btrfs images that keep the root in a subvolume. A partition override option may be needed.
- Filesystems with a dirty journal need
noload(ext4) ornorecovery(xfs) to mount from a read-only device. - The whole rootfs is copied into the multikernel pool, so large VM images need a correspondingly large pool.
- The host kernel parses the guest filesystem, which is an attack surface for untrusted images. A userspace parser would avoid that at the cost of a dependency.
vmlinuz.pyalready shells out for zstd and lz4 compressed kernels. Ifzstandardbecomes a dependency for qcow2 clusters, that path could use it as well.
Activity
saeedvft commentedon Nov 27, 2026
I'd like to take this. I plan to split it into PRs: (1) a standalone qcow2→raw decoder with tests (zlib and zstd clusters, zero clusters, no backing files), (2) loop attach + read-only mount, (3) kernel discovery, (4) the --qcow2 option in load. I'll start with (1) as new files so it doesn't conflict with your work in load. Does that split and ordering work for you?
congwang-mk commentedon Nov 28, 2026
Thanks for taking this, @saeedvft . Looks like a good plan. Just one small request: please keep the code shell-out free, that is, avoiding executing external command. Leverage existing Python modules.
Looking forward to your PR!
saeedvft commentedon Nov 29, 2026
Thanks! Understood on keeping it shell-out free: the decoder will be pure Python (struct, zlib, plain file I/O), and I'll use compression.zstd on 3.14 or the zstandard module otherwise. I'm starting on the decoder now and will open the first PR once it has tests.
saeedvft commentedon Dec 1, 2026
First PR for this is up: #28