At this moment, we have a fully initialized Linux Kernel running, the initramfs
area in memory is populated by a temporary root filesystem with just the most
basic Linux commands, and temporary init just started.
Having the temporary root filesystem in initramfs is not ideal, since it doesn't
support pivot_root system call - an important operation which will be
used later in the boot up process. We need to switch from initramfs to something
else. To do that, the temporary init firstly mounts a tmpfs filesystem over /m,
moves all files and directories in there including the init script itself, and
uses switch_root to make this tmpfs /m the new root and to restart the
init itself from there too. Blue star denotes the directory which is moved.
No matter how strange this whole action looks like (we've ended up with the
very same directory structure like before, it seems like no improvement at all),
the change is significant. Since now, the temporary root filesystem is on tmpfs
instead of initramfs, and thus pivot_root operation will be available when needed
in the future.
You may be wondering why is the current root filesystem still labeled as temporary.
It's because we're still at the very beginning of the construction phase and we'll
just build the real root filesystem later, as explained below, by combining Slax
compressed data images to AUFS union.
Slax Data Lookup
Before the init process could start to search for Slax data on available devices,
it needs to setup the working environment. The proc and sysfs
filesystems are mounted over /proc and /sys respectively. Some
important kernel drivers such as aufs, squashfs and loop are loaded using modprobe,
and device files are created in /dev directory by the mdev command.
Path to the mdev binary is also echoed to /proc/sys/kernel/hotplug,
to make sure that the Linux Kernel automatically creates new device files in /dev
for all the newly discovered disk partitions as soon as they become available
later. That is specially needed for partitions on USB devices, since those can
take few seconds to fully initialize.
As soon as storage devices are accessible through device files in /dev, the
blkid command is used to filter out only those which can be mounted (which
contain a filesystem known to the running kernel). The devices are examined (mounted
read-only over /memory/data/) one after another, until a valid Slax data directory
is found. Then, all files with .sb extension (Slax Bundles) are processed
- for each Slax Bundle, a directory is created in /memory/bundles/ and
the bundle (which in fact is a squashfs compressed image file) is loop-mounted
over it. In the diagram below, squashfs content is green.