[Toybox] mkroot tricks.

Rob Landley rob at landley.net
Tue Dec 21 06:48:28 PST 2021


FYI, if you have to debug something like
https://github.com/landley/toybox/issues/306 where "I think this is a kernel bug
in btrfs but need to reproduce it", here's how I do it.

1) Set up the musl-cross-make tools according to
https://landley.net/toybox/faq.html#cross2 which is a "run overnight" kind of
thing for me, but only has to be done once. (Well, maybe annually to update 'em.)

2) Grab the toybox and linux sources (if you haven't already got 'em), make sure
the ccc symlink in toybox points to musl-cross-make's output dir, and select the
linux version you want to reproduce the bug against:

$ git clone https://github.com/landley/toybox
$ ln -s ~/musl-cross-make/ccc toybox/ccc
$ git clone https://github.com/torvalds/linux
$ cd linux
$ git checkout v5.15
$ cd ..

(You can also apply patches and such to the Linux source here.)

3) Build a mkroot system with extra kernel config args.

In this case we need to add the butter filesystem, which is:

$ cd toybox
$ rm -f .config; CROSS=x86_64 LINUX=~/linux scripts/mkroot.sh \
    KEXTRA=BTRFS_FS,BTRFS_FS_POSIX_ACL

Note: the reason we're cross compling for x86-64 here (even though our host is
presumably x86-64 already) is to use the musl toolchain instead of the glibc
host toolchain. Glibc faceplants on static linking because Ulrich Drepper didn't
care what his users wanted, and the gnu committee that inherited control when he
bogged off to Goldman Sachs can't make decisions and will never actually fix
anything.

4) Make a btrfs image and feed it to qemu:

$ cd root/x86_64
$ truncate -s 1g walrus.img
$ mkfs.btrfs walrus.img
$ ./qemu-x86_64.sh -hda walrus.img

and then in the VM go:

  $ mnt /dev/sda /mnt
  $ df /mnt

Rob


P.S. There's a "PENDING=" for extra toybox command names to switch on too, but
that's space separated not comma separated (ala PENDING="man dd stty") mkroot
will use the existing toybox .config if one exists, which is why we deleted it
to force a new one. Since defconfig doesn't have sh enabled yet it's pretty easy
to wind up with a system that won't boot if you skip that step. In theory the
1.0 release will have toys/pending cleaned out so that should become moot
eventually. Teething problem until then.


More information about the Toybox mailing list