
Running Emacs in a NetBSD microVM built with smolBSD
A developer who blogs as The Emacs Cat needed to verify that a C networking library builds on NetBSD, so he set up a tiny smolBSD microVM whose kernel starts in 26 ms and takes about 180 MB of host memory.
The developer who blogs as The Emacs Cat describes running Emacs inside a NetBSD microVM built with smolBSD, a minimal BSD UNIX virtual machine that boots and starts a service in a few milliseconds. The starting point was an ordinary engineering task: he wanted to confirm that a C networking library and the full C toolchain build on NetBSD the same way they do on Ubuntu and macOS.
Why NetBSD
NetBSD is an open-source Unix-like system known for its portability: it runs on x86-64 and aarch64 servers, embedded systems, handhelds, vintage machines such as VAX and m68k, and even some game consoles. Its long-standing motto is “Of course it runs NetBSD”. The author notes it is the good old 4.3BSD, which adds a touch of nostalgia. His home data center has no dedicated NetBSD machine, so a virtual machine was the practical choice.
A microVM configured like a Dockerfile
The microVM image is defined by a SMOLerfile, smolBSD's configuration file for a minimal NetBSD-based service. It reuses familiar Dockerfile verbs such as FROM, RUN and CMD, although it does not implement the full reference. The author's Dockerfile.devsh starts from the base,etc,comp set: the core system, the configuration skeleton, and the compiler toolchain with headers, libraries, linker and make.
Labels name the service devsh, add packages such as pkgin, curl, rsync and sqlite3, request a PTY console, and set a 2 GB disk image truncated to the minimum plus 512 MB.
Emacs inside the guest
The requirements were short: an interactive shell (ksh is NetBSD's default), the compiler toolchain with gcc, make and ld, and Emacs itself. NetBSD ships vi, not vim, in version 1.81.6-2013-11-20nb4; the author installed Emacs with pkgin as emacs-nox11 and added GNU make (gmake) instead of the default bsdmake.
A minimal ~/.emacs enables column numbers, paren highlighting and a 4-space indent with the stroustrup C style. One quirk: QEMU uses Ctrl-A as its escape key, so Ctrl-A never reaches the guest; double-pressing works, but the author rebound beginning-of-line to M-a.
26 milliseconds and 180 MB
A small script boots the image: startnb.sh takes the VM configuration generated during the build with -f, a PTY console with -P, shutdown from ksh with -n 2, and mounts a host directory into the guest's /mnt with -w.
On an old Dell Latitude 7400 laptop the NetBSD kernel starts in 26 ms and the whole virtual machine initially takes 180 MB of host memory.
In the post the author documents the whole path, from installing smolBSD to building and booting the image, which leaves him a full NetBSD development environment without a dedicated physical machine.
SiTech — AI-powered web development
We build fast, modern websites and bring AI into real business workflows. Have a project or a question? We'd love to help.