by JonChesterfield · 3y ago · 0 comments
Options that come to mind are:
- build your application as a linux kernel module, load it into a normal kernel, and generally ignore the userspace that runs anyway
- take Linux and hack it down pretty aggressively plus splice your code into it
- find some github unikernel effort and go from there (which I think the OP does)
- take some other OS - freebsd? - and similarly hack out parts
Other?
I like the idea of a x64 machine running a VM connected to a network card as a generic compute resource that does whatever tasks are assigned by sending it data over the network. It's not been worth the hassle relative to a userspace daemon, but one day I may find the time and would be interested in the HN perspective on where best to start the OS level hackery.
> The Unikernel Linux (UKL) project started as an effort to exploit Linux’s configurability.. Our experience has led us to a more general goal: creating a kernel that can be configured to span the spectrum between a general-purpose operating system, amenable to a large class of applications, and a highly optimized, possibly application- and hardware-specialized, unikernel... other technologies occupying a similar space have come along, especially io_uring and eBPF. io_uring is interesting because it amortizes syscall overhead. eBPF is interesting because it’s another way to run code in kernel space (albeit for a very limited definition of “code”).
Code, https://github.com/unikernelLinux/ukl
> Unikernel Linux (UKL) is a small patch to Linux and glibc which allows you to build many programs, unmodified, as unikernels. That means they are linked with the Linux kernel into a final vmlinuz and run in kernel space. You can boot these kernels on baremetal or inside a virtual machine. Almost all features and drivers in Linux are available for use by the unikernel.
There are projects that permit statically linking a traditional kernel with a traditional application into a unikernel. NetBSD pioneered this with their rump kernel build framework, and I believe there's at least one Linux build framework that mimics this. The build frameworks cut out the syscall layer; an application calling read(2) is basically calling the kernel's read syscall implementation directly. Often you don't need to change any application source code. The build frameworks handle configuring and building the kernel image, and statically linking the kernel image with your application binary to produce the unikernel image.
> fully-standalone, specialised unikernel that runs under a Xen or KVM hypervisor.
Or maybe xen / kvm are no longer called operating systems?
I'm interested in having my code be responsible for thread scheduling and page tables - no OS layer to syscall into - but am not as keen on DIYing the device drivers to get it talking to the rest of the world.
> I replace the [QubesOS] Linux firewall VM with a MirageOS unikernel. The resulting VM uses safe (bounds-checked, type-checked) OCaml code to process network traffic, uses less than a tenth of the memory of the default FirewallVM, boots several times faster, and should be much simpler to audit or extend.
NanoVMs has OSS tools for golang unikernels on multiple hypervisors and cloud platforms, https://nanovms.com/dev/tutorials/running-go-unikernels
But MirageOS does exactly that, last I looked. As does RustyHermit.
> I'm interested in having my code be responsible for thread scheduling and page tables - no OS layer to syscall into [...]
You might be confusing Xen and KVM here? Xen and KVM are rather different in this regard.
KVM runs on a full Linux kernel (as far as I know). But running your application as unikernels on top of Xen is more comparable to the old Exokernel concept.
1. Minimizing an existing general-purpose OS
2. By-passing the OS
3. Starting from scratch
You can read more in detail about this here from Unikraft's documentation[0].
[0]: https://unikraft.org/docs/concepts/design-principles#approac...
- take Linux and hack it down pretty aggressively plus splice your code into it
But rather than starting with a Linux distro and hacking it down, I'd start the other way: Boot the kernel directly (via a UEFI bootloader). You can embed a basic filesystem structure (/dev, /proc, /etc, etc.) in a binary blob inside the kernel file itself on build (kind of dumb that this is required at all, but it is)). The kernel itself has basically everything you'd need (for any reason you'd want a unikernel).
Nanos has had strace/ftrace/gdb, plenty of apm/monitoring such as cloudwatch and all sorts of tools in/around that realm for years now.
https://docs.ops.city/ops/debugging
https://nanovms.com/dev/tutorials/using-netconsole-for-debug...
https://nanovms.com/dev/tutorials/debugging-unikernels-using...
https://nanovms.com/dev/tutorials/profiling-unikernel-syscal...
https://nanovms.com/dev/tutorials/debugging-nanos-unikernels...
https://nanovms.com/dev/tutorials/profiling-and-tracing-nano...
He made a few crates which handles the boot process, paging, x86 structures and more.
ops pkg load eyberg/wasmedge:0.9.1 -c config.json
You could replicate this is seconds and then push that image to AWS or GCP also in seconds.That's a lot more mature than RustyHermit, last I looked.