I got a local LLM running on a Raspberry Pi Zero 2 W with no operating system. There’s no Linux: llama.cpp sits directly on top of Circle, a bare-metal environment, and runs Qwen2.5-0.5B in 512MB of RAM. Compared with Raspberry Pi OS, it’s only about 10% faster, but it has far more free memory and the speed stays steady.
TL;DR#
- llama.cpp runs without an OS. Its source needed almost no changes. The work went into the layers underneath: threads,
malloc, and file reads. - Generation went from 6.90 tok/s on Raspberry Pi OS Lite to 7.50 tok/s on bare metal (3 threads), and prompt processing from 28.03 to 30.75 tok/s (4 threads). Generation speed is set by how fast the weights can be read from memory, so removing the OS doesn’t make it dramatically faster.
- The bigger difference is memory: about 340MiB free on Pi OS versus about 460MB on bare metal, with no swapping.
- That headroom is what let me fit Sarashina2.2-0.5B-instruct, a model that’s good at Japanese. Its weights alone wouldn’t fit in the free memory on Pi OS.
- Model load time from the SD card went from 86 seconds to 16.7 seconds.
Why bare metal#
It started with an article (in Japanese) about “asm-llm-os”, an OS of about 24KB written entirely in assembly that boots straight into Qwen3-0.6B. That one only runs on x86-64, so I wanted to try the same thing on a 512MB ARM board.
Right now the result is a dedicated chat device: you power it on and talk to it in Japanese from a Mac, and a character named “Pico” answers. This post covers what it took to get it running without an OS, and how much the speed differs with an OS (Raspberry Pi OS Lite) and without one.
By the way, I built this almost entirely together with Claude Code. My job was mostly deciding the direction, swapping SD cards, and power-cycling the board.
The setup#
- Board: Raspberry Pi Zero 2 W (4× Cortex-A53 at 1GHz, 512MB RAM)
- Bare-metal environment: Circle and circle-stdlib
- Inference engine: llama.cpp
- Model: Qwen2.5-0.5B-Instruct, Q4_0
- Development from a Mac. Builds run in Docker, and kernels are sent over UART through a USB-to-serial adapter
Circle, llama.cpp, and the app are statically linked into a single kernel8.img. The SD card holds only the firmware and the model. Whether you’d call this an OS is debatable, but you could say it’s an OS whose only job is running an LLM.
Raspberry Pi Zero 2 WHAd
Raspberry Pi
As an Amazon Associate, Checkela Log earns from qualifying purchases.
The baseline: Raspberry Pi OS Lite#
Without a baseline I couldn’t say whether anything got faster, so I first ran llama-bench on Raspberry Pi OS Lite (64-bit). The llama.cpp commit, build options, and model all match the bare-metal build. Building on the Pi itself is painfully slow, so I built in Docker on the Mac (arm64 Debian), which takes 1 minute 50 seconds.
The model is Q4_0, with the output layer and embeddings also lowered to Q4_0 (338MiB). The best generation speed was 6.90 tok/s with 3 threads. Turning on repack (rearranging the weights into a CPU-friendly layout) makes each thread about 1.8× faster, and speed tops out at 3 threads. That’s the memory bandwidth wall; working backward from the numbers gives about 1.8GiB/s.
The catch is that Pi OS leaves only about 340MiB of free memory. Repack duplicates the weights, which triggers swapping (zram), and in 5 runs, 2 dropped to 5.0 tok/s. Counting only the runs without swapping, 3 threads gives about 6.6 tok/s. Loading the whole model into RAM (no mmap) got the process killed by the OOM killer.
Getting it running without an OS#
Booting Circle#
First I put Circle’s sample kernel8.img (86KB) on the SD card and checked that “Circle 51.1.1 started on Raspberry Pi Zero 2 W 512MB (AArch64)” appeared on the UART.
Rewriting the SD card every time is a pain, so I installed Circle’s serial bootloader and send kernels over the UART instead. On macOS, Circle’s upload tool only handled up to 230400bps, so I patched it, and I now send at 3Mbps. Transferring a 6.6MB kernel went from about 3.5 minutes to about 1 minute.
When I first switched to 3Mbps, the bootloader went silent. The cause was that the UART clock value the firmware measures wobbled between 48,000,000 and 47,999,000 from boot to boot. The divisor for 3Mbps is exactly 1, so a slightly low clock truncated it to 0. Rounding instead of truncating fixed it.
One more trap I fell into: the CPU runs at 600MHz right after boot. Unless you raise it to 1GHz, memory reads are also about 20% slower.
On plain Circle, the free heap right after boot is 473MB. Even after allocating 400MB in one go, 73MB is left. DRAM read bandwidth peaks at 2375MB/s with 2 cores. From that, the ceiling for generation speed works out to about 8.5 tok/s.
Porting ggml#
Next was ggml, the compute part of llama.cpp. The build stopped about seven times. Mostly it was just newlib not exposing its POSIX declarations for Circle. Here’s what I dealt with:
- pthread: wrote a tiny implementation that, when you create a thread, just hands the work to a free core
dlfcn.h: provided adlopenthat always fails (fine, because the CPU backend is linked in statically)stdatomic.h: with gcc 15, newlib’s version is picked up first andatomic_intisn’t defined, so I made it use gcc’sclock_gettimeand the pthread declarations: defined_POSIX_TIMERSand friendsposix_memalign: implemented withmemalign
Benchmarking a Q4_0 matrix-vector multiply gave 2328MB/s with repack and 3 threads, almost exactly the 2375MB/s memory bandwidth ceiling.
The interesting part: even without an OS, 4 threads were slower than 3. I had assumed 4 threads not helping on Pi OS was the OS’s fault, but it’s a property of the memory side.
Porting the rest of llama.cpp#
llama.cpp itself ran with almost no changes to its source. Memory is where most of the time went.
Circle’s malloc never reuses freed blocks larger than 512KB, and it rounds small blocks up to units like 1KB. As a result, just loading the vocabulary used up all the memory. I rewrote malloc and ran randomized allocate/free tests with AddressSanitizer on the Mac before putting it on the Pi. I’d never paid much attention to how malloc is implemented, so it was an eye-opener that this kind of thing can happen.
I also worked around a few other things: the thread-less libstdc++ has no real implementation of std::future, and ggml’s scheduler allocates about 45MB up front (on Linux, untouched memory doesn’t use real RAM).
With that, the model loaded from the SD card, and here are the first words it spoke without an OS:
あそぶは、毎朝の朝食を食べようという言葉です。
(Roughly: “Asobu [to play] is a word that means let’s eat breakfast every morning.”) It’s nonsense, but it’s the same kind of nonsense I got on Pi OS, so I could tell the same thing was running.
Removing the duplicate output layer: 7.50 tok/s#
At this point, generation was stuck at 6.90 tok/s, the same as Pi OS. Digging in, Qwen2.5-0.5B shares its output layer with its embeddings, and the GGUF file contained the same 73MB twice. Their sha256 hashes match, too.
There wasn’t enough memory to repack the output layer, so I removed it from the file and put a small patch on llama.cpp’s loader: read the 73MB once, then rearrange it from there. That brought 3-thread generation to 7.50 tok/s, finally beating Pi OS.
The first version of this patch hung silently on the Pi. The UART log was cut off partway, so I couldn’t tell where it stopped. Building the same code on the Mac with AddressSanitizer and running it pointed at the offending line on the first try. When something fails invisibly on the Pi, the quickest route is to bring it to the Mac and make it fail there.
Loading from the SD card faster: 86 s to 16.7 s#
The other thing that bothered me was model load time. At first it took 86 seconds.
The culprit was newlib’s fread. Its internal buffer was only 1KB, so even when asked for a big read, it went to the SD card 1KB at a time. Without touching llama.cpp, I intercepted fopen at link time and attached a bigger buffer. I hadn’t known a bottleneck could hide in a place like this, either.
I started with 1MB, but the buffer gets refilled in full on every seek, so small tensors read far more than they need. I settled on 64KB. I also changed the loader to read weights in file order, and loading ended up at 16.7 seconds. The weight read speed is now quite close to the SD card’s sequential read limit (20.7MB/s).
Overclocking the SD card beyond spec would shrink it further, but I decided not to go that far.
With an OS vs. without: about 10% faster, much more memory#
Both use Qwen2.5-0.5B-Instruct Q4_0 and the same llama.cpp commit.
| Item | Pi OS Lite | Bare metal |
|---|---|---|
| Free memory | ~340MiB | ~460MB |
| Loading the whole model into RAM | Killed by OOM | Works |
| Generation (3 threads) | 6.90 tok/s | 7.50 tok/s |
| Prompt processing (4 threads) | 28.03 tok/s | 30.75 tok/s |
| Run-to-run variation | Drops to ~5.0 on runs that swapped | ±0.06 or less |
The speed difference is about 10%. Prompt processing is faster by the amount the OS’s interrupts and swapping used to cost, and generation benefits from removing the duplicate output layer. Generation speed is set by how fast the weights can be read from memory, so removing the OS doesn’t make it dramatically faster.
Memory is where the difference is large. On Pi OS, the kernel side (including the 64MiB CMA reservation) takes a lot, leaving about 340MiB free. On bare metal about 460MB is free, and with no swapping, the speed stays steady.
Response quality doesn’t depend on the OS#
With the same model and the same weights, going bare metal doesn’t change what the model says. Even after repacking the output layer, Pico’s reply was the same breakfast sentence, character for character.
The real problem is the 0.5B model itself: Qwen2.5-0.5B’s replies often don’t make sense. When I narrowed down the cause, the biggest factor was that I’d been talking to it in hiragana only (Japanese written phonetically, without kanji). Asking “にほんのしゅとはどこ?” (“Where is Japan’s capital?” in hiragana) got rambling that had nothing to do with capitals, but asking “日本の首都はどこ?” (the same question with kanji) got “日本の首都は、東京です。” (“Japan’s capital is Tokyo.”). Just switching to kanji tripled the number of replies that made sense. Quantization also cost 30–40%.
So I left Japanese input to the IME (the input method) on the Mac side, and switched to Sarashina2.2-0.5B-instruct, a model that’s strong in Japanese. At Q4_0, though, it’s 483MB and doesn’t fit on the Pi as is. I built an imatrix from Japanese text, shrank the model to 3-bit-class quantization (Q3_K_S, 345MiB), and blocked tokens containing non-Japanese characters such as English. In an evaluation on the Mac, 34 of 36 replies made sense.
On the Pi it fit with 47MB of free memory to spare. Its weights alone wouldn’t fit in the roughly 340MiB free on Pi OS, so this may be where dropping the OS paid off most.
Speed is 3.4 tok/s with 4 threads, about half of Qwen. The Cortex-A53 lacks the dotprod instruction, so Q3_K can’t use repack and is compute-bound; unlike Qwen, 4 threads are faster. On the other hand, Sarashina packs about 2 Japanese characters into each token, so in characters it’s about 7 per second, not far from Qwen’s 8–9 per second.
Ask “日本の首都はどこ?” (“Where is Japan’s capital?”) and it answers “日本の首都は東京だよ。ピコも東京が大好きなんだ。” (“Japan’s capital is Tokyo. Pico loves Tokyo too!”). That’s Pico, really talking from inside the Pi.
Here’s what it looks like in action. I’m talking to it over UART from a terminal on the Mac.

It adds things nobody asked about, like “首都大学東京という大学も近くに存在しているんだ” (“There’s also a university nearby called Tokyo Metropolitan University” — the name literally contains “capital” and “Tokyo”), which feels very 0.5B.
What’s next#
Two issues remain: replies run long, and after the context fills up and resets, Pico still says “yes, I remember.” I plan to keep improving these bit by bit.
Reply by Email

