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 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, 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 USE static enabled:

You will also need the kernel sources, in this article we'll use -3.2.0. 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 CONFIG_DEVTMPFS option enabled. It is required by the init script below and.

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.

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

Copy and save the contents of the above to.

Generating the Initramfs
Change to the top kernel source directory:

From here we run the scripts/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 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

External resources

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