5.10. Building an Initial RAM Filesystem (initramfs) Image

initramfs is the successor of Initial RAM Disk (initrd). It is a "copy in and out" (cpio) archive of the initial file system that gets loaded into memory during the Linux startup process. Because Linux uses the contents of the archive during initialization, the initramfs needs to contain all of the device drivers and tools needed to mount the final root filesystem.

To build an initramfs image and bundle it into the kernel, set the INITRAMFS_IMAGE_BUNDLE variable in your local.conf file, and set the INITRAMFS_IMAGE variable in your machine.conf file:

     INITRAMFS_IMAGE_BUNDLE = "1"
     INITRAMFS_IMAGE = "image_recipe_name"
            

Setting the INITRAMFS_IMAGE_BUNDLE flag causes the initramfs created by the recipe and defined by INITRAMFS_IMAGE to be unpacked into the ${B}/usr/ directory. The unpacked initramfs is then passed to the kernel's Makefile using the CONFIG_INITRAMFS_SOURCE variable, allowing initramfs to be built in to the kernel normally.

Note

The preferred method is to use the INITRAMFS_IMAGE variable rather than the INITRAMFS_TASK variable. Setting INITRAMFS_TASK is supported for backward compatibility. However, use of this variable has circular dependency problems. See the INITRAMFS_IMAGE_BUNDLE variable for additional information on these dependency problems.

The recipe that INITRAMFS_IMAGE points to must produce a .cpio.gz, .cpio.tar, .cpio.lz4, .cpio.lzma, or .cpio.xz file. You can ensure you produce one of these .cpio.* files by setting the INITRAMFS_FSTYPES variable in your configuration file to one or more of the above file types.

Note

If you add items to the initramfs image by way of its recipe, you should use PACKAGE_INSTALL rather than IMAGE_INSTALL. PACKAGE_INSTALL gives more direct control of what is added to the image as compared to the defaults you might not necessarily want that are set by the image or core-image classes.