You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The FreeBSD container extensions are nearly standardised and the FreeBSD project is producing base images.
I've been running FreeBSD containers on macOS for about a year with a patched version of Podman that runs a FreeBSD VM to run the containers (I put together some infrastructure for building FreeBSD VM images that did everything that Podman expected), but it would be great to be able to run them with the one-VM-per-container model of this project and have an easy way of working with FreeBSD containers on macOS.
Are the requirements for how the VM image interacts with the host environment documented?
Code of Conduct
I agree to follow this project's Code of Conduct
Reacted by lin72h, Rasmus Sten, Recovered Expert, Marko Kaznovac, Ellis Breen, Robert Gogolok, ObjectiveSwift, ekzeb and ZX
Reacted by lin72h, Mateus, Recovered Expert, Maxime Grenu, Marko Kaznovac, Robert Gogolok and Helena Butow
@davidchisnall Good idea! I'm going to move this to the containerization repo as your initial work on this would involve the sorting out how to create a runtime abstraction around a VM running a BSD kernel.
You'll see gRPC calls in there inside all of the VirtualMachineAgent protocol implementations. Those are going over a vsock into the VZVirtualMachine, and the server side is the Linux guest agent in Sources/vminitd.
Start hacking in containerization with the objective of enhancing the cctl tool so that you can launch a BSD container. There's little point in dealing with the container repo until you can do that. Good luck!
Mirroring John, I think this would be sweet. Happy to help if you run into anything. This'd be the first time someone would stress the guest agent side of things in a non-linux world, so if any of the rpcs don't get you to the promise land please report what does and doesn't suck. Anything is up for change as it's pre 1.0
I could either see you editing vminitd to be more agnostic, or honestly my preferred approach would just be a new freebsd guest agent that conforms to the guest agent protocol as I don't think we're ready to take in any drastic changes in vminitd that may be needed.
Thanks. From a quick look at the protocol, I’d expect the FreeBSD version of the daemon to be 90% the same as the Linux one. I had a look at a few of the files in the implementation and there were only a few places that looked like they’d want to be different (and a lot of the differences are things that Swift already papers over).
The initial question was really aimed at an earlier step though. In particular:
How are host files shared to the guest? (VirtIO-FS?)
How does the guest get the mount points (explicit mount commands via the daemon? On Podman this is exposed via the qemufwcfg device, so I had to write a driver for that, but if they’re just RPC messages that’s simpler)
How are commands issued to the guest (gRPC over VirtIO socket? Is it always a specific socket, or is there a dynamic discovery mechanism?)
Do you expect a container runtime inside the VM, or do you simply treat the entirety of the inside of the VM as the container’s world? If the former, does this use the same protocol as existing container runtimes or something new? (It looks as if the vminitd stuff works with processes, rather than containers?)
How is the kernel loaded? (Podman just has a disk image, do you do this or use something simpler like the Linuxboot protocol to load an initial image plus RAM disk?)
How are host files shared to the guest? (VirtIO-FS?)
Yep!
How does the guest get the mount points (explicit mount commands via the daemon? On Podman this is exposed via the qemufwcfg device, so I had to write a driver for that, but if they’re just RPC messages that’s simpler)
How are commands issued to the guest (gRPC over VirtIO socket? Is it always a specific socket, or is there a dynamic discovery mechanism?)
Yep! And right now we mostly dial once on a known vsock port that the guest is listening on (1024), and reuse that conn for all communication with the guest (resizing terminal, wait(), kill() etc.)
Do you expect a container runtime inside the VM, or do you simply treat the entirety of the inside of the VM as the container’s world? If the former, does this use the same protocol as existing container runtimes or something new? (It looks as if the vminitd stuff works with processes, rather than containers?)
We expect just our guest agent and this small runc-like shim binary that actually does the container launches. The entirety of the VM today is the container's playground though. It's a new protocol, although we'd love to either flesh out the shim binary to be a more full fledged OCI runtime, or support just packaging an existing one in the guest. Today the way we describe the container is still the OCI runtime spec, but the APIs on the host (LinuxContainer type) only expose what our shim binary can actually set up (for example it'd be weird to just let the user edit a runtime spec and pass it to our type, as we don't support seccomp and other things so they'd essentially be nops).
How is the kernel loaded? (Podman just has a disk image, do you do this or use something simpler like the Linuxboot protocol to load an initial image plus RAM disk?)
Let us know what your thoughts/plans are after diggin in! It's still obviously an extremely new project so I'm hesitant to take in support for a new platform already, but if the changes are somewhat self contained we'd definitely evaluate. The nice bit is I'd think most of the changes could even be in a separate repo as the bulk of the work likely will be in some new VirtualMachineInstance, Container and guest agent which are all pluggable.
Thanks, that all looks feasible. There's Linuxboot support in FreeBSD already, I think the VirtIO-FS patches are nearly in (FUSE and VirtIO are there already, so it's mostly plumbing), especially if we can start by reusing ocijail as the runtime.
Oh, one more thing:
Do you extract the container images on the host or the guest? If it's the former (I guess it is, since APFS is much more sensible for this kind of thing than any standard Linux FS), do you depend on the page-sharing bits of VirtIO-FS (I think those are still to-do, the externally-owned-page bits in the buffer cache were added for ZFS and should be reusable, but it's not trivial to connect them up correctly)?
Don't expect anything fast from me - it will probably take a few weeks for me to dig through and understand this, but the FreeBSD Foundation is gently pushing on the container bits so I may be able to persuade some other folks to put in a bit more time (I've been trying to gently nudge the pieces into place to enable this kind of use case for the last few years and I think almost everything is there).
Do you extract the container images on the host or the guest?
On the host. However, I didn't think about the image side of things.. The way we do the extracts and expose the image to a guest is not via virtiofs. We unpack the tar archives directly into a sparse file formatted with ext4 on the fly, and then we clonefile(2) the file when we want to run a container and attach this clone as a block device to the VM. I'm ignorant to FreeBSD's ext4 support, but today that is the only way we support exposing the images to a guest. We don't do unpack directly to files on the host for performance, and because APFS is case insensitive by default so some workloads just won't work (like if you wanted to compile the linux kernel that has quite a few files that only differ in casing).
Do you extract the archives on the host with an ext4 driver or in the VM? If it’s the latter, that’s easy. I don’t think ext4 is a good fit for FreeBSD. There’s an ext2 (maybe 3?) driver and, if I remember correctly, the on-disk format is compatible, but it is not really a native FS and I think extended attributes are probably not working (among other things). Most container systems on FreeBSD use ZFS, but if you’re doing the CoW bits externally then UFS is probably fine. I’m not sure if the macOS UFS driver supports UFS2? If you’re manually creating the filesystem, the on-disk structures for UFS are fairly similar (the FreeBSD ext2 driver shares a lot of code with the UFS driver), they’re both simple inode-based filesystems (and, to create a disk image, you don’t need to touch any of the journalling or soft updates bits). The FreeBSD tools for building disk images work this way, creating a filesystem directly rather than going via the kernel).
It currently implements most of the features required by ext3 and ext4 file systems. Support for Extended Attributes in ext4 is experimental. Journalling and encryption are currently not supported.
but indeed isn't a great fit for FreeBSD containerization
@davidchisnall We do the extract/formatting on the host, the link I shared is an ext4 formatter implementation in Swift we'd written to do this Archive -> Ext4 block device dance for image pulls. The full flow is:
Pull tars
Make sparse file of size {configurable, but for the container tool is 512GiB}
Write tar data into sparse file with the EXT4 lib we have.
It's obviously non trivial to add new filesystem formatters, but we're open to it (we've been thinking about erofs lately on the linux side).
The nice bit is I'd think most of the changes could even be in a separate repo as the bulk of the work likely will be in some new VirtualMachineInstance, Container and guest agent which are all pluggable.
It'd be nice in some respects if our Linux vminitd was in its own repo.
Getting a FreeBSD container to run on macOS would be great. It would complete the set for those of us looking to use Swift on FreeBSD (still waiting for the 6.2 release to ship…. :-( ). There is a lot of work happening to ensure that FreeBSD can be a first class container and cloud native platform and this would be just one more piece of that.
Most container systems on FreeBSD use ZFS, but if you’re doing the CoW bits externally then UFS is probably fine. I’m not sure if the macOS UFS driver supports UFS2? ... The FreeBSD tools for building disk images work this way, creating a filesystem directly rather than going via the kernel).
Given the FreeBSD OCI support was just released as part of of the latest OCI Spec, it would be great to have FreeBSD support here. I do agree that UFS2 or ZFS would be ideal as the filesystem for these containers.
I'd like to share some additional thoughts on the filesystem discussion.
I think that APFS is not only case insensitive but also utf8-only
FreeBSD flags are only supported on ZFS and UFS to my knowledge (rw)
We could probably get a read-only container without flags working with minimal effort (ext4 should work?, also tarfs)
For me, the only use case for rw containers is image build. How is the new layer calculated on commit? Is it something like tar running in the VM to pack files based on mtime/ctime or something more complicated?
Ext4 only is probably even for linux a bit limiting. It might make sense to provide an option to use disk images as volumes for use cases where we don't need to share data between host and/or containers (e.g. database files).
Does the introduction of Container Machines have any impact on Containerization and the chances of a FreeBSD port? There was a talk at BSDCan that talked about using FreeBSD inside the Windows Subsystem for Linux (WSL) that may be relevant.
@majortom64 No, machine shouldn't have any effect on freebsd experiments here. The library (this repo) didn't really need any changes for machine at all.
Activity
jglogan commentedon Jul 24, 2025
@davidchisnall Good idea! I'm going to move this to the containerization repo as your initial work on this would involve the sorting out how to create a runtime abstraction around a VM running a BSD kernel.
Start with this bit of documentation: https://swiftpackageindex.com/apple/containerization/0.5.0/documentation/containerization/virtualmachineagent.
The implementation of this that runs the VMs for containers today is: https://github.com/apple/containerization/blob/main/Sources/Containerization/Agent/Vminitd.swift.
You'll see gRPC calls in there inside all of the VirtualMachineAgent protocol implementations. Those are going over a vsock into the VZVirtualMachine, and the server side is the Linux guest agent in Sources/vminitd.
Start hacking in containerization with the objective of enhancing the cctl tool so that you can launch a BSD container. There's little point in dealing with the container repo until you can do that. Good luck!
dcantah commentedon Jul 24, 2025
Mirroring John, I think this would be sweet. Happy to help if you run into anything. This'd be the first time someone would stress the guest agent side of things in a non-linux world, so if any of the rpcs don't get you to the promise land please report what does and doesn't suck. Anything is up for change as it's pre 1.0
dcantah commentedon Jul 24, 2025
I could either see you editing vminitd to be more agnostic, or honestly my preferred approach would just be a new freebsd guest agent that conforms to the guest agent protocol as I don't think we're ready to take in any drastic changes in vminitd that may be needed.
davidchisnall commentedon Jul 24, 2025
Thanks. From a quick look at the protocol, I’d expect the FreeBSD version of the daemon to be 90% the same as the Linux one. I had a look at a few of the files in the implementation and there were only a few places that looked like they’d want to be different (and a lot of the differences are things that Swift already papers over).
The initial question was really aimed at an earlier step though. In particular:
dcantah commentedon Jul 24, 2025
Yep!
Explicit mount commands via the framework here, but also for "bind" mounts from the host, we have to obviously tell the VMM that we're exposing this so it can actually be mounted in the guest. https://github.com/apple/containerization/blob/main/Sources/Containerization/VZVirtualMachineInstance.swift#L305-L307 https://github.com/apple/containerization/blob/main/Sources/Containerization/Mount.swift#L135, those two spots should help.
Yep! And right now we mostly dial once on a known vsock port that the guest is listening on (1024), and reuse that conn for all communication with the guest (resizing terminal, wait(), kill() etc.)
We expect just our guest agent and this small runc-like shim binary that actually does the container launches. The entirety of the VM today is the container's playground though. It's a new protocol, although we'd love to either flesh out the shim binary to be a more full fledged OCI runtime, or support just packaging an existing one in the guest. Today the way we describe the container is still the OCI runtime spec, but the APIs on the host (
LinuxContainertype) only expose what our shim binary can actually set up (for example it'd be weird to just let the user edit a runtime spec and pass it to our type, as we don't support seccomp and other things so they'd essentially be nops).The latter. Linuxboot and a block device that has the guest agent and shim binary in it that you pass to be the userland of the VM. I'd look at https://github.com/apple/containerization/blob/main/Sources/cctl/RootfsCommand.swift and https://github.com/apple/containerization/blob/main/Sources/cctl/RunCommand.swift for how we both create and use the initial filesystem mount to setup the VM.
dcantah commentedon Jul 24, 2025
Let us know what your thoughts/plans are after diggin in! It's still obviously an extremely new project so I'm hesitant to take in support for a new platform already, but if the changes are somewhat self contained we'd definitely evaluate. The nice bit is I'd think most of the changes could even be in a separate repo as the bulk of the work likely will be in some new
VirtualMachineInstance,Containerand guest agent which are all pluggable.davidchisnall commentedon Jul 24, 2025
Thanks, that all looks feasible. There's Linuxboot support in FreeBSD already, I think the VirtIO-FS patches are nearly in (FUSE and VirtIO are there already, so it's mostly plumbing), especially if we can start by reusing ocijail as the runtime.
Oh, one more thing:
Do you extract the container images on the host or the guest? If it's the former (I guess it is, since APFS is much more sensible for this kind of thing than any standard Linux FS), do you depend on the page-sharing bits of VirtIO-FS (I think those are still to-do, the externally-owned-page bits in the buffer cache were added for ZFS and should be reusable, but it's not trivial to connect them up correctly)?
Don't expect anything fast from me - it will probably take a few weeks for me to dig through and understand this, but the FreeBSD Foundation is gently pushing on the container bits so I may be able to persuade some other folks to put in a bit more time (I've been trying to gently nudge the pieces into place to enable this kind of use case for the last few years and I think almost everything is there).
dcantah commentedon Jul 24, 2025
On the host. However, I didn't think about the image side of things.. The way we do the extracts and expose the image to a guest is not via virtiofs. We unpack the tar archives directly into a sparse file formatted with ext4 on the fly, and then we clonefile(2) the file when we want to run a container and attach this clone as a block device to the VM. I'm ignorant to FreeBSD's ext4 support, but today that is the only way we support exposing the images to a guest. We don't do unpack directly to files on the host for performance, and because APFS is case insensitive by default so some workloads just won't work (like if you wanted to compile the linux kernel that has quite a few files that only differ in casing).
davidchisnall commentedon Jul 25, 2025
Do you extract the archives on the host with an ext4 driver or in the VM? If it’s the latter, that’s easy. I don’t think ext4 is a good fit for FreeBSD. There’s an ext2 (maybe 3?) driver and, if I remember correctly, the on-disk format is compatible, but it is not really a native FS and I think extended attributes are probably not working (among other things). Most container systems on FreeBSD use ZFS, but if you’re doing the CoW bits externally then UFS is probably fine. I’m not sure if the macOS UFS driver supports UFS2? If you’re manually creating the filesystem, the on-disk structures for UFS are fairly similar (the FreeBSD ext2 driver shares a lot of code with the UFS driver), they’re both simple inode-based filesystems (and, to create a disk image, you don’t need to touch any of the journalling or soft updates bits). The FreeBSD tools for building disk images work this way, creating a filesystem directly rather than going via the kernel).
emaste commentedon Jul 25, 2025
ext2fs(4) has some ext3 and ext4 support
but indeed isn't a great fit for FreeBSD containerization
dcantah commentedon Jul 25, 2025
@davidchisnall We do the extract/formatting on the host, the link I shared is an ext4 formatter implementation in Swift we'd written to do this Archive -> Ext4 block device dance for image pulls. The full flow is:
It's obviously non trivial to add new filesystem formatters, but we're open to it (we've been thinking about erofs lately on the linux side).
jglogan commentedon Jul 30, 2025
It'd be nice in some respects if our Linux vminitd was in its own repo.
majortom64 commentedon Oct 8, 2025
Getting a FreeBSD container to run on macOS would be great. It would complete the set for those of us looking to use Swift on FreeBSD (still waiting for the 6.2 release to ship…. :-( ). There is a lot of work happening to ensure that FreeBSD can be a first class container and cloud native platform and this would be just one more piece of that.
majortom64 commentedon Nov 4, 2025
Given the FreeBSD OCI support was just released as part of of the latest OCI Spec, it would be great to have FreeBSD support here. I do agree that UFS2 or ZFS would be ideal as the filesystem for these containers.
b8b commentedon Dec 4, 2025
I'd like to share some additional thoughts on the filesystem discussion.
For me, the only use case for rw containers is image build. How is the new layer calculated on commit? Is it something like tar running in the VM to pack files based on mtime/ctime or something more complicated?
Ext4 only is probably even for linux a bit limiting. It might make sense to provide an option to use disk images as volumes for use cases where we don't need to share data between host and/or containers (e.g. database files).
majortom64 commentedon Jun 23, 2026
Does the introduction of Container Machines have any impact on Containerization and the chances of a FreeBSD port? There was a talk at BSDCan that talked about using FreeBSD inside the Windows Subsystem for Linux (WSL) that may be relevant.
dcantah commentedon Jun 25, 2026
@majortom64 No, machine shouldn't have any effect on freebsd experiments here. The library (this repo) didn't really need any changes for machine at all.