Early Userspace Mounting

Because of various changes in udev (see ), the need for a minimal initramfs that checks the filesystem and pre-mounts  arose. This article will detail how build a custom 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 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 readonly.
 * 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 it to  using the --move mount parameter.
 * 5) Switchs to real root and executes init.

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 a initramfs. It's also critical that you emerge it with static USE flag enabled:

The kernel sources provide the gen_init_cpio and gen_initramfs_list.sh utilities. The gen_init_cpio 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 gen_initramfs_list.sh how to construct the initramfs:

Copy and save the contents of the above to.

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 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 our file:

System Preparation
In 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 :

Configuring GRUB
Add the initrd line to :

Result
When booting, the output looks like this : output of the initramfs when booting

External resources

 * http://jootamam.net/howto-initramfs-image.htm
 * http://whitehathouston.com/documentation/gentoo/initramfs_howto.htm
 * http://www.landley.net/writing/rootfs-howto.html