Building an OS for Dummies
I did a thing!
Today I finished a semi-long-term project. I managed to complete the CLFS guide and produce a working "distro" of linux for my raspberry pi. It is rather barebones at the moment and is not configured for even networking out of the box, but the fact that nothing segfaults immediately after booting makes this a great success! My version also contains updated packages, as the ones on the guide were all outdated.
Compiling a (cross-)compiler
For the longest time I was trying to properly configure the toolchain. Turns out that building a toolchain is rather simple, as long as you stick to the correct sequence of operations:
1) Build barebones binutils for your chosen arch [no libc]
2) Build barebones gcc for your chosen arch [no libc]
3) Compile your libc for your chosen arch
3.1) Compile your libc++ for your chosen arch
4) Recompile binutils for your chosen arch
5) Recompile gcc for your chosen arch
Compiling the base
After compiling the toolchain, I was able to start compiling the basic packages that are required for a working OS (that is the system libc, libstdc++, kernel, and bootloader). Since the libc and libstdcxx we compiled in the previous step are for the xbinutils and xgcc, we need to recompile (I placed the sysroot for the xgcc in the root of the clfs system, instead of the cross-toolchain root). This allows us to compile whichever packages we want in the sysroot, and be able to link to them afterwards, instead of having to compile in the toolchain sysroot and copy libraries to the clfs sysroot later.
Compiling more packages
In addition to the base packages in the system, we compile busybox to provide
a basic unix environment, and zlib to provide compression. We also compile
dropbear, netplug, and wireless tools to provide a ssh server and a few
convenience net utilities. Some configuration is also done via files placed
in /etc/
.
Conclusions
This was both a very fun and a very frustrating project. At multiple points my builds were failing mysteriously, and I ended up banging my head against a wall. After hopping onto irc and asking for help, these issues were eventually resolved and I managed to continue with the project. The source code for the build script can be found here.