Skip to content

bootstrapping from aboriginal linux

rofl0r edited this page Oct 10, 2012 · 11 revisions

aboriginal is a great start platform for building sabotage, because it comes as prebuilt qemu images for all sorts of different archs. currently the only major missing arch is microblaze. it has support for arm4-6, mips, ppc, sh4, sparc, and of course x86 and amd64.

since sabotage includes hundreds of packages, that are mostly not designed for cross-compilation, qemu + aboriginal (or similar projects) is the only viable way to bootstrap sabotage when not building for the same archictecture your host OS runs on.

setting up sabotage

git clone sabotage

cd into it, run utils/build-butch.sh and use the resulting butch binary like this

butch prefetch stage0 stage1 world

that' ll download all source tarballs.

setting up aboriginal

if you're not on x86 or amd64, skip the distcc/cross-compiler specific steps

** important : aboriginal mips images have a broken network stack - do not enable distcc support there (i.e. no cross-compiler in PATH) **

grab system-image-$ARCH from landley.net

same for cross-compiler-$ARCH (only needed for distcc)

untar both

for example

~/qemu/aboriginal/system-image-mips

~/qemu/aboriginal/cross-compiler-mips

cd into system-image-$ARCH

edit dev-environment.sh

put PATH=~/qemu/aboriginal/cross-compiler-mips/bin:$PATH

as second line (this way the crosscompiler can be found and used by distcc)

search for 2048 and replace it with 8192 (so that our work hd getting created is 8GB)

./dev-environment.sh this'll create an 8GB "hdb.img" and start qemu

exit qemu using CTRL-d

important in case you are building for mips, the GCC4 build during stage1 will fail with OOM.

you need to add swap like this:

dd if=/dev/zero of=swap.img count=0 bs=1 seek=256M

always launch qemu like this:

HDC=swap.img ./dev-environment.sh

and after aboriginal is running, issue these two commands:

mkswap /dev/hdc
swapon /dev/hdc

to activate the swap.

put this into loopmount.sh

#!/bin/sh
mkdir -p mnt
sudo mount -o loop -t ext3 hdb.img mnt

run sh loopmount.sh

put this into prepare-sabotage-workspace-img:

#!/bin/sh
syntax() {
        echo $0 sabotage-dir
        echo "sabotage-dir must contain a tarballs dir with all tarballs"
        echo "in case it doesnt already, call butch prefetch world"
        echo "in your sabotage work env. that'll download everything"
        exit 1
}

if [ -z "$1" ] ; then
        syntax
fi

sabodir="$1"
sabogit=git://github.com/rofl0r/sabotage

echo "assert that mnt/ in the current dir is loopmounted to the aboriginal work hd image"
echo "sleeping 3 seconds, press ctrl-c now if this isnt the case"
sleep 3

