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