Early Userspace Mounting

Because of various changes in sys-fs/udev, the need for a minimal initramfs that checks the /usr filesystem and pre-mounts /usr arose. This article will detail how build this initramfs.

In this article we'll be working with the following:
 * An initramfs content list
 * The gen_init_cpio and gen_initramfs_list.sh utilities, provided by the kernel itself.
 * The gen_init_cpio and gen_initramfs_list.sh utilities, provided by the kernel itself.

The initramfs also contains the required libraries and binaries to run an ext4 fsck. Most of the code to run the fsck is coming from the /etc/init.d/fsck script.

If you are using any other filesystem than ext4, you will need to add the required binaries/libraries into the initramfs list.

Basically, the init script is doing following actions :
 * 1) Mounts the root partition on /mnt/root as readonly.
 * 2) Symlinks the fstab from the root partition to the initramfs environment.
 * 3) Checks the filesystem of our /usr device using the embedded /sbin/fsck binary.
 * 4) Mounts /usr, then move the /usr tree to /mnt/root/usr using the --move mount parameter.
 * 5) Switchs to real root and executes init.

The article also assumes we are working in /usr/src/initramfs/, so for the sake of ease, begin with creating this directory.

Requirements
The most important package here is as it provides utilities sutiable for a initramfs. It's also critical that you emerge it with USE static enabled:

You will also need the kernel sources, in this article we'll use. The kernel sources provides the gen_init_cpio and gen_initramfs_list.sh utilitiies. Thes gen_init_cpio utility does not come prepackaged and needs need to built:

Make sure that these two are executable:

Next up is the initramfs_list file which will tell gen_initramfs_list.sh how to construct the initramfs:

Copy and save the contents of the above to /usr/src/initramfs/initramfs_list.

Last up is the actual ./init file which will execute the initramfs:

Copy and save the contents of the above to /usr/src/initramfs/init.

Generating the Initramfs
Change to the top kernel source directory:

From here we run the gen_initramfs_list.sh script with the -o argument pointing to where we want the initramfs image to be placed followed by the path to out initramfs_list file:

System Preparation
In /etc/fstab, we must set the sixth field for the /usr entry to 0, this will prevent the OpenRC fsck init script to try to check the filesystem for the already mounted /usr:

Configuring GRUB
Add the initrd line to grub.conf:

Result
When booting, the output looks like this :

output of the initramfs when booting