Early Userspace Mounting

This article will detail Article description::how to build a custom minimal [[initramfs that checks the filesystem and pre-mounts .]] This has become necessary for affected configurations because of various changes in udev (see ).

In this article we'll be working with the following:


 * Busybox
 * An initramfs content list
 * The and  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 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  as read-only.
 * 2) Symlinks the fstab from the root partition to the initramfs environment.
 * 3) Checks the filesystem of our  device using the embedded  binary.
 * 4) Mounts, then moves it to  using the   mount parameter.
 * 5) Switches to real root and executes.

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

Requirements
The most important package here is as it provides utilities suitable for an initramfs. It is also critical that you emerge it with  USE flag enabled:

The kernel sources provide the and  utilities. The utility does not come prepackaged and needs to be built:

Make sure that these two are executable:

Make sure that your running kernel is built with the devtmpfs option enabled. It is required by the init script below and udev:

Next up is the file which will tell  how to construct the initramfs:

Copy and save the contents of the above to after adjusting for your architecutre.

Last up is the actual file which will execute the initramfs:

Copy and save the contents of the above to.

Generating the Initramfs
Run the script with the   argument pointing to where we want the initramfs image to be placed followed by the path to our  file:

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

Bootloader configuration
To use the initramfs, the bootloader needs to be configured as shown below for GRUB and LILO as examples.

Configuring GRUB
Add the  line to :

Configuring LILO
Add the  and   line to :

Result
When booting, the output looks like this:

External resources

 * http://jootamam.net/howto-initramfs-image.htm
 * http://whitehathouston.com/documentation/gentoo/initramfs_howto.htm Link seems dead
 * http://www.landley.net/writing/rootfs-howto.html
 * https://forums.gentoo.org/viewtopic-p-7038132.html