void0
I have not written up anything, but I can just describe here. The terminal uses an internal (for now) API to create a VM, passing a bunch of file and pipe handles and a bunch of configs to crosvm. Crosvm launches the VM either with direct boot (kernel + initrd) or bootloader (sudh as u-boot).
The build/debian directory contains scripts and configs for building Google's Debian image + kernel, and build/custom_vm directory contains my modified scripts for building the Alpine image + kernel.
Both these images uses a similar initrd design based on busybox, which loads the bare minimum modules from initrd to read the filesystem (see e.g. build/custom_vm/generic-kernel/initrd/modules), mounts the kernel_extras_part partition and links its contents (mainly kernel modules) to appropriate system folders, and finally chroots into the real root to run its /sbin/init.
When the Debian VM boots from the real root for the first time, it uses cloud-init to run a bunch of setup, including adding all these services. These services launch after that or when the VM boots subsequently. Among them are ttyd and avahi.
ttyd is this, which is not a serial console but just a terminal emulator provided inside a webpage. They forces it to use the ca.crt from host (mounted at /mnt/internal/ca.crt with virtiofs), and put avahi on top of its default port. Avahi publishes ttyd's webpage as a network service with the name ttyd using mDNS/DNS-SD. From what I gather, mDNS is like how your computer discovers your printer by nickname in the local network.
The app itself, after launching the VM, waits for it to do all the above, and signify its readiness by waiting for the ttyd network service. Once the ttyd network service is found and passes the certificate check, the terminal tab loads a webview displaying the page ttyd provided, and the user finally sees the "console".
willing to beta test it.
New release is here. I regret to inform you it is a pre-alpha test :) The thing fricking crashes if you look at it wrong.