cd mnt/
echo cloning repo
git clone $sabogit || exit 1
echo copying tarballs
time cp "$sabodir"/tarballs/* sabotage/tarballs/

run it, passing your sabotage dir as argument. that'll get you a fresh checkout of sabotage plus all the earlier downloaded tarballs.

sh ./prepare-sabotage-workspace-img.sh /path/to/sabotage/dir

the contents of hdb.img will be available as /home inside qemu.

sudo umount mnt/

now you can launch aboriginal using CPUS=1-3 ./dev-environment.sh

(note CPUS should be maximum 3, otherwise you'll start swapping with only 256 MB available inside the VM)

bootstrapping butch for the target arch

bootstrapping from aboriginal is a little bit tricky because it uses uclibc, which in turn lacks posix_spawn(), required by butch.

you have 2 options to bootstrap butch (butch/musl tarballs are located in sabotage/tarballs if you followed the above steps):

a) use a musl/glibc crosscompiler (i.e. from GregorR/musl-cross) for your target and build a static butch binary. this should be the fastest possible way.

b)

  • build musl manually into a home prefix and --disable-shared, i.e.

    ./configure --prefix=/home/musl-prefix --disable-shared && make -j$CPUS && make install

  • use

    KEEP/musl-gcc-old-gen.sh /home/musl-prefix /inexistent/libc.so > /home/musl-prefix/bin/musl-gcc-old

  • use

    CC="/home/musl-prefix/bin/musl-gcc-old -static" make

    to build butch

then (inside qemu) put BUTCH_BIN=/path/to/butch.binary into your stage0 config.

from here on, you can continue as usual.

Misc

build times usgin QEmu / armv6l on a 3.1 Ghz 8core machine:

2012.10.06 01:58:41 building stage0_gcc3 (/home/sabotage.bld/src/build/build_stage0_gcc3.sh) -> /home/sabotage.bld/src/logs/build_stage0_gcc3.log
2012.10.06 02:21:07 building stage0_musl (/home/sabotage.bld/src/build/build_stage0_musl.sh) -> /home/sabotage.bld/src/logs/build_stage0_musl.log
2012.10.06 02:37:02 building stage0_mini-kernel-headers (/home/sabotage.bld/src/build/build_stage0_mini-kernel-headers.sh) -> /home/sabotage.bld/src/logs/build_stage0_mini-kernel-headers.log
2012.10.06 02:37:02 building stage0_butch (/home/sabotage.bld/src/build/build_stage0_butch.sh) -> /home/sabotage.bld/src/logs/build_stage0_butch.log
2012.10.06 02:37:09 building stage0_patch (/home/sabotage.bld/src/build/build_stage0_patch.sh) -> /home/sabotage.bld/src/logs/build_stage0_patch.log
2012.10.06 02:41:23 building stage0_busybox (/home/sabotage.bld/src/build/build_stage0_busybox.sh) -> /home/sabotage.bld/src/logs/build_stage0_busybox.log
2012.10.06 03:01:08 building stage0_binutils (/home/sabotage.bld/src/build/build_stage0_binutils.sh) -> /home/sabotage.bld/src/logs/build_stage0_binutils.log
2012.10.06 04:06:33 building stage0_make (/home/sabotage.bld/src/build/build_stage0_make.sh) -> /home/sabotage.bld/src/logs/build_stage0_make.log
2012.10.06 04:09:20 building stage0_finish (/home/sabotage.bld/src/build/build_stage0_finish.sh) -> /home/sabotage.bld/src/logs/build_stage0_finish.log
2012.10.06 04:09:22 done.

2.5 hours for stage0.

same on mipsel:

2012.10.10 02:14:12 building stage0_gcc3 (/home/sabotage.bld/src/build/build_stage0_gcc3.sh) -> /home/sabotage.bld/src/logs/build_stage0_gcc3.log
2012.10.10 03:23:49 building stage0_musl (/home/sabotage.bld/src/build/build_stage0_musl.sh) -> /home/sabotage.bld/src/logs/build_stage0_musl.log
2012.10.10 03:48:13 building stage0_mini-kernel-headers (/home/sabotage.bld/src/build/build_stage0_mini-kernel-headers.sh) -> /home/sabotage.bld/src/logs/build_stage0_mini-kernel-headers.log
2012.10.10 03:48:14 building stage0_butch (/home/sabotage.bld/src/build/build_stage0_butch.sh) -> /home/sabotage.bld/src/logs/build_stage0_butch.log
2012.10.10 03:48:14 building stage0_patch (/home/sabotage.bld/src/build/build_stage0_patch.sh) -> /home/sabotage.bld/src/logs/build_stage0_patch.log
2012.10.10 03:53:42 building stage0_busybox (/home/sabotage.bld/src/build/build_stage0_busybox.sh) -> /home/sabotage.bld/src/logs/build_stage0_busybox.log
2012.10.10 04:30:47 building stage0_binutils (/home/sabotage.bld/src/build/build_stage0_binutils.sh) -> /home/sabotage.bld/src/logs/build_stage0_binutils.log
2012.10.10 06:23:58 building stage0_make (/home/sabotage.bld/src/build/build_stage0_make.sh) -> /home/sabotage.bld/src/logs/build_stage0_make.log
2012.10.10 06:28:37 building stage0_finish (/home/sabotage.bld/src/build/build_stage0_finish.sh) -> /home/sabotage.bld/src/logs/build_stage0_finish.log
2012.10.10 06:28:39 done.

4.25 hrs

i would recommend you to save $R once you have your stage0, to save time in case you need multiple rebuilds.