frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Booting Linux in QEMU and Writing PID 1 in Go to Illustrate Kernel as Program

https://serversfor.dev/linux-inside-out/the-linux-kernel-is-just-a-program/
113•birdculture•6d ago

Comments

tombert•4h ago
I love blog posts like this. You're not wrong in saying that the kernel is sort of this magical block box to most engineers (including me). I know how to use systemd and I know how to use bash and I know a few other things, but the kernel has always been "the kernel", and it's something I've never really tried to mess with. But you're right: ulimately the kernel is just a program. Yes, it's a big and important program that works at a lower level than I typically work at, but it's probably not something that is impossible for me to learn some basic stuff around.

I have had a bit of a dream of building a full desktop operating system around seL4 [1], with all drivers in user space and the guts fully verified in Isabelle, but learning about this level of code kind of feels like drinking from a firehose. I would like to port over something like xserver and XFCE and go from there, but I've never made a proper attempt because of how overwhelming it feels.

[1] I know about sculpt and Genode, and while those are interesting, not quite what I want.

ronsor•4h ago
You can actually disable most features of the Linux kernel, including multi-user support (everything will run as root). The end result is a stripped down kernel fit for only running your single desired application.
TZubiri•4h ago
It reminds me of when people speak of money as a product. Sure, maybe you are right, but I think more of it as something in relation to products/programs than as a product/program itself.

The fact that it's also a product/program is some brainfucky exercise that might either be an interesting hobby thought experiment OR it might be a very relevant nuance that will be useful to the top 0.1% of professionals who need a 99.9% accuracy, like the difference between classical and relativistic mechanics.

I mean, sure you are right that kernels are programs and that money is a product, and that gravity is not a force. But I am a mere mortal and I will stick to my incorrect and incomplete mental model at a small expense of accuracy to the great advantage of being comprehensible.

bitwize•3h ago
Try working on NetBSD or OpenBSD. You can learn kernel hacking by literally reading the man pages. Changing, rebuilding,and booting your own custom kernel is tremendously exciting.
peddling-brink•4h ago
Ahh, this was really cool. I’m not sure I understand the kernel much better, but init and the concept of an operating system make a lot more sense.

I’d love a similarly styled part two that dives into making a slightly useful distro from “scratch” in go.

geonineties•3h ago
I would say something a little different. The kernel is a _library_ that has an init routine you can provide the function for. Or put another way, without the kernel your go program would have to have drivers statically compiled into it. This was the world of DOS, btw.
charcircuit•3h ago
More importantly, a kernel is a platform. Conceptually it isn't that much different than other platforms such as Chrome or Roblox. They all have to care about the lifecycle of content, expose input events to content, allow content to render things, make sure bad things don't happen when running poorly programmed or malicous content, etc.
zsoltkacsandi•1h ago
> More importantly, a kernel is a platform.

Completely agree with this framing. We will get there by the end of the series.

sedatk•3h ago
I agree with your point, but I must correct you on DOS: it had device drivers too. :) That's how we used to access mouse input, CD drives, network, extended memory, etc. Yes, it sucked on the graphics and sound; every app basically had to reimplement its own graphics and audio layer from scratch, but the rest was quite abstracted away.
pastage•3h ago
This is a really clean write up, but it is absolutely a happy path. I do feel the kernel is too big to be called a program. It is almost everything you want from comp sci class, router, scheduler, queue, memory manager. There are some interesting things that you have to handle if you do not run and OS and init on hardware e.g. handle signals, how do you shutdown, reap child process. I believe you are always better off with an init process and an OS.
zsoltkacsandi•50m ago
> I do feel the kernel is too big to be called a program.

I kind of agree, but the kernel as a program serves a pedagogical framing here.

The goal of the post is to make it more tangible for developers, they write programs that are files on the disk, and you can interact with them. That's where the analogy came from.

fxbois•3h ago
Thank you for this quite perfect blog post (short, interesting, well written). One subject I would be interested in is what are all the parameters a kernel accepts
zoobab•3h ago
Is there a patch for systemd so that you can start it without PID1 monopoly?
drnick1•3h ago
It's a bit unnatural to use Go when C is the "native language" of Linux and pretty much every operating system.
cpach•3h ago
I mean what you run is still machine code anyway, right?
ktpsns•2h ago
Talos Linux [1], "the Kubernetes Operating System", is written in Go. That means it exactly works as the little demo here, where the Kernel hands over to a statically compiled Go code as init script.

Talos is really an interesting linux distribution because it has no classical user space, i.e. there is no such thing as a $PATH including /bin, /usr/bin, etc. The shell is instead a network API, following the kubernetes configuration-as-code paradigm. The linux host (node) is supposed to run containerized applications. If you really want to, you can use a special container to get access to the actual user space from the node.

[1] https://www.talos.dev/ [2] https://github.com/siderolabs/talos/releases/tag/v1.11.5

preisschild•45m ago
I also use Talos, but I wonder if just using systemd for the init process wouldn't have been easier. You can interface with systemd in go quite easily anyways...
cpach•43m ago
s6 (perhaps with s6-rc) is another interesting option. One could say it’s less opinionated than systemd. Or perhaps it’s more correct to say it has another set of opinions.
zsoltkacsandi•46m ago
The goal was to strip away most of the complexities (including C), to make the topic more approachable for a broader audience.

Go seemed a perfect fit, it is easy to pick up the syntax and see what is going on, but you can still be close to the OS.

themafia•28m ago
Go can speak C. It's fine.
mrbluecoat•2h ago
> If you ever wondered what this name means: vmlinuz: vm for virtual memory, linux, and z indicating compression

Thank you. I have always wondered that.

alexellisuk•2h ago
Interesting starter post.. I took this one step further a few years ago to make the init mount various other /proc /sys etc filesystems and boot up with Firecracker - using a container image as a rootfs.. GitHub https://github.com/alexellis/firecracker-init-lab Blog post: https://actuated.com/blog/firecracker-container-lab
CSDude•2h ago
I had a similar experiment ~10yr ago, see relevant discussion https://news.ycombinator.com/item?id=11064694

And updated domain: https://mustafaakin.dev/posts/2016-02-08-writing-my-own-init...

westurner•1h ago
Systemd service unit and systemd-nspawn support could be written in Go, too;

From https://news.ycombinator.com/item?id=41270425 re: "MiniBox, ultra small busybox without uncommon options":

> There's a pypi:SystemdUnitParser.

> docker-systemctl-replacement > systemctl3.py parses and schedules processes defined in systemd unit files: https://github.com/gdraheim/docker-systemctl-replacement/blo...

From a container2wasm issue about linux-wasm the other day: https://github.com/container2wasm/container2wasm/issues/550#... :

> [ uutils/uucore, uutils/coreutils, uutils/procps, uutils/util-linux, findutils, diffutils, toybox (C), rustybox, ]

WesolyKubeczek•1h ago
Can anyone explain why CGO_ENABLED needs to be set to 1 here?
zsoltkacsandi•34m ago
In the post it is set to 0. `CGO_ENABLED=0 go build -o init .`

The only reason is because I like to be explicit, and I could not know what was set before in the user's environment.

zsoltkacsandi•1h ago
Author here. It was a bit emotional seeing this on the front page.

My goal with this post and the whole (work in progress) series is to fill the gap between "here are the commands to do X" and "if you want to contribute to the kernel, you need to learn this" style books and tutorials.

I want something in between, for developers who just want a solid mental model of how Linux fits together.

The rough progression I have in mind is:

1. the Linux kernel as "just a program"

2. system calls as the kernel's API

3. files as resources manipulated through system calls, forming a consistent API

4. the filesystem hierarchy as a namespace system, not a direct map of disk layout

5. user/group IDs and permissions as the access control mechanism for resources (files)

6. processes, where all of the above comes together

I deliberately chose Go for the examples instead of C because I want this to be approachable to a broader audience of developers, while still being close enough to the OS to show what's really going on.

As a developer, this kind of understanding has been incredibly useful for me for writing better software, debugging complex issues with tools like strace and lsof, or the proc fs. I would like to help others to gain the same knowledge.

potato-peeler•38m ago
Can you also consider adapting Linux from scratch as a part of this series? Or Maybe after this series, you can expand what is learnt to build a minimal Linux distribution. I suppose that might give a good understanding on how to apply this knowledge and a have a foundation on the internals of the os itself.
preisschild•34m ago
Another "interesting" related thing I found is that pid 1 signals are handled differently in the kernel. Basically, SIGTERM is ignored and you need to explicitly handle it in your program. Took me quite a while before I found out why my program in a container didn't quit gracefully...

https://raby.sh/sigterm-and-pid-1-why-does-a-container-linge...

gr4vityWall•27m ago
The writing is really succinct and easy to follow.

One thing that could be improved is that the author could break down some of the commands, and explain what their arguments mean. For example:

> mknod rootfs/dev/console c 5 1

Depending on the reader's background, the args 'c', '5', and '1' can look arbitrary and not mean much. Of course, we can just look those up, and it doesn't make the article worse.

jkrejcha•19m ago
A fun little tidbit, if you don't provide an init to the kernel command line, it'll try to look for them in a few places in this order:

1. /sbin/init

2. /etc/init

3. /bin/init

4. /bin/sh

It dropping you into a shell is a pretty neat little way to allow recovery if you somehow really borked your init

akpa1•10m ago
I love that it's possible to boot a raw Linux kernel this way; I only learned about it very recently when working on a university project. It makes me want to fiddle around with it more and really understand the nuts and bolts of a modern Linux system and work out what actually is responsible for what and, crucially, when it happens.

Size of Life

https://neal.fun/size-of-life/
2050•eatonphil•19h ago•221 comments

A "Frozen" Dictionary for Python

https://lwn.net/SubscriberLink/1047238/25c270b077849dc0/
16•jwilk•1h ago•0 comments

The Cost of a Closure in C

https://thephd.dev/the-cost-of-a-closure-in-c-c2y
78•ingve•3h ago•19 comments

Getting a Gemini API key is an exercise in frustration

https://ankursethi.com/blog/gemini-api-key-frustration/
560•speckx•14h ago•228 comments

Patterns.dev

https://www.patterns.dev/
296•handfuloflight•9h ago•73 comments

Australia begins enforcing world-first teen social media ban

https://www.reuters.com/legal/litigation/australia-social-media-ban-takes-effect-world-first-2025...
787•chirau•1d ago•1195 comments

Booting Linux in QEMU and Writing PID 1 in Go to Illustrate Kernel as Program

https://serversfor.dev/linux-inside-out/the-linux-kernel-is-just-a-program/
113•birdculture•6d ago•32 comments

How the Brain Parses Language

https://www.quantamagazine.org/the-polyglot-neuroscientist-resolving-how-the-brain-parses-languag...
26•mylifeandtimes•2d ago•6 comments

Auto-grading decade-old Hacker News discussions with hindsight

https://karpathy.bearblog.dev/auto-grade-hn/
453•__rito__•17h ago•205 comments

Why Startups Die

https://www.techfounderstack.com/p/why-startups-die
13•makle•3d ago•5 comments

Python Workers redux: fast cold starts, packages, and a uv-first workflow

https://blog.cloudflare.com/python-workers-advancements/
64•dom96•2d ago•15 comments

Go's escape analysis and why my function return worked

https://bonniesimon.in/blog/go-escape-analysis
11•bonniesimon•6d ago•6 comments

VCMI: An open-source engine for Heroes III

https://vcmi.eu/
109•eamag•4d ago•14 comments

How Google Maps allocates survival across London's restaurants

https://laurenleek.substack.com/p/how-google-maps-quietly-allocates
272•justincormack•2d ago•131 comments

Incomplete list of mistakes in the design of CSS

https://wiki.csswg.org/ideas/mistakes
123•OuterVale•6h ago•73 comments

Rubio stages font coup: Times New Roman ousts Calibri

https://www.reuters.com/world/us/rubio-stages-font-coup-times-new-roman-ousts-calibri-2025-12-09/
285•italophil•1d ago•478 comments

Super Mario 64 for the PS1

https://github.com/malucard/sm64-psx
233•LaserDiscMan•16h ago•91 comments

Fossils reveal anacondas have been giants for over 12 million years

https://www.cam.ac.uk/stories/twelve-million-years-of-giant-anacondas
49•ashishgupta2209•1w ago•21 comments

Qwen3-Omni-Flash-2025-12-01:a next-generation native multimodal large model

https://qwen.ai/blog?id=qwen3-omni-flash-20251201
270•pretext•19h ago•95 comments

Show HN: Wirebrowser – A JavaScript debugger with breakpoint-driven heap search

https://github.com/fcavallarin/wirebrowser
31•fcavallarin•20h ago•8 comments

Show HN: Automated license plate reader coverage in the USA

https://alpranalysis.com
182•sodality2•17h ago•105 comments

Flow Where You Want – Guidance for Flow Models

https://drscotthawley.github.io/blog/posts/FlowWhereYouWant.html
19•rundigen12•5d ago•1 comments

McDonald's removes AI-generated ad after backlash

https://www.theguardian.com/business/2025/dec/11/mcdonalds-removes-ai-generated-christmas-ad-adve...
7•terabytest•21m ago•1 comments

Common Lisp, ASDF, and Quicklisp: packaging explained

https://cdegroot.com/programming/commonlisp/2025/11/26/cl-ql-asdf.html
84•todsacerdoti•1d ago•20 comments

Scientists create ultra fast memory using light

https://www.isi.edu/news/81186/scientists-create-ultra-fast-memory-using-light/
99•giuliomagnifico•6d ago•24 comments

Valve: HDMI Forum Continues to Block HDMI 2.1 for Linux

https://www.heise.de/en/news/Valve-HDMI-Forum-Continues-to-Block-HDMI-2-1-for-Linux-11107440.html
740•OsrsNeedsf2P•17h ago•410 comments

3D-printed carotid artery-on-chips for personalized thrombosis investigation

https://advanced.onlinelibrary.wiley.com/doi/10.1002/adma.202508890
20•PaulHoule•1w ago•2 comments

Terrain Diffusion: A Diffusion-Based Successor to Perlin Noise

https://arxiv.org/abs/2512.08309
129•kelseyfrog•16h ago•38 comments

Gundam is just the same as Jane Austen but happens to include giant mech suits

https://eli.li/gundam-is-just-the-same-as-jane-austen-but-happens-to-include-giant-mech-suits
216•surprisetalk•1w ago•147 comments

Is it a bubble?

https://www.oaktreecapital.com/insights/memo/is-it-a-bubble
243•saigrandhi•17h ago•378 comments