Search code examples
embedded-linuxyoctobitbake

Home directory not created by useradd-example.bb


I'm using a modified version of the useradd-example.bb to create only user1. The USERADD_PARAMS suggest that a home directory should be created under /home/user1.

When building the image, user1 is added as expected and so is the directory /usr/share/user with the correct permissions. However, the /home/user1 directory is not created. Actually, I was already surprised that no specification of the path such as -d ${D}/home/user1 was needed in USERADD_PARAMS.

Do I have to add the path manually in do_install with the appropriate permissions? Did I strip something from the original example that caused the home directory gone missing or do I have to specify the full path in USERADD_PARAM such as -d ${D}/home/user1?

This is the example stripped by the user2 and user3 parts (which I find make the example overly complex).

SUMMARY = "Example recipe for using inherit useradd"
DESCRIPTION = "This recipe serves as an example for using features from useradd.bbclass"
SECTION = "examples"
PR = "r1"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"

S = "${WORKDIR}"

inherit useradd

# You must set USERADD_PACKAGES when you inherit useradd. This
# lists which output packages will include the user/group
# creation code.
USERADD_PACKAGES = "${PN}"

# You must also set USERADD_PARAM and/or GROUPADD_PARAM when
# you inherit useradd.

# USERADD_PARAM specifies command line options to pass to the
# useradd command. Multiple users can be created by separating
# the commands with a semicolon. Here we'll create two users,
# user1 and user2:
USERADD_PARAM:${PN} = "-u 1210 -d /home/user1 -r -s /bin/bash user1"

# GROUPADD_PARAM works the same way, which you set to the options
# you'd normally pass to the groupadd command. This will create
# groups group1 and group2:
GROUPADD_PARAM:${PN} = "-g 880 group1"

do_install () {
    install -d -m 755 ${D}${datadir}/user1

    # The new users and groups are created before the do_install
    # step, so you are now free to make use of them:
    chown -R user1 ${D}${datadir}/user1

    chgrp -R group1 ${D}${datadir}/user1
}

FILES:${PN} = "${datadir}/user1 /usr/share/user1"

# Prevents do_package failures with:
# debugsources.list: No such file or directory:
INHIBIT_PACKAGE_DEBUG_SPLIT = "1"

Solution

  • I'm not sure if it's a clean way but I ended up creating the home directories as follows:

    do_install () {
        install -d -m 711 ${D}/home/user1
        chown -R user1 ${D}/home/user1
        chgrp -R user1 ${D}/home/user1
    }
    

    Important lesson learned: If you plan to move files into the created home directory from another recipe, make sure that the directories you create there match the permissions as they are set here. Otherwise you will get an error saying that there are conflicting directories.