InitramFS - axxia/axxia_yocto_linux_4.9 GitHub Wiki

Table of Contents

  1. Overview
  2. Yocto Setup
  3. Build Requirements
  4. Building the InitramFS
  5. Method 1: Stand Alone InitramFS Image
  6. Method 2: Combined Kernel and InitramFS Image
  7. Limitations
  8. QEMU x86 Example

## Overview

An initramfs is a RAM based filesystem intended for a two phase boot initialization. The initramfs typically contains a minimal filesystem to do scripted boot initialization, such as loading device drivers and mounting the main root filesystem. Another use for an initramfs is to provide a runtime environment with minimal dependencies on device drivers. This is useful for debugging.

This document describes the steps to build a stand alone initramfs image, and a combined kernel and initramfs image, through the Yocto build system.


## Yocto Setup ### Build Requirements It is assumed that a Yocto build environment has been configured per Yocto Build Environment. At this point, it is not necessary to build yet.

NOTE

  1. The jethro release of Yocto is required to build the combined initramfs and kernel image.
  2. Ensure that the meta-axxia layer has the jethro branch checked out.

InitramFS Image Type (FSIMAGE_TYPES)

The initramfs image is a compressed cpio archive. The cpio archive must be in the "newc" format (cpio -H newc), and the compression method must be one of gzip, lzma, xz, or lzop. Thus, to build an initramfs image, the appropriate FSIMAGE_TYPES must be passed to bitbake.

The following table lists the compression method, IMAGE_FSTYPES, kernel config option to enable, and the trade offs.

Compression IMAGE_FSTYPES Kernel Config Comments
gzip cpio.gz CONFIG_RD_GZIP Good compression and speed. The default.
bzip2 cpio.bz2 CONFIG_RD_BZIP2 Better compression than gzip, but (much slower) to compress and decompress. NOTE: not supported by Yocto!
lzma cpio.lzma CONFIG_RD_LZMA Much better compression than gzip, and better compression than bzip2. Faster decompression than bzip2, but slower than gzip.
xz cpio.xz CONFIG_RD_XZ Best compression. Faster decompression than bzip2, but slower than gzip. Supersedes LZMA.
lzo cpio.lzo CONFIG_RD_LZO Worst compression, but fastest decompression speed.

Please note that appropriate support for the compression method must be configured in the kernel. Gzip is the default as it is widely supported and provides a good trade off between speed, memory overhead, and compression.

## Building the InitramFS ### Method 1: Stand Alone InitramFS Image The following instructions are for configuring Yocto to build a stand alone initramfs image.

1. Create the following bitbake configuration file in your Yocto build directory.

conf/initramfs.conf

2. Add the following line in conf/initramfs.conf. Change IMAGE_FSTYPES to the desired compressed image type.

IMAGE_FSTYPES = "cpio.gz"

3. Build the initramfs image.

$ bitbake -R conf/initramfs.conf core-image-minimal

Note the -R switch. It tells bitbake to process initramfs.conf after all other configuration files (e.g. local.conf). This allows initramfs.conf to override IMAGE_FSTYPES. It is not necessary to create the default ext3 and tar.bz2 images when building the initramfs image. This is also useful for reusing an existing Yocto build directory. To build an axxia-image-large ext3 image after building the initramfs image, run bitbake without the -R.

$ bitbake axxia-image-large

The initramfs image is in tmp/deploy/images// when the build completes. Note that additional processing may be required to make the compressed cpio archive into a usable boot image, depending on your bootloader. For example, U-Boot requires that the compressed cpio archive is turned into a uimage file (this can be done with the mkimage command).

### Method 2: Combined Kernel and InitramFS Image The following instructions are for configuring Yocto to build a combined kernel and initramfs image.

1. Create the following bitbake configuration file in your Yocto build directory.

conf/initramfs.conf

2. Add the following line in conf/initramfs.conf. Change IMAGE_FSTYPES to the desired compressed image type.

INITRAMFS_IMAGE = "core-image-minimal"
INITRAMFS_IMAGE_BUNDLE = "1"

IMAGE_FSTYPES = "cpio.gz"

Note the INITRAMFS_IMAGE and INITRAMFS_IMAGE_BUNDLE. These variables instruct the kernel bitbake recipe (meta/classes/kernel.bbclass) to bundle the kernel image with a core-image-minimal initramfs image. This is only supported in Yocto dora or later.

3. Build the initramfs image.

$ bitbake -R conf/initramfs.conf core-image-minimal

The initramfs image is in

$YOCTO/tmp/deploy/images/<machine>/

when the build completes. The image file name is

<kernel-image>-initramfs-<machine>.bin

Amarillo (axm5500) Boot Image

Amarillo (axm5500) uses the U-Boot FIT image. The legacy uImage generated through Yocto is not compatible with the axm5500's bootloader.

An additional step is needed to create the proper boot image file. Please follow the NonYoctoBuildInstructions for Amarillo for instructions on how to create the FIT boot image. The vmlinux file with the embedded initramfs could be found in the kernel build directory.

$YOCTO/axm5500/tmp/work/axm4400-poky-linux-gnueabi/linux-yocto/3.10.19+auto-r0/linux-axm5500-standard-build/vmlinux

Please note that the actual path to the vmlinux file may be different for your build, as it is determined by the kernel variant (standard/preempt-rt) and version.


## Limitations

As the combined kernel and initramfs boot image is larger, care must be taken to ensure that the boot image and the decompressed kernel image do not overlap. The image load address may need to be adjusted.


## QEMU x86 Example

The qemux86 target and QEMU emulator are supported by Yocto. They provide a virtualized environment with minimal host dependencies; this is useful for building and testing a rootfs configuration with minimal deployment effort. The following is an example for building and running a combined kernel and initramfs image for qemux86.

1. Follow the steps in Yocto Environment Setup. In the build's conf/local.conf file, replace MACHINE with

MACHINE = "qemux86"

2. Follow the steps in Method 2: Combined Kernel and InitramFS Image to configure and build the kernel with a core-image-minimal initramfs. The combined kernel and initramfs image is in the following directory when the build completes.

$YOCTO/qemux86/tmp/deploy/images/qemux86/bzImage-initramfs-qemux86.bin

3. Start the QEMU emulator with the following.

$YOCTO/qemux86/tmp/sysroots/x86_64-linux/usr/bin/qemu-system-i386 \
 -kernel $YOCTO/qemux86/tmp/deploy/images/qemux86/bzImage-initramfs-qemux86.bin \
 -vga vmware \
 -no-reboot \
 -m 512

Note that this starts the kernel without any bootargs (e.g. root=/dev/sda) or a separate initrd file (-initrd).

The QEMU window should show that the target has booted to login prompt.

⚠️ **GitHub.com Fallback** ⚠️