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 rndis.network file is provided in a systemd directory which exists alongside the systemd.bbappend file. The rndis.network 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 mdis.network 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

~/oe-core/stuff/openembedded-core/meta/recipes-core/initscripts

I created a directory in my build recipe directory as follows

~/oe-core/stuff/meta-myname-apalis/recipes-core/initscripts

Which contains the following file

~/oe-core/stuff/meta-myname-apalis/recipes-core/initscripts/initscripts_1.0.bbappend

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

SRC_URI += " \
    file://backlightset.sh \
"

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

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

and the following directory

~/oe-core/stuff/meta-myname-apalis/recipes-core/initscripts/initscripts

Which contains the following file

~/oe-core/stuff/meta-myname-apalis/recipes-core/initscripts/initscripts/backlightset.sh

#!/bin/sh
### BEGIN INIT INFO
# Provides:          backlight brightness setting
# Required-Start:
# Required-Stop:
# Default-Start:     S
# Default-Stop:
# Short-Description: Set Backlight Brightness
### END INIT INFO

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