How to add/modify files in the root file systems in Yocto

Are there any examples on how to add startup scripts and other files to the target root file system using yocto?
ie placing shell scripts into the etc/init.d directory and the /etc/modules-load.d directory

This is commonly done using a do_install_append script in the recipe. The files you want to install are generally provided in a directory of the same name as the recipe. Here is one of many examples of this. The file is provided in a systemd directory which exists alongside the systemd.bbappend file. The file is installed using the install command in the do_install_append script of the systemd recipe. Also note the very first line of the recipe which adds the systemd directory to FILESEXTRAPATHS.

Some examples of this are also provided in the Toradex Yocto Project Webinar - Part 2. See the base-files recipe at ~41 min and the bluez4 recipe at ~44 min.

Thank you.

Unfortunately I could not get the example to work for me.

This is an example to simply set the backlight brightness in a startup script.
This example was tested and works on a apalis imx6-ixora with a fusion07 display.

The original recipe for the init startup scripts is in the following directory


I created a directory in my build recipe directory as follows


Which contains the following file


FILESEXTRAPATHS_prepend := "${THISDIR}/initscripts:"

SRC_URI += " \
    file:// \

do_install_append() {
    # The extra files need to go in the respective directories
    install -m 0755    ${WORKDIR}/       ${D}${sysconfdir}/init.d

    # Create the symbolic links
    update-rc.d -r ${D} start 03 S .

and the following directory


Which contains the following file


# Provides:          backlight brightness setting
# Required-Start:
# Required-Stop:
# Default-Start:     S
# Default-Stop:
# Short-Description: Set Backlight Brightness

echo 7 > /sys/class/backlight/backlight.17/brightness

@mbarn Can you provide more detail about what didn’t work?

It would not add the files into the directories I needed. No error was generated. I would imagine that the /etc/init.d directory does not exist? when the systemd recipe is being run but as I am just learning the ropes of yocto, it could very well be something I did wrong. The example I provided does put the files into the correct directories as verified in the target zip file.

If /etc/init.d doesn’t exist at the time the recipe installs the file, then you’ll want to add the following to the top of the do_install_append() function:

install -d ${D}${sysconfdir}/init.d