Skip to contentSkip to conversation

Correct way for multiple recipes to install files in the same directory

DISCUSSION [email protected] 3 participants 10 messages Apr 11, 2024 – Apr 13, 2024

lore
Share & tools
lore
#0 lore raw

Hi!
How/can I let multiple recipes install files in the same directory without getting a conflict during bitbake process?

Recipe 1 creates a user and its homedir:
inherit useradd
USERADD_PACKAGES = "${PN}"
USERADD_PARAM:${PN} = "-u 1000 -d /home/user1 -m -s /bin/bash -p 'XXX' user1" do_install(){
install -d ${D}/home/user1
chown -R user1:user1 ${D}/home/user1
}

Recipe 2 wants to install some config-files inside /home/user1/.config/. DEPENDS = "recipe1"
RDEPENDS:${PN} = "recipe1"
do_install(){
install -d ${D}/home/user1/.config/
install -m 0644 sourcefile ${D}/home/user1/.config/
chown -R user1:user1 ${D}/home/user1/.config/
}

There is also FILES directives at the end of each recipe for the corresponding files. For better readability I've removed everything that I deemed was irrelevant. The problem I get when trying to bitbake the image is during the do_rootfs stage:
file /home/user1 conflicts between attempted installs of <recipe2> and <recipe1>

If I comment out the "chown" line from both recipes it seems to work but then I guess those directories will be owned by root during runtime, which will be a problem for user1.

Is there a proper way to do this?

Kind regards, Linus

#1 lore raw
Quoted 3 lines · On Thu, Apr 11 2024 at 12:52:49 AM -07:00:00, [email protected] wrote:

Is there a proper way to do this?

Kind regards, Linus

Hi,
can't tell if this would be a proper way, but this is how I do it and what works for me:

Create a main user:
<https://codeberg.org/flk/meta-image/src/branch/master/recipes-extended/system-config/main-user.bb>

Inherit a main-user class for every recipe that wants to write stuff to /home/user
<https://codeberg.org/flk/meta-image/src/branch/master/classes/main-user.bbclass>

You can override the values set in main-user.bbclass to fit your needs in e.g. local.conf

Regards,
Markus

#2 lore raw
In reply to [email protected]

From: [email protected] <[email protected]> On Behalf Of linusnilsson via lists.yoctoproject.org
Sent: Thursday, April 11, 2024 9:53
To: [email protected]
Subject: [yocto] Correct way for multiple recipes to install files in the same directory

Quoted 12 lines

Hi!
How/can I let multiple recipes install files in the same directory without getting a conflict during bitbake process?

Recipe 1 creates a user and its homedir:
inherit useradd
USERADD_PACKAGES = "${PN}"
USERADD_PARAM:${PN} = "-u 1000 -d /home/user1 -m -s /bin/bash -p 'XXX' user1" do_install(){
install -d ${D}/home/user1
chown -R user1:user1 ${D}/home/user1
}

Quoted 7 lines

Recipe 2 wants to install some config-files inside /home/user1/.config/. DEPENDS = "recipe1"
RDEPENDS:${PN} = "recipe1"
do_install(){
install -d ${D}/home/user1/.config/
install -m 0644 sourcefile ${D}/home/user1/.config/
chown -R user1:user1 ${D}/home/user1/.config/

Have you tried to change this line to

chown -R user1:user1 ${D}/home/user1

The error may come from fact that directory /home/user1 has different ownership in both recipes

Quoted 11 lines

}

There is also FILES directives at the end of each recipe for the corresponding files. For better readability I've removed everything that I deemed was irrelevant. The problem I get when trying to bitbake the image is during the do_rootfs stage:
file /home/user1 conflicts between attempted installs of <recipe2> and <recipe1>

If I comment out the "chown" line from both recipes it seems to work but then I guess those directories will be owned by root during runtime, which will be a problem for user1.

Is there a proper way to do this?

Kind regards, Linus

#3 lore raw

Changing in recipe 2 from
chown -R user1:user1 ${D}/home/user1/.config/
to
chown -R user1:user1 ${D}/home/user1
actually seems to solve the problem with those particular recipes.

After getting a bit further in the bitbake process I now have the same problem with another recipe that wants to add custom files to /etc/polkit-1/rules.d/ but this recipe doesn't contain any 'chown' statement so I can't apply the same solution here. file /etc/polkit-1/rules.d conflicts between attempted installs of disk-automount-0.1-r0.core2_64 and polkit-124-r0.core2_64

disk-automount-0.1 recipe contains:
do_install(){
install -d ${D}/${sysconfdir}/polkit-1/rules.d
install -m 0644 ${S}/00-mount-internal.rules ${D}/${sysconfdir}/polkit-1/rules.d }

polkit-124 recipe contains:
do_install:append() {
#Fix up permissions on polkit rules.d to work with rpm4 constraints chmod 700 ${D}/${datadir}/polkit-1/rules.d
chmod 700 ${D}/${sysconfdir}/polkit-1/rules.d
chown polkitd:root ${D}/${datadir}/polkit-1/rules.d chown polkitd:root ${D}/${sysconfdir}/polkit-1/rules.d
}

Since polkit is maintained by yocto I want to avoid making changes to it but rather adapt my disk-automount recipe somehow since the problem probably is on my end.
IIRC install -d will set the permissions to 0755 unless otherwise specified which might conflict with polkit's chmod 700 so I might try copying chmod 700 ${D}/${sysconfdir}/polkit-1/rules.d to my disk-automount recipe.

#4 lore raw

