Skip to content

A complete workflow for Linux kernel development on Apple Silicon. This project provides a containerized toolchain to build the ARM64 Linux kernel and a minimal BusyBox-based initramfs, with a pre-configured QEMU setup for immediate testing on macOS.

Notifications You must be signed in to change notification settings

hassansys2/mac-docker-linux-kernel-arm64

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Linux Kernel Build & Run (ARM64) on macOS (Apple Silicon)

This guide documents a reproducible workflow to:

  • Build the Linux kernel (ARM64) using Docker
  • Build a BusyBox-based initramfs
  • Boot the kernel using QEMU (AArch64) on macOS (Apple Silicon / M1–M3)

System Requirements

Host (macOS)

  • macOS on Apple Silicon (M1 / M2 / M3)
  • Docker Desktop (Compose v2)
  • Homebrew
  • QEMU (AArch64)

Install QEMU:

brew install qemu

Directory Layout (Host)

.
├── docker-compose.yml
├── Dockerfile
├── linux/
├── out/
├── initramfs/
└── initramfs.cpio.gz

Step 1: Build Kernel Builder Image

docker compose -f docker-compose.yml build

Step 2: Enter Builder Container

docker compose -f docker-compose.yml run --rm kernel-builder

Or one-shot build:

docker compose run --rm kernel-builder make -C /work/linux O=/work/out ARCH=arm64 -j$(nproc)

Step 3: Build Linux Kernel

cd /work

git clone --depth 1 --branch v6.12 https://github.com/torvalds/linux.git
# or git clone --depth 1 https://github.com/torvalds/linux.git

cd linux
# if you have older linux cloned folder to cleanup
# or git clean -idx for intractive clean
git clean -fdx 

make ARCH=arm64 O=/work/out defconfig
make ARCH=arm64 O=/work/out -j$(nproc)

Kernel image produced:

/work/out/arch/arm64/boot/Image

Step 4: Build BusyBox (Static)

clone BusyBox → /work/busybox

cd /work

git clone --depth 1 --branch 1_37_0 https://github.com/mirror/busybox.git
# or git clone https://github.com/mirror/busybox.git

cd busybox
make distclean
make defconfig ARCH=arm64
make menuconfig

BusyBox Fixes (ARM64)

Disable:

  • Settings → SHA1/SHA256 hardware acceleration
  • Networking Utilities → tc

Enable static build:

sed -i.bak 's/# CONFIG_STATIC is not set/CONFIG_STATIC=y/' .config

Build and install:

make ARCH=arm64 -j$(nproc)
make ARCH=arm64 CONFIG_PREFIX=/work/initramfs install

This installs BusyBox into:

/work/initramfs/{bin,sbin,usr/bin,...}


Step 5: Create an /init script (the first userspace process)

cat > /work/initramfs/init <<'EOF'
#!/bin/sh

# 1. Mount basic filesystems
mkdir -p /proc /sys /tmp
mount -t proc none /proc
mount -t sysfs none /sys
mount -t tmpfs none /tmp

# 2. Mount devtmpfs FIRST
# This populates /dev with device nodes like console, null, etc.
mount -t devtmpfs none /dev

# 3. NOW create pts inside the newly mounted /dev and mount devpts
mkdir -p /dev/pts
mount -t devpts none /dev/pts

echo "Booted into initramfs!"
echo "Kernel: $(uname -a)"

# drop into a shell
# exec /bin/sh
# cttyhack detects the console and runs the shell with a controlling terminal
exec setsid cttyhack /bin/sh
EOF

Step 5: Make init script executable

chmod +x /work/initramfs/init

Step 6: Create initramfs

cd /work/initramfs

# mkdir -p proc sys dev dev/pts tmp # Not required as init script will do it
find . -print0 | cpio --null -ov --format=newc | gzip -9 > /work/initramfs.cpio.gz

# exit from container
exit

Now you have:

  • /work/out/arch/arm64/boot/Image
  • /work/initramfs.cpio.gz

Step 7: Boot with QEMU (on your Mac host)

qemu-system-aarch64 \
  -machine virt \
  -cpu cortex-a72 \
  -m 2048 \
  -nographic \
  -kernel ./out/arch/arm64/boot/Image \
  -initrd ./initramfs.cpio.gz \
  -append "console=ttyAMA0 loglevel=8 rdinit=/init"

Exit QEMU:

Ctrl + A, then X

Done 🎉

You are now running a custom ARM64 Linux kernel in QEMU on macOS.

About

A complete workflow for Linux kernel development on Apple Silicon. This project provides a containerized toolchain to build the ARM64 Linux kernel and a minimal BusyBox-based initramfs, with a pre-configured QEMU setup for immediate testing on macOS.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published