tNew post: make your own distro - monochromatic - monochromatic blog: http://blog.z3bra.org
(HTM) git clone git://z3bra.org/monochromatic
(DIR) Log
(DIR) Files
(DIR) Refs
---
(DIR) commit 6bd9571517b7a95aea2500fe61e1a79302985dc3
(DIR) parent b2a1c9c47ea60957f89dc6211f5b336c21f2a47f
(HTM) Author: z3bra <willyatmailoodotorg>
Date: Sun, 31 Jan 2016 12:15:11 +0000
New post: make your own distro
Diffstat:
M 2016/01/make-your-own-distro.txt | 77 ++++++++++++++++++++++++++++++-
M config.mk | 5 +++--
M index.txt | 1 +
3 files changed, 80 insertions(+), 3 deletions(-)
---
(DIR) diff --git a/2016/01/make-your-own-distro.txt b/2016/01/make-your-own-distro.txt
t@@ -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).
t@@ -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
+[here](http://git.z3bra.org/cross/file/cross-gcc.html).
+
+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
+prefix.
+
+<video controls>
+ <source src='/vid/20160131-osdev-xcompiler.webm' type='video/webm'>
+</video>
+<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
t@@ -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
mk](http://plan9.bell-labs.com/sys/doc/mk.html).
+
+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).
+
+<video controls>
+ <source src='/vid/20160131-osdev-mkports.webm' type='video/webm'>
+</video>
+<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
+familiar with.
+
+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.
+
+<video controls>
+ <source src='/vid/20160131-osdev-containers.webm' type='video/webm'>
+</video>
+<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.
+
+But.
+
+That's neat.
(DIR) diff --git a/config.mk b/config.mk
t@@ -1,7 +1,7 @@
MD =/usr/bin/markdown
NAME = monochromatic
-PREFIX = /var/http/blog.z3bra.org
+PREFIX = /var/www/blog.z3bra.org
PAGES = index.html \
about.html \
t@@ -29,7 +29,8 @@ PAGES = index.html \
2015/04/the-wrong-sysadmin.html \
2015/06/vomiting-colors.html \
2015/08/cross-compiling-with-pcc-and-musl.html \
- 2015/08/install-alpine-at-onlinenet.html
+ 2015/08/install-alpine-at-onlinenet.html \
+ 2016/01/make-your-own-distro.html
FEEDS = rss/feed.xml
EXTRA = css img vid data errors favicon.ico
(DIR) diff --git a/index.txt b/index.txt
t@@ -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)