After adding
chmod 700 ${D}/${sysconfdir}/polkit-1/rules.d
chown polkit:root ${D}/${sysconfdir}/polkit-1/rules.d
to the disk-automount recipe I get error with chown not knowing about the polkit user, even though I've added polkit to both DEPENDS and RDEPENDS of disk-automount recipe so now I've got figure out how to make it aware that the user polkit exists.

#5 lore raw
In reply to [email protected]

Obvious solution is to copy chmod command to your recipe. Peter

From: linusnilsson via Lists.Yoctoproject.Org <[email protected]>
Sent: Thursday, April 11, 2024 14:38
To: Marko, Peter (ADV D EU SK BFS1) <[email protected]>; [email protected]
Subject: Re: [yocto] Correct way for multiple recipes to install files in the same directory

Quoted 26 lines

Changing in recipe 2 from
chown -R user1:user1 ${D}/home/user1/.config/
to
chown -R user1:user1 ${D}/home/user1
actually seems to solve the problem with those particular recipes.

After getting a bit further in the bitbake process I now have the same problem with another recipe that wants to add custom files to /etc/polkit-1/rules.d/ but this recipe doesn't contain any 'chown' statement so I can't apply the same solution here. file /etc/polkit-1/rules.d conflicts between attempted installs of disk-automount-0.1-r0.core2_64 and polkit-124-r0.core2_64

disk-automount-0.1 recipe contains:
do_install(){
install -d ${D}/${sysconfdir}/polkit-1/rules.d
install -m 0644 ${S}/00-mount-internal.rules ${D}/${sysconfdir}/polkit-1/rules.d
}

polkit-124 recipe contains:
do_install:append() {
#Fix up permissions on polkit rules.d to work with rpm4 constraints chmod 700 ${D}/${datadir}/polkit-1/rules.d
chmod 700 ${D}/${sysconfdir}/polkit-1/rules.d
chown polkitd:root ${D}/${datadir}/polkit-1/rules.d chown polkitd:root ${D}/${sysconfdir}/polkit-1/rules.d
}

Since polkit is maintained by yocto I want to avoid making changes to it but rather adapt my disk-automount recipe somehow since the problem probably is on my end.
IIRC install -d will set the permissions to 0755 unless otherwise specified which might conflict with polkit's chmod 700 so I might try copying chmod 700 ${D}/${sysconfdir}/polkit-1/rules.d to my disk-automount recipe.

#6 lore raw
Quoted 2 lines

Obvious solution is to copy chmod command to your recipe.

Yes and I did that but that line alone didn't suffice. I also had to copy the 'chown'-line but since the polkit user was created in another recipe it is not recognized in this recipe and so I have to somehow figure out a way to fix that.

#7 lore raw

I found a solution and I'll try to break it down. There was the original problem with the conflict between the recipes and then there were the problem with the recipe not being aware of the existence of the user polkitd.

The solution for the first problem was to make sure that the permissions and ownership set by my recipe 2 matches the one in recipe 1 exactly, hence:

Quoted 7 lines

Changing in recipe 2 from
chown -R user1:user1 ${D}/home/user1/.config/
to
chown -R user1:user1 ${D}/home/user1/
actually seems to solve the problem with those particular recipes.

The solution to the second problem (disk-automount recipe bitbake error because user polkitd is invalid) was to copy the creation of the user polkitd from the original polkit recipe into my recipe:
inherit useradd
USERADD_PACKAGES = "${PN}"
USERADD_PARAM:${PN} = "--system --no-create-home --user-group --home-dir ${sysconfdir}/${BPN}-1 --shell /bin/nologin polkitd"

and then make sure that my disk-automount recipe matches the permissions and ownerships set up by the polkit recipe as well:
do_install:append() {
#Fix up permissions on polkit rules.d to work with rpm4 constraints
chmod 700 ${D}/${datadir}/polkit-1/rules.d
chmod 700 ${D}/${sysconfdir}/polkit-1/rules.d
chown polkitd:root ${D}/${datadir}/polkit-1/rules.d
chown polkitd:root ${D}/${sysconfdir}/polkit-1/rules.d
}

This is working but I can see some issues with copying code from one recipe to another. If the original recipe changes, I will need to manually update every one of my own recipes with the corresponding changes, which doesn't scale very well. Having this in mind I think that Markus Volk's post might be a nicer way to do things so I think I will consider his way of doing it in the future. I haven't worked with the classes yet but I can see how they can be used to make things a lot easier in my case.

Big thanks and great appreciation to everyone who came up with suggestions, they eventually led me towards a solution! :)

#8 lore raw
Quoted 1 line · Linus Nilsson

I haven't worked with the classes yet but I can see how they can be used to make things a lot easier in my case.

But don't use classen too invasively. They can be problematic, e.g. an :append may be ignored depending on the BBFILE_PRIORITY of a layer

#9 lore raw

As I have no prior experience with classes I'll have to read through the manual to learn and I'll have that in mind, cheers. 🙂
________________________________
Från: Markus Volk <[email protected]>
Skickat: den 13 april 2024 00:48
Till: [email protected] <[email protected]>; [email protected] <[email protected]> Ämne: Re: [yocto] Correct way for multiple recipes to install files in the same directory

On Fri, Apr 12 2024 at 09:14:45 AM -07:00:00, Linus Nilsson <[email protected]> wrote:
I haven't worked with the classes yet but I can see how they can be used to make things a lot easier in my case.

But don't use classen too invasively. They can be problematic, e.g. an :append may be ignored depending on the BBFILE_PRIORITY of a layer