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.
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.
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
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.
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.
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.
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.
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
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…
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.
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/
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.
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
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.
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.
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.
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.
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
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.
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.
A version of this that targeted RPi would be neat!
I wonder why this instead of using Gentoo to explore Linux.
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.
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.
ah, ok, i thought they officially discontinued stages 1 and 2 a while ago.
Thanks a lot for this awesome informative post, I genuinely learned a ton from it!
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
Obligatory reference
https://www.linuxfromscratch.org
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…
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.
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/
LFS has been on my todo list for like a decade, I really need to plan a weekend and just do it
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.
You and me both!
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?
Ilove