162
submitted 1 day ago by zknd@lemmy.world to c/linux@lemmy.ml

I’ve been working on a "Linux Inside Out" series and wrote a post that might interest folks here who like low(ish)-level / OS internals.

The idea is to dissect the components of a Linux OS, layer by layer, and build a mental model of how everything fits together through experiments.

The first part is about the kernel, in the post I:

  • take the same kernel image my distro boots from /boot
  • boot it directly with QEMU (no distro, no init system)
  • watch it panic
  • write a tiny Go program and use it as PID 1
  • build a minimal initramfs around it so the kernel can actually start our process

The goal isn’t to build a real distro, just to give a concrete mental model of:

  • that the Linux kernel is just a compressed file, you can boot it
  • without anything else
  • what the kernel actually does at boot
  • how it hands control to userspace
  • what PID 1 / init is in practice
  • what is kernel space vs user space

Link: https://serversfor.dev/linux-inside-out/the-linux-kernel-is-just-a-program/

I’m the author, would be happy to hear from other devs whether this way of explaining things makes sense, and what you’d add or change for future posts in the series.

Hope you find it useful.

top 17 comments
sorted by: hot top controversial new old
[-] utopiah@lemmy.ml 3 points 16 hours ago

Nitpicking but a line is missing IMHO namely The code of the program: should also suggest which file to edit, e.g potato.go. It might be obviously to anybody working with Go but for others it's not.

[-] Quazatron@lemmy.world 3 points 16 hours ago

I'm old enough to remember UML (User Mode Linux). I don't know if it's still around, but it was a port of the Linux kernel that you would run as a standard user binary.

[-] Goodman@discuss.tchncs.de 5 points 20 hours ago

I took kernel device driver programming as a course in uni. They were still teaching the device driver course but not the operating system course you were supposed to take before that. Always felt like I have been systematically lacking that knowledge because of that. I'm interested!

[-] MonkderVierte@lemmy.zip 2 points 17 hours ago* (last edited 17 hours ago)

I like the "take things appart, recombine, look what breaks" approach, same line of thought.

Btw, i think the current tech stack (CPU, initram, X/Wayland server, input handling, pam/polkit) is just shoehorned Desktop on tech made for server and a lot of historical baggage.

[-] Hyunta@discuss.tchncs.de 16 points 1 day ago

It's pretty cool and a nice way to discover the kernel!

[-] utopiah@lemmy.ml 2 points 20 hours ago
[-] utopiah@lemmy.ml 2 points 18 hours ago* (last edited 18 hours ago)

FWIW makes me wonder how much work would be required to have this as a Web container, e.g. Dockerfile with

FROM debian:13
RUN apt update && apt install -y qemu-system-x86 qemu-utils
WORKDIR /linux-inside-out

then https://github.com/container2wasm/container2wasm#container-on-browser

Edit: FWIW the image of Debian 13 with QEMU and its utils is ~1.1Gb

[-] brownmustardminion@lemmy.ml 4 points 1 day ago

This is amazing. Thank you!

[-] Farnsworth@lemmy.world 2 points 22 hours ago

Bookmarked 😜 Mind adding a dark mode?

[-] zknd@lemmy.world 1 points 20 hours ago

Thank you! :) Sure, working on it. :)

[-] MonkderVierte@lemmy.zip 2 points 17 hours ago

Ah, please utilize prefers-color-scheme and just place your --color-variables in it, if possible. It's the simplest and most compatible way.

[-] rubdos@lemmy.zip 7 points 1 day ago

Cool! Looking forward to the next post. I'd love to learn about how the kernel and initramfs work together though. For now the magic seems to be in how qemu strings things together.

[-] Klumz@feddit.dk 5 points 1 day ago

Very cool guide, got the kernel running! Looking forward to your next post!

[-] ch00f@lemmy.world 3 points 1 day ago

You got a subscriber! Looking forward to more.

[-] non_burglar@lemmy.world 0 points 1 day ago* (last edited 1 day ago)

Are you just reverse-engineering this for fun, or are you trying to learn how qemu builds on a bootstrap?

[-] zknd@lemmy.world 3 points 18 hours ago

I am writing a blog post series to make this topic more approachable for others.

[-] non_burglar@lemmy.world 3 points 12 hours ago

Nice, and good job.

With respect:

  • You are describing the init process, after the boot stuff is done. Not sure if you meant that or not.
  • vmlinuz is the bootable kernel image distinct from the kernel itself. It contains the compressed bootbale ELF kernel image (which itself contains bvmlinuz) and gzip decompress function, bsetup code, bbootsect system.map, and a handful of commands for the kernel image to bootstrap itself.
  • Kernel space doesn't stop once user space is allocated memory and initialized, they both run at the same time. Maybe I read that wrong, but it didn't seem right to me.

I want to be careful here not to discourage you, this is great exploration!

I realize I'm handing out unsolicited advice here, but when I was first learning about Unix/Linux kernels in the Solaris and HP/UX days, the thing that helped the process "click" for me was compiling a kernel and building an ELF. And if you're going to continue on this journey (which I hope you do), you should probably read a bit on memory segmentation and broadly about assembly instructions.

Good luck!

this post was submitted on 05 Dec 2025
162 points (100.0% liked)

Linux

59991 readers
360 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 6 years ago
MODERATORS