User:Zulu Foxtrott/GentooOnARM/EasyInstall/Initramfs

From Gentoo Wiki
Jump to:navigation Jump to:search

Optional: Building an initramfs

If the main partition has been encrypted, building an initial RAM file system (initramfs) is required.

Another common reason for building an initramfs is when important file system locations (like /usr/ or /var/) are on separate partitions.

As outlined in the section before an initramfs provides a minimal root filesystem and some tools (applications) to the kernel. It usually takes care of making the "real" root filesystem accessible. Depending on the tools included, different tasks can be performed. Thus it's possible to configure it not only to mount separate partitions or decrypt devices but also to do something else.

First, create a directory for the initramfs:

root #mkdir /mnt/gentoo/usr/src/initramfs

Creating the intiramfs filesystem structure

Create a minimal root filesystem structure in that directory, using mkdir with the command line argument -p to allow that all necessary parent directories are created as well:

TODO: compare

root #mkdir -p /mnt/gentoo/usr/src/initramfs/{bin,dev,etc,lib,lib64,mnt/root,proc,root,run,sbin,sys}

Creating necessary device nodes

The initramfs' /dev directory needs to be populated with the necessary device nodes. Device nodes are block or character special files - files that can generate or receive data. They can be created with the mknod command. The argument -m followed by the file permissions allows to set these correctly (in the example the numeric notation is used). Following that is the name of the new device node before its type (c for character devices and b for block devices) is defined. This is concluded by the major and minor device numbers. (The major number identifies the device type and thus the driver and the minor number identifies the device served by the driver.)

Create the required character device nodes:

root #mknod -m 666 /mnt/gentoo/usr/src/initramfs/dev/null c 1 3
root #mknod -m 666 /mnt/gentoo/usr/src/initramfs/dev/random c 1 8
root #mknod -m 666 /mnt/gentoo/usr/src/initramfs/dev/urandom c 1 9

After creating the tty device node, its group ownership should be changed:

root #mknod -m 666 /mnt/gentoo/usr/src/initramfs/dev/tty c 5 0
root #chgrp tty /mnt/gentoo/usr/src/initramfs/dev/tty

This is not necessary for the console device node, but its file permissions are more restricted:

root #mknod -m 600 /mnt/gentoo/usr/src/initramfs/dev/console c 5 1

Finally create the required block device node with the correct permissions and adjust the group ownership as recommended:

root #mknod -m 660 /mnt/gentoo/usr/src/initramfs/dev/mmcblk0p4 b 179 4
root #chgrp disk /mnt/gentoo/usr/src/initramfs/dev/mmcblk0p4
Important
If a block device other than that used in the example has been encrypted, the name of the device node and the major and minor numbers corresponding to the main partition must be used instead.

Now that all necessary device nodes have been created, it is time to add some tools so the initramfs can actually serve its purpose.

Adding tools (applications)

Any application that needs to be executed before the "real" root filesystem is available to the kernel must be present on the initramfs. In the best case these tools are included in the stage tarball that has been downloaded and unpacked earlier in the installation process. Sometimes, however, when this is not the case, it may become necessary to be creative. If the host system's and the target system's architecture are identical they could be installed on the host system and copied from there, for instance. In any case the simplest approach is to use only statically linked binaries, which means only one file will have to be copied over to the initramfs instead of many files to different directories of the initramfs.


busybox cryptsetup

script

kernel compilation still difficult?


The initramfs will be stored in /boot/. The resulting file can be found by simply listing the files starting with initramfs:

root #ls /boot/initramfs*

Next

Compiling and installing the kernel