With the OS image that I wrote about in the previous post I was able to build a new distro with the various substitution I’d made. There were 3 things that I wanted to mention in this post. First, turns out Linux has a bc(1) build dependency which I found when I omitted building it and came to compile the kernel. Second, you really need to run
make defconfig before visiting the kernel
menuconfig, otherwise you end up with a “default kernel config” lacking any on disk file system support (memory and network file systems are still supported). This was the reason why the kernel was unable to find init in the previous post.
My workflow is that I have flat file which I mount via loop back and I use that as the file system to build the OS in a chroot. When it comes to installing a boot loader using
grub-install, if sysfs is not mounted to a location from within the chroot,
grub-install will fail, complaining
Unknown device "/dev/loop10p1": No such device, p1 being a child node for the first partition on the file backed by
/dev/loop10 which is odd as
grub-install was pointed at
/dev/loop10, the parent node. This is because it is trying to enumerate the start of partitions so it can work out the start sector via sysfs (see grub-core/osdep/linux/hostdisk.c, starting at sysfs_partition_path() . Elsewhere it might have been achieved via ioctls. Either way it is asking the kernel but the dependency for a pseudo filesystem to be mounted in place threw me but looking around
/sys/devices/virtual/block/loop10 I see files which expose various characteristics, including offset and start points for each partition.