Mechanism behind pkg_postinst_ontarget_${PN} #yocto
Hi,
I am trying to execute a few shell commands the first time a new image boots. The Yocto built-in mechanism for that should be pkg_postinst_ontarget_${PN}. However I can not get the commands I put within that function to execute. I am having a hard time trying to figure out what the problem is.
I am installing the new image to my board via SWUpdate. My suspicion is that the mechanism behind the pkg_postinst_ontarget_${PN} is somehow hindered by the SWUpdate utility. I could imagine that whatever mechanism is used might me surpressed/ignored by the SWUpdate process.
That is why im asking about the exact mechanism within Linux that is used to execute the contents of the pkg_postinst_ontarget_${PN} function on first boot.
As a reference:
Yocto version: sumo
pkg_postinst_ontarget_${PN} () {
#!/bin/sh
file=$D/home/root/test.txt
printf "hello world\n" > $file
}
Thanks in advance
Stefan Wenninger
You can start by inspecting your image's rootfs, the scripts to run on first boot should be in /etc/ somewhere. Are they?
Alex
Quoted 27 lines · On Fri, 27 Mar 2020 at 09:14, <[email protected]> wrote:
Hi,
I am trying to execute a few shell commands the first time a new image boots. The Yocto built-in mechanism for that should be *pkg_postinst_ontarget_${PN}.*However I can not get the commands I put within that function to execute. I am having a hard time trying to figure out what the problem is.
I am installing the new image to my board via SWUpdate. My suspicion is that the mechanism behind the *pkg_postinst_ontarget_${PN}* is somehow hindered by the SWUpdate utility.
I could imagine that whatever mechanism is used might me surpressed/ignored by the SWUpdate process.That is why im asking about the exact mechanism within Linux that is used to execute the contents of the *pkg_postinst_ontarget_${PN}* function on first boot.
As a reference:
Yocto version: sumo
pkg_postinst_ontarget_${PN} () {
#!/bin/sh
file=$D/home/root/test.txt
printf "hello world\n" > $file
}Thanks in advance
Stefan Wenninger
Hi Alex,
Im not sure if my previous reply got sent/reached you. I apologise in case you receive this message twice.
Should there be a script in /etc created from my pkg_postinst_ontarget_${PN} function? If yes, what would its name be?
Stefan
Actually, that depends on which package format you use. The script that executes the postinsts on target can be found in meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts.
Alex
Quoted 9 lines · On Fri, 27 Mar 2020 at 10:06, <[email protected]> wrote:
Hi Alex,
Im not sure if my previous reply got sent/reached you. I apologise in case you receive this message twice.Should there be a script in /etc created from my *pkg_postinst_ontarget_${PN}* function? If yes, what would its name be?
Stefan
I am using deb as my package class. What I am gathering from that run-postinsts directory is that there is a systemd service that starts and executes the run-postinsts script. That script looks for a directory /etc/deb-postinsts and executes all scripts in there. Does that mean, that the mechanism used in the end is the post-install scripts of deb packages? So basically the pkg_postinst_ontarget_${PN} function adds a postinstall script to the .deb package of the recipe it is in, correct?
That should mean that I can expect to see a script in /etc/deb-postinsts that contains my commands. I will verify that right away.
If these assumptions are correct, you have already greatly improved my understanding of this process. Thank you for that.
Stefan
I am not sure about deb-postinsts. What I see the script doing is:
eval dpkg --configure -a $append_log
Alex
Quoted 16 lines · On Fri, 27 Mar 2020 at 10:26, <[email protected]> wrote:
I am using deb as my package class. What I am gathering from that run-postinsts directory is that there is a systemd service that starts and executes the run-postinsts script.
That script looks for a directory/etc/deb-postinstsand executes all scripts in there. Does that mean, that the mechanism used in the end is the post-install scripts of deb packages?
So basically the *pkg_postinst_ontarget_${PN}* function adds a postinstall script to the .deb package of the recipe it is in, correct? That should mean that I can expect to see a script in/etc/deb-postinststhat contains my commands. I will verify that right away.If these assumptions are correct, you have already greatly improved my understanding of this process. Thank you for that.
Stefan
I think the relevant part for me in that script is the func exec_postinst_scriplets(). It looks to me as if this function iterates through all scripts in the /etc/deb-postinsts directory in my case and executes them with "sh". My problem seems to have stemmed from confusion on my part about what package the postinst attaches to.
The postinst belongs to the package with the same name as my recipe because of the _${PN}. However I specified that my recipe produces another package with the PROVIDES ="" variable.
In my IMAGE_INSTALL I only added the package I specifically provide. Therefore the recipe package with the postinst did not end up in my rootfs.
When changing the IMAGE_INSTALL I get my commands to be executed on the system on first boot.
I realize now that my current method of having every recipe create an extra package with PROVIDES is not really necessary.
Your hint about the run-postinsts directory was what lead me to understand the mechanism further. And on the way I recognized a bad or at least confusing practice on my behalf.
I consider this question/problem solved, thank you very much.
Stefan
Hi Stefan,
Quoted 3 lines · On Fri, Mar 27, 2020 at 05:26:23AM -0700, [email protected] wrote:
I think the relevant part for me in that script is the func
exec_postinst_scriplets(). It looks to me as if this function iterates through all scripts in the/etc/deb-postinstsdirectory in my case and executes them with "sh". My problem seems to have stemmed from confusion on my part about what package the postinst attaches to.
The postinst belongs to the package with the same name as my recipe because of the _${PN}. However I specified that my recipe produces another package with the PROVIDES ="" variable.
I think you meant PACKAGES and not PROVIDES here. If that is the case, then yes, congrats, you found the root cause :)
Otherwise, I think there might be something worth debugging and maybe reporting.
Quentin
Hi Quentin,
I have now read up on the exact meaning of PROVIDES and PACKAGES and I do understand your response. It does sound like I am talking about PACKAGES since I did suspect PROVIDES to work like that. Well at least if PROVIDES would work like that, it would explain why my postinstall did not work previously.
But I did use PROVIDES, which I now know is basically just a alias.
Here is the situation I had before and how I solved it:
Previous attempt:
*my_recipe.bb:*
...
PROVIDES += "my_recipes_package"
RPROVIDES_${PN} += "my_recipes_package"
pkg_postinst_ontarget_${PN} () {
#!/bin/sh
file=$D/home/root/test/test.txt
printf "hello world\n" > $file
}
*my_image.bb:*IMAGE_INSTALL += " my_recipes_package "
current solution:
*my_recipe.bb:*
...
pkg_postinst_ontarget_${PN} () {
#!/bin/sh
file=$D/home/root/test/test.txt
printf "hello world\n" > $file
}
*my_image.bb:*IMAGE_INSTALL += " my_recipe "
I can only guess that the postinst was only attached to the package called "my_recipe" and not to its alias "my_recipes_package"?
Stefan
Hi Stefan,
Quoted 5 lines · On Fri, Mar 27, 2020 at 06:41:57AM -0700, [email protected] wrote:
Hi Quentin,
I have now read up on the exact meaning of PROVIDES and PACKAGES and I do understand your response. It does sound like I am talking about PACKAGES since I did suspect PROVIDES to work like that. Well at least if PROVIDES would work like that, it would explain why my postinstall did not work previously.
Quoted 8 lines
But I did use PROVIDES, which I now know is basically just a alias.
Here is the situation I had before and how I solved it:
Previous attempt:
*my_recipe.bb:*
...
PROVIDES += "my_recipes_package"
Your recipe can now be used in DEPENDS of other recipes with both "my-recipe" and "my-recipe-package". N.B.: please do not use underscore in recipe names, it can have weird consequences (been there, trust me). I assume it's only for the sake of an example so it's fine.
Quoted 2 lines
RPROVIDES_${PN} += "
my_recipes_package"
Here, you mean, ${PN} (packaged named my-recipe which is the main package usually) can also be known as my-recipes-package, it's another alias, for different thing but still nothing crazy.
Quoted 9 lines
pkg_postinst_ontarget_${PN} () {
#!/bin/sh
file=$D/home/root/test/test.txt
printf "hello world\n" > $file
}*my_image.bb:*
IMAGE_INSTALL+= "my_recipes_package"
"Please install my-recipes-package which is an alias to my-recipe package."
This actually seems okay to me. So if no typo and no underscore, I'm clueless.
Can you try that exact same recipe but with:
pkg_postinst_ontarget_my-recipes-package instead of pkg_postinst_ontarget_${PN} ()?
And another try, with the exact same recipe (so not the modification asked above), with IMAGE_INSTALL += "my-recipe"?
In any case, this seems to me to be bug that should be reported.
Quentin