Tech News
← Back to articles

Building Linux kernel on macOS natively

read original related products more articles

I've recently added a Linux compatibility layer to Starina operating system based on a lightweight VM approach similar to WSL2.

I can cross-compile its init program with Cargo. I can prepare a container image contents using skopeo. However, I need to build the genuine Linux kernel, preferably on my daily driver: macOS.

The most common way to build Linux kernel on macOS would be using Docker Desktop, and that works fine. I know nobody need to build on macOS natively, but it looked possible - there are 2 previous attempts before (1 and 2).

Tested with Linux version 6.12.34 and macOS version 15.5 (Sequoia). RISC-V is chosen here because Starina OS supports it, and it's a good example of cross compilation.

TL;DR: It works. Use this patch.

make is too old

First of all, I need to generate a minimal kernel configuration, and I got the following error:

$ make ARCH=riscv allnoconfig Makefile:15: *** GNU Make >= 4.0 is required. Your Make version is 3.81. Stop.

This is a typical issue for macOS users. GNU packages are shipped with macOS, but the version is typically very old. Fortunately, Homebrew can help us. Install make package from Homebrew and use the binary with gmake :

$ brew install make $ gmake ARCH=riscv allnoconfig HOSTCC scripts/kconfig/conf.o HOSTCC scripts/kconfig/confdata.o HOSTCC scripts/kconfig/expr.o HOSTCC scripts/kconfig/lexer.lex.o HOSTCC scripts/kconfig/menu.o HOSTCC scripts/kconfig/parser.tab.o HOSTCC scripts/kconfig/preprocess.o HOSTCC scripts/kconfig/symbol.o HOSTCC scripts/kconfig/util.o HOSTLD scripts/kconfig/conf ld: unknown options: --version ld: unknown linker scripts/Kconfig.include:57: Sorry, this linker is not supported.

... continue reading