dev log: building my own distro
Published: 2024-02-26
Another adventure have started: I'm builing my own distro! I'm not sure about the motivations as it started naturally from my fidlings with OSs. Some of the things I remember are:- My disk was full, so I began to think how to use less space
- I want to try musl
- I discovered that the linux kernel can run shell scripts as init
- I like minimal stuff
Turns out there is a cool project called buildroot that makes building a minimal linux system very easy. So I used it to create the linux kernel and userspace programs for a RPi 3B+ I had lying arround.
The result was a system that does the minimum: boots the linux kernel without initrd directly from the RPi bootloader, it then runs a simple shell script as init and drops to a shell.This system is taking only 22MiB of RAM, which 14 are cache, and 500MiB of disk, which 470MiB are for git binaries. I am very happy. Obviously there are drawbacks: no module hotplugging, this gave me a headache as my keyboard needed a kernel module, it took me a day to figure this out. I tought this was the kernel's job.
So far I'm having a great time learning, turns out there is a lot of details we usually don't need to know. For example, firmware, which for the RPi is a must: in order to load the brcmfmac module its firmware must be present in the correct place. If not whenever you modprobe it you'll get a subtle timeout error.
Luckly buildroot also facilitates this, just select the corresponding option in firmware section. The next steps are now building sbase, ubase and sdhcp. I also included a tiny c compiler so I can compile the rest of the system.
So far this is the init script:
#!/bin/dash echo "Init started" export PATH=/usr/bin:/bin:/sbin:/usr/sbin mount -n -o remount,rw / mount -t devfs /dev /dev mount -t proc /proc /proc mount -t sysfs /sysfs /sys mount -t tmpfs /tmpfs /run modprobe hid-apple modprobe brcmfmac agetty -n --login-program /bin/dash tty1 shutdown -h
There is too much to do, still. I'll keep you posted.