Making a micro Linux distro (2023)

(popovicu.com)

190 points | by turrini 2 days ago ago

30 comments

  • termie 2 days ago ago

    I've been working on a micro Linux distro for a couple of months now. User mode is just a single static binary (and a few files to support confidential microVM containers). The initramfs is such an interesting feature, the kernel knows how to unpack cpio archives and just magically drops you into a tmpfs and executes /init. You can have multiple concatenated cpio archives, and each can be compressed, and they all just overlay in sequence. There's an elegance to the design. I also had to write some code to unpack them and learned more than I wanted to.

  • sigwinch 2 days ago ago

    More recently, qemu supports uftrace on the more popular architectures. That’s how you answer the pro’s question, “but how do I debug this?”

    https://news.ycombinator.com/item?id=45533804

  • Levitating 2 days ago ago

    I have a similar little project https://github.com/LevitatingBusinessMan/azathos

    I have my own toy init, shell and other utilities. The GNU coreutils are included for debugging.

    My current focus is on drawing windows onto the framebuffer.

  • EvanAnderson 2 days ago ago

    This is pretty neat. I remember making floppy-based "distributions" back in '98 to do utility tasks (imaging Windows PCs over UDP broadcast being one I spent a long time on). So many memories of "make bzimage", hanging init scripts, reboots. So many reboots.

    Charmingly, the "modern" process doesn't seem wholly dissimilar. I would echo the comments of one of the sibling comments here: Targeting this to RPi would be fun and educational. Maybe I'll give it a try.

    • reactordev 2 days ago ago

      That was like me in ‘98 trying to install Mandrake linux over NetBIOS with a public sftp over ISDN line… one bad block or wrong checksum stalled the whole install. Start over again. Eventually a friend of mine was kind enough to store the sftp contents to a CD as I had already parted my drive. Thankfully we had CD burners but was limited to 2x write speed due to checksum verification failures.

  • mouse_ 2 days ago ago

    This entire, beautiful blog post scales wrong on my phone because of this one line of code near the bottom doesn't get wrapped or get its own overflow box: -device virtio-net-device,netdev=usernet -netdev user,id=usernet,hostfwd=tcp::10000-:22

  • pluto_modadic 2 days ago ago

    I wonder what the level of difficulty getting this to run as a cloud image (e.g. on Vultr or Digitalocean) would be. Or getting it to boot a GUI and run firefox.

    • c0balt 2 days ago ago

      Running as a cloud image can be relatively easy, you only need the default drivers from the kernel and need to get your image installed.

      The latter can be done by booting into another distro and kexec'ing into your own kernel and performing the Installation afterward from memory. See also nixos-anywhere for a practical implementation of this

      • ratrocket 2 days ago ago

        On digital ocean (at least) you can upload your own images and boot droplets directly from them.

        In the past I've used a script called "alpine-make-vm-image" to run alpine images in digital ocean.

        https://github.com/alpinelinux/alpine-make-vm-image

        (Maybe that script does some magic to make booting a droplet directly from the image possible. On that I plead ignorance :)

    • Nux 2 days ago ago

      Make an image with virtio drivers for network and storage, save it or convert it to qcow2 then register it into Digitalocean etc, it's quite easy.

  • SomeHacker44 2 days ago ago

    A version of this that targeted RPi would be neat!

  • trelane 2 days ago ago

    I wonder why this instead of using Gentoo to explore Linux.

    • laweijfmvo 2 days ago ago

      gentoo is “built from source”, but its package manager, which is wonderful, does all the heavy lifting. it’s a bare distribution, but all the customization is user space stuff. so it’s not a great way to learn “linux”, IMO. a stage3 tarball is already more of a “mini” distro.

      • trelane 2 days ago ago

        Yes, exactly, though you can start from earlier stages too. The process even from stage 1 is well documented. It is all there but you can customize it completely from the ground up. Or, if starting from stage 1, the foundations are there and you have to build it up yourself.

        For a newbie (looks to be the intended audience of the article), this gives them a working foundation to start from. They can get progressively more involved with whatever part of Linux they desire, as their experience grows.

        • laweijfmvo 2 days ago ago

          ah, ok, i thought they officially discontinued stages 1 and 2 a while ago.

  • synergy20 2 days ago ago

    great for learning, to get one done fast, buildroot is a good candidate

  • ruguo 2 days ago ago

    Thanks a lot for this awesome informative post, I genuinely learned a ton from it!

  • 2 days ago ago
    [deleted]
  • keyle 2 days ago ago
    • throwaway8902 2 days ago ago

      LFS takes the opposite approach. You build a cross compilation toolchain, build out a full Linux file system, compile a massive number of packages… it’s almost two days of work before you even start thinking about a boot loader.

      This tutorial gets straight to the heart of the matter. Get a system that boots asap and then add complexity as you discover the shortcomings.

      This seems like a much better pedagogical approach for someone not sure how the kernel works or what initramfs is, etc…

    • webdevver 2 days ago ago

      i once sat down to go through this as a challenge, but started to get bored quickly. skipping ahead, i built bash, configured grub to init=/bin/bash, threw in coreutils, and was very thrilled to see my very own "distro" boot in under a second (not counting bios init ofcourse) on an ancient p3 box.

      i think i disabled everything i could think of in the kernel (including filesystem support, which was quickly rectified) for a truly 'minimalist' experience.

      it ofcourse didnt do much but it was very responsive.

      • rzzzt 2 days ago ago

        Same here, I tried it on a 486 and it became an idle game. Just glancing on it from time to time, lines are still running down the screen, OK, move on to other things.

        u-root is mentioned in the article -- I used buildroot and busybox for embedded Linux development while in university: https://buildroot.org/

    • b00ty4breakfast 2 days ago ago

      LFS has been on my todo list for like a decade, I really need to plan a weekend and just do it

      • tombert 2 days ago ago

        I did it once, about twelve years ago, just to prove to myself that I could.

        It was kind of fun, but I have absolutely no desire to do it again. I tried running it as my "full time" distro but what I ended up with was something extremely fragile and decidedly not fun for me to use.

        Nowadays I run a NixOS Minimal install, which is about the level of operating system that I like to work in.

      • keyle 2 days ago ago

        I think it's a month thing rather than a weekend thing, no?

        • cheschire 2 days ago ago

          Depends on your CPU (due to all the compiling), and if you plan on only doing the base OS or the extended plans too.

      • NetOpWibby 2 days ago ago

        You and me both!

  • geroff 14 hours ago ago

    micro-distro?? just need one that installs easily on any 10year old hardware and can replace Windows for the most part.

  • pluto_modadic 2 days ago ago

    this is kinda cool. Does that mean you can use u-root to embed as a UEFI image? or to boot a u-root image over PXE netboot?

  • abety607 2 days ago ago

    Ilove