Author: z3bra <willyatmailoodotorg>
Date: Sun, 31 Jan 2016 12:15:11 +0000
New post: make your own distro
3 files changed, 80 insertions(+), 3 deletions(-)
diff --git a/2016/01/make-your-own-distro.txt b/2016/01/make-your-own-distro.txt
@@ -8,6 +8,12 @@ So here is a fun project I'm working on: Making my own linux distro!
I consider building a linux distribution from scratch to be one of the coolest
things one could do with their computers. And I finally got into it!
+I've been writing my "tales" in my
+[journal](gopher://z3bra.org/0/distro/journal.txt). Be sure to read it for a
+more "day-to-day" like approach.
+This post is only meant to detail the tools used and the workflow I have when
+I work on it.
First off all, I have never built an [LFS](https://linuxfromscratch.org) system,
and will probably never do (their documentation is great though).
@@ -46,11 +52,24 @@ I am using [pcc](http://pcc.ludd.ltu.se) as my complier of choice, and
[musl](http://musl-libc.org) as my libc.
To this day, I couldn't find a suitable replacement for GNU's binutils, but am
-still looking forrward to elfutils and elftoolchain.
+still looking forward to elfutils and elftoolchain.
To make it easier to work with this toolchain, I decided to build a
cross-compiler featuring both. I also had to create one using gcc, until I can
figure out a patch for softwares that can't compile with pcc.
+The script used to generate the cross-compiler can be found
+In order to use it, add the path to the toolchain in your path. Calling
+`x86_64-linux-musl-gcc` will automatically call libs/include from the cross
+ <source src='/vid/20160131-osdev-xcompiler.webm' type='video/webm'>
+<span class='caption'>Using the cross-compiler to build a software statically
+against musl libc.</span>
#### Package management toolchain
There are a lot of them. But the most challenging one will be the one I'll write
@@ -64,3 +83,59 @@ it follows the way the *BSD handle their own port-tree, while using mk(1) from
plan9, which is, in my opinion, more predictable. For more information on mk,
check the link [maintaining files on plan9 with
+The ports are available [here](http://git.z3bra.org/mkports/log.html). To build
+a port, you need to configure the `config.mk` file to match your environment, and
+run `mk <port>`. This will build all the deps required to build you port, and
+install them under your cross-compilation root directory.
+To clean the tree from this deps, run `mk clean`. The tarball will be packed in the
+port directory of your tool, eg `pm/pm#1.0.tar.bz`. Theses file are suitable for
+installation via [pm](http://git.z3bra.org/pm/log.html).
+ <source src='/vid/20160131-osdev-mkports.webm' type='video/webm'>
+<span class='caption'>Show casing the creation of a port within the mk port-tree
+and building/installing it under a specific directory</span>
+#### Testing toolchain
+To actually test the distro, you need a way to boot from it. I chose to use linux
+containers (LXC) over traditionnal VMs (virtualbox, qemu) as I'm not playing with
+different CPU architectures (yet!).
+This way I can treat my distro as a simple chroot and modify it from outside in real
+time. It also let me play with those containerization technologies I'm not
+The first thing to do is to install the packs under your chroot. For this purpose, I
+chose `/ns/pm/rootfs`. After installing a few packs, you can fire up a container
+using this directory as its root to check wether the distro boots, and if the tools
+you installed work as expected.
+As of today, spawning gettys doesn't work. I'll need to figure out why, but otherwise,
+it's been a pretty successful (and fun!) experience.
+ <source src='/vid/20160131-osdev-containers.webm' type='video/webm'>
+<span class='caption'>Demonstrating the whole testing process, from creating the
+containers and saying "hello world!" from within this container</span>
+In the process, I learnt how to spawn containers "the hard way". Here is a quick
+peak at it:
+ ip link add veth0 type veth peer name eth0
+ ip netns add foo
+ ip link set eth0 netns foo
+ ip netns exec foo ip addr add 192.168.0.100/24 dev eth0 broadcast +
+ ip netns exec foo ip link set eth0 up
+ ip netns exec foo ip route add default via 192.168.0.254
+ brctl addif br0 veth0
+ ip netns exec unshare -fpium --mount-proc env -i chroot /ns/pm/rootfs /sbin/init
+This is far from a final-run-everywhere solution of course, because you'll miss /dev
+mounts, ttys and such, and won't be able to log within this container, or inject
+processes in to it.
diff --git a/config.mk b/config.mk
@@ -1,7 +1,7 @@
NAME = monochromatic
-PREFIX = /var/http/blog.z3bra.org
+PREFIX = /var/www/blog.z3bra.org
PAGES = index.html \
@@ -29,7 +29,8 @@ PAGES = index.html \
+ 2015/08/install-alpine-at-onlinenet.html \
FEEDS = rss/feed.xml
EXTRA = css img vid data errors favicon.ico
diff --git a/index.txt b/index.txt
@@ -1,3 +1,4 @@
+* 0x001a - [Make your own distro](/2016/01/make-your-own-distro.html)
* 0x0019 - [Install Alpine at online.net](/2015/08/install-alpine-at-onlinenet.html)
* 0x0018 - [cross-compiling with PCC and musl](/2015/08/cross-compiling-with-pcc-and-musl.html)
* 0x0017 - [Vomiting colors](/2015/06/vomiting-colors.html)