Search code examples
dnsyoctobitbakeyocto-recipe

How to replace a default configuration file of an yocto-base Linux distribution


I'm developing a Linux distribution by yocto and I need to substitute the default configuration file /etc/hosts by a custom hosts file where I have to insert some DNS settings.

The default file installed in the image is:

127.0.0.1   localhost.localdomain       localhost

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

I'm sure that the previous file comes from one of the packages that are part of the image creates by core-image-minimal.bb, but I don't know what is this package!

To customize the file /etc/hosts in the yocto image I need to solve two problems:

  1. find the recipe which adds the file to image
  2. find how to substitute the original file with mine.

Someone can help me to find the recipe and settings for the substitution?

Thanks


Solution

  • I have found the solution to my question myself. I can divide the task in two different steps and at the end of the answer I will add a little paragraph about the generality of this answer to solve similar problem.

    First step: look up for the recipe

    I'm working with the zeus release of yocto; in this release I've eventually found the recipe that installs /etc/hosts in the image; the recipe is:
    meta/recipes-core/base-files/base-files_<recipe_version>.bb

    To find previous recipe I looked for the file hosts into the folder which contains all the yocto layers.
    To do that I have executed the following commands:

    cd <path/to/yocto/folder>
    
    # I have used the following "find" command many times to solve
    # similar problems encountered working with Yocto
    find ./meta* -name "*hosts*"
    

    The output of the previous command contains:

    ...
    ./meta/recipes-core/base-files/base-files/hosts
    ...
    

    Inside the recipe ./meta/recipes-core/base-files/base-files_3.0.14.bb I have found the following assignement for the variable SRC_URI:

    SRC_URI = "file://rotation \
               file://nsswitch.conf \
               file://motd \
    =========> file://hosts \
               file://host.conf \
               file://profile \
               file://shells \
               file://fstab \
               file://issue.net \
               file://issue \
               file://share/dot.bashrc \
               file://share/dot.profile \
               file://licenses/GPL-2 \
               "
    

    In the list of files assigned to SRC_URI it is present the file hosts.

    Second step: create a base_files_%.bbappend file

    The way I have found to substitute the hosts file is by adding a base_files_%.bbappend file (in mylayer/recipes-core/base-files) and substitute the default hosts file with a customized hosts file.

    To do this I have followed this link which explains very well the meaning and use of the variable FILESEXTRAPATHS_prepend.

    The content of my file base_files_%.bbappend is:

    FILESEXTRAPATHS_prepend := "${THISDIR}/base-files:"
    
    SRC_URI = "file://rotation \
           file://nsswitch.conf \
           file://motd \
           file://hosts \
           file://host.conf \
           file://profile \
           file://shells \
           file://fstab \
           file://issue.net \
           file://issue \
           file://share/dot.bashrc \
           file://share/dot.profile \
           file://licenses/GPL-2 \
    "
    

    Furthermore I have inserted the new hosts file inside the folder: mylayer/recipes-core/base-files/base-files:

    mylayer
       |
       recipes-core
          |
          base-files
             |
             base-files
                |
                hosts
    

    The other files listed in the SRC_URI definition (rotation, nsswitch.conf, and so on) continue to come from the main base-files folder that is: meta/recipes-core/base-fles/base-files.

    This answer is a reminder to solve similar task

    I think that this problem is a common task which must be solved any time it is necessary to do some modification to a default file installed inside a yocto-based linux distribution by the default recipes. In this case the core recipe is core-image-minimal.bb.

    In fact sometimes I use this post as reminder to solve similar problems I happen to encounter.