14

Can I take a Linux kernel and use it with, say, FreeBSD and vice versa (FreeBSD kernel in, say, a Debian)? Is there a universal answer? What are the limitations? What are the obstructions?

5
  • 5
    No, absolutely not. A good exercise would be to try it and see how it breaks. You can't even replace a Linux kernel with a much older Linux kernel reliably. Replacing userland tools is definitely doable though (if recompiled).
    – Kusalananda
    Mar 22, 2018 at 9:35
  • 3
    debian.org/ports/kfreebsd-gnu and debian.org/ports/hurd might interest you
    – muru
    Mar 22, 2018 at 9:37
  • @Kusalananda regarding replacing userland tools, going from BSD to Linux can be painful: some BSD tools are quite hard to build on non-BSD systems... I’ve come across a few tools over the years which I would have liked to port, but it turned out to be non-trivial :-/. Mar 22, 2018 at 11:28
  • 1
    @StephenKitt The reverse is true too :-) Especially when the software makes assumptions about being able to access /procor other Linux-specific bells and whistles.
    – Kusalananda
    Mar 22, 2018 at 11:33
  • What you can do is to take a x86_64 (linux) kernel and force-install it on i386 32-bit distribution (assuming a 64-bit intel CPU and support for 32-bit binaries compiled in). This is quite well known, but not immediately obvious... Mar 23, 2018 at 14:17

2 Answers 2

39

No, kernels from different implementations of Unix-style operating systems are not interchangeable, notably because they all present different interfaces to the rest of the system (user space) — their system calls (including ioctl specifics), the various virtual file systems they use...

What is interchangeable to some extent, at the source level, is the combination of the kernel and the C library, or rather, the user-level APIs that the kernel and libraries expose (essentially, the view at the layer described by POSIX, without considering whether it is actually POSIX). Examples of this include Debian GNU/kFreeBSD, which builds a Debian system on top of a FreeBSD kernel, and Debian GNU/Hurd, which builds a Debian system on top of the Hurd.

This isn’t quite at the level of kernel interchangeability, but there have been attempts to standardise a common application binary interface, to allow binaries to be used on various systems without needing recompilation. One example is the Intel Binary Compatibility Standard, which allows binaries conforming to it to run on any Unix system implementing it, including older versions of Linux with the iBCS 2 layer. I used this in the late 90s to run WordPerfect on Linux.

See also How to build a FreeBSD chroot inside of Linux.

5
  • 1
    Some people have quite strong opinions on how important it is to keep the kernel and user APIs synced :)
    – tonysdg
    Mar 23, 2018 at 0:47
  • 4
    Indeed @tonysdg, and believe me, I know all about that :-/. Mar 23, 2018 at 13:47
  • @tonysdg I get a page not found on your link. (Unless that's a joke I'm missing?)
    – mbrig
    Mar 23, 2018 at 17:23
  • 1
    @mbrig: Until yesterday, it was there -- here's an archived version: web.archive.org/web/20171102142621/http://…
    – tonysdg
    Mar 23, 2018 at 20:10
  • @StephenKitt: Ouch :( Sorry!! But major kudos for even having code in the kernel to begin with!
    – tonysdg
    Mar 23, 2018 at 20:13
4

Some kernels have binary compatibility allowing you to mix userspace programs with different ABIs (eg freebsd can work with linux binaries to a degree) - however, the core binaries (eg the init program, the module loader, device driver setup tools, the C library, the tools needed to setup the filesystems... ) will in practice have too much need-to-know about kernel level interfaces to boot a system with a foreign kernel successfully.

Also, filesystems would need to be compatible. Also, binary compatibility options would need to be compiled "hard" into the kernel - anything implemented as a kernel module would like fail because you could not run the module loader.

As mentioned, the user environments tend to be somewhat portable if you are willing to recompile - like freebsd-based debian systems, or setting up the netbsd pkgsrc system on linux (absolutely non trivial, but supported and possible!).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy