tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Disabling drivers from a NetBSD kernel without `userconf(4)` nor rebuild




Hi,

I've restarted working on a micro-NetBSD project I've documented back in 2020
here: https://imil.net/blog/posts/2020/fakecracker-netbsd-as-a-function-based-microvm/
The idea being to create a micro-service virtual machine that starts a NetBSD
kernel and a dedicated service in less than 200ms.
The project works but there are some elements to be improved. First, in order
to reduce boot speed, the kernel is directly called from qemu with the
-kernel flag, this means the project relies on multiboot(8), so for the time
being, it only works with an i386 kernel.
Second, in this proof of concept, it is mandatory to rebuild a very minimal
kernel in order to kick out every driver that's not absolutely necessary, but
this step would be really painful for someone not used and not wanting to dig
into kernel build etc.
My endgame is being able to build a NetBSD-based micro service with something
similar to:

$ mksmolnb https://cdn.NetBSD.org 9.3 nginx

which will download and prepare all the pieces with a process similar to what
I described in the blog post.

I began digging for a method that could permit to disable kernel drivers in
the same way userconf(4) does, and realized with the help of mlelstv@ on IRC
that I'd only need to alter autoconf tables to disable all the drivers I'd
want.
So I found where cfdata was, and how to overwrite the fstate with gdb --write
and finally came to this very nasty hack: https://gitlab.com/iMil/sailor/-/snippets/2491821
which basically permits to disable every driver in the kernel except those
needed directly in the kernel binary.
I am totally aware that this method could be made obsolete as soon as struct
cfdata is modified.

I just wanted to share this for anyone curious how to do this, and maybe get
some more ideas to make it cleaner.

Cheers,

------------------------------------------------------------------------
Emile `iMil' Heitor <imil@{home.imil.net,NetBSD.org}> | https://imil.net



Home | Main Index | Thread Index | Old Index