Skip to content

About

MinOS for containers

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

MinOS

A minimal, container-native operating system built from scratch in C.

MinOS boots a custom Linux kernel into a compressed SquashFS read-only root, layers an OverlayFS writable upper layer on top, and runs a hand-written init binary as PID 1. Containers are isolated using Linux namespaces, cgroup v2 resource limits, and a seccomp BPF syscall whitelist — all implemented without any container framework.


Features

Feature Implementation
Custom init (PID 1) init/ — mounts filesystems, starts supervisor
Service supervisor supervisor/ — auto-restart, service configs
Container runtime (minc) runtime/ — namespaces, OverlayFS, pivot_root
cgroup v2 resource limits cgroup/ — memory, PID, CPU enforcement
Host bridge + NAT setup netd/ — creates osBr0, enables IP forwarding at boot
Seccomp BPF filter runtime/seccomp.c — ~165 syscall whitelist
Session multiplexer (mintab) tools/mintab.c — multiple containers simultaneously
Network / cgroup diagnostics tools/netstat.c, tools/nslist.c, tools/cginspect.c — interface, namespace, and cgroup inspection
Python 3.12 in containers build/setup-langs.sh — musl-linked static binary
SquashFS + OverlayFS root build/mksquashfs.sh, initramfs-stage1/

Architecture

┌──────────────────────────────────────────────────┐
│              User Programs                       │
│   minc  │  mintab  │  python3  │  /bin/sh        │
├──────────────────────────────────────────────────┤
│   Supervisor  (service manager, auto-restart)    │
├──────────────────────────────────────────────────┤
│   init  (PID 1, hand-written C, no systemd)      │
├──────────────────────────────────────────────────┤
│   SquashFS (read-only) + OverlayFS (writable)    │
├──────────────────────────────────────────────────┤
│   Linux Kernel (custom minimal config)           │
└──────────────────────────────────────────────────┘

Boot sequence:

  1. QEMU loads kernel + initramfs (stage 1)
  2. Stage-1 shell script finds and mounts SquashFS → /squash
  3. OverlayFS is mounted: lower=/squash, upper=ext4 partition
  4. switch_root → custom /sbin/init
  5. init mounts /proc, /sys, /dev, /run, /tmp, cgroups
  6. Supervisor starts: cgmgr, netd, mintab, console (shell)

Project Structure

MinOS/
├── init/               # PID 1 — mount, signals, zombie reaping
├── supervisor/         # Service manager — spawn, parse, restart
├── runtime/            # minc container runtime
│   ├── minc.c          # CLI — arg parsing, container lifecycle
│   ├── spawn.c         # clone() — PID/MNT/NET/UTS/IPC namespaces
│   ├── rootfs.c        # OverlayFS setup + pivot_root
│   ├── seccomp.c       # BPF syscall whitelist
│   └── namespace.c     # uid/gid map helpers for CLONE_NEWUSER —
│                        # written but not wired into clone() yet
├── cgroup/             # cgmgr daemon — cgroup v2 limits
├── netd/               # host bridge + NAT setup at boot; per-container
│                        # veth attachment exists (bridge.c, veth.c) but
│                        # isn't called from runtime/ yet — see below
├── tools/
│   ├── mintab.c        # PTY session multiplexer
│   ├── nslist.c        # Namespace isolation inspector
│   ├── cginspect.c     # cgroup v2 resource tree viewer
│   ├── memhog.c        # Memory stress tool (cgroup OOM demo)
│   ├── netstat.c       # Interface / bridge / veth status
│   └── demo.sh         # Container feature demo script
├── projects/
│   ├── sysmon/         # TUI process/resource monitor
│   └── pyrun/          # Container-gated Python demo runner
├── build/
│   ├── mkdisk.sh       # Assemble bootable disk image
│   ├── mksquashfs.sh   # Pack rootfs into SquashFS
│   ├── mkrootfs.sh     # Compile all binaries + assemble rootfs/
│   ├── setup-langs.sh  # Stage Python 3.12 + TCC into rootfs/
│   └── verify.sh, check_phases.sh  # Post-build integrity checks
├── initramfs-stage1/   # Busybox initramfs — mounts SquashFS + overlay
├── syslinux/           # Bootloader config
├── services.d/         # Service configs (cgmgr, netd, mintab) — console's
│                        # config is synthesized at build time, not stored here
├── kernel/             # Kernel config (bzImage not tracked — too large)
└── rootfs/             # Staged OS root (generated by make)

Building

Prerequisites (Ubuntu / WSL2)

sudo apt update
sudo apt install gcc make squashfs-tools syslinux-utils \
                 qemu-system-x86 busybox-static rsync cpio

Build and Run

# 1. Stage language runtimes (Python 3.12 — downloads ~50 MB, one-time)
bash build/setup-langs.sh

# 2. Build disk image (compiles all C, packs SquashFS, writes disk)
make image

# 3. Boot in QEMU
make test

Note: The kernel (kernel/bzImage) is not tracked in git — it's 14 MB.
Build it with your kernel config or download a pre-built one.


Container Usage

Run a one-shot command

minc run /bin/sh -c "hostname && ps"

Interactive shell in a container

minc run -t /bin/sh

Run Python inside a container

minc run /usr/bin/python3 /home/hello.py
minc run -t /usr/bin/python3 /home/todo.py

Multiple concurrent containers with mintab

# Start background sessions
mintab new minc run -t /bin/sh
mintab new minc run -t /usr/bin/python3 /home/todo.py

# List all running sessions
mintab list

# Attach to a session  (Ctrl+A then D to detach)
mintab attach 0
mintab attach 1

# Kill a session
mintab kill 0

Container Isolation

Each minc container gets:

Isolation Mechanism
Own PID tree (container = PID 1) CLONE_NEWPID
Own filesystem root CLONE_NEWNS + OverlayFS + pivot_root
Own hostname CLONE_NEWUTS
Own network stack CLONE_NEWNET
Own IPC CLONE_NEWIPC
Memory / PID limits cgroup v2 via cgmgr
Syscall restriction seccomp BPF whitelist
No capability escalation All capabilities dropped before exec

Current limitation: CLONE_NEWNET gives each container a genuinely isolated network namespace, but nothing currently attaches it to the host bridge — containers have loopback only, no outside connectivity yet. There is also no user-namespace UID/GID remap (CLONE_NEWUSER): containers run as literal host UID 0, so capability-drop + seccomp are the only privilege boundaries, not a mapped unprivileged UID as a backstop.


Language Runtimes

Run bash build/setup-langs.sh once before make image to stage:

  • Python 3.12 — musl-linked static binary from python-build-standalone
  • TCC — Tiny C Compiler, compiled statically, for in-container C execution

These are staged into rootfs/usr/ and excluded from git (too large).


Demo

# After booting:

# 1. Show OS identity
uname -a && ps

# 2. Container isolation
minc run /bin/sh -c "hostname && echo PID=\$\$"

# 3. Filesystem isolation (write inside, gone on host)
minc run /bin/sh -c "echo secret > /tmp/f && cat /tmp/f"
ls /tmp/f    # not here

# 4. Python in a container
minc run /usr/bin/python3 /home/hello.py

# 5. Multiple containers simultaneously
mintab new minc run -t /bin/sh
mintab new minc run -t /usr/bin/python3 /home/todo.py
mintab list
mintab attach 0   # Ctrl+A D to detach
mintab attach 1

What's NOT included

  • No systemd, no udev, no dbus
  • No glibc (Python uses musl; all OS binaries are statically linked)
  • No package manager
  • No kernel modules (monolithic minimal config)
  • No end-to-end container network connectivity yet — netd sets up the host bridge and NAT plumbing at boot, and per-container veth attachment is fully implemented (netd/bridge.c, netd/veth.c), but it isn't yet called from the container spawn path (runtime/spawn.c), so containers currently get an isolated-but-unconnected network namespace
  • No user-namespace UID/GID remapping — containers run as host UID 0; capability dropping and the seccomp filter are the only privilege boundaries
  • No checksum/signature verification on the staged Python/TCC toolchains downloaded by build/setup-langs.sh

About

MinOS for containers

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages