How to create and modify initramfs with Factory tools

How to create an initramfs for my system

An initramfs is a filesystem image that runs directly from RAM. It is packaged as an archive using the cpio tool. The Factory allows you to automate this process and output your RFS as a cpio-archvied initramfs with the selection of a few options. You can choose to either build it as a separate image, or even build it in to the kernel image itself. The former choice makes it easier to modify your initramfs image without having to modify the kernel, while the latter method simplifies the boot process and possibly saves space. To build an initramfs image of your RFS using the Factory:

  • In the root of your Factory directory, run make menuconfig.
  • In the menu, set Target Configuration->Build RFS->cpio to y.
  • If you wish to build the initramfs image into the kernel, set the option Target Configuration->Build RFS->cpio->Build cpio into kernel as initramfs to y.
  • The gzip-compressed initramfs image is located at build_<architecture>-timesys-linux-<libc>/images/rfs/rootfs.cpio.gz.

If you opted to combine the initramfs with your Linux kernel, the kernel at build_-timesys-linux-/images will include initramfs as well.

How to add various custom files in my RFS

You can use the RFS content archive to overlay an archive on top of your RFS. This option can be found in Target Configuration -> Build RFS -> RFS Content Tarball. If the archive is in the top level factory build system directory, then the configuration value can use the $(BASE_DIR) variable for its location. An example value would be file://$(BASE_DIR)/overlay.tar.gz.

The archive will be applied after all of the other selections have been installed into the RFS working directory. The build system will change directory into the RFS staging area and explode the archive on top of the existing contents. This tarball should contain content that expects to be uncompressed at the root (/) of the filesystem.

$ tar ./overlay.tar.gz 
etc/
etc/group
etc/inittab
etc/init.d/
etc/init.d/S00-custominitscript
etc/passwd

Once the overlay is created and its location is defined in the desktop factory, simply run make command to rebuild your images.

How to boot the initramfs based Linux kernel

The exact boot process varies from one system to another. Different boot loaders are involved, and the way a kernel gets started also varies. The Linux kernel will automatically boot into an initramfs assuming that the noinitrd option is not present in the Linux kernel command line.

The Linux Startup Process