diff mbox series

execute pkg_postinst_ontarget when read-only-rootfs-delayed-postinsts is set for a read only rootfs

Message ID EERs.1719320900453164786.rlUz@lists.yoctoproject.org (mailing list archive)
State New
Headers show
Series execute pkg_postinst_ontarget when read-only-rootfs-delayed-postinsts is set for a read only rootfs | expand

Commit Message

Gassner, Tobias.ext June 25, 2024, 1:08 p.m. UTC
Hi,

we specify read-only-rootfs and use an overlayFS to "make the roofts writable". We also want to execute a postinstall script for our package on the target:

pkg_postinst_ontarget: ${PN} () {

#some code...
}

in order for bitbake to not complain that a read-only rootfs and pkg_postinst_ontarget don't work together, we also specify read-only-rootfs-delayed-postinsts ( https://docs.yoctoproject.org/dev/ref-manual/features.html )

However, it seems that the run-postinsts package is removed by the _uninstall_unneeded function (in file meta/lib/oe/rootfs.py), because the image_rorfs flag only checks for read-only-rootfs and not for read-only-rootfs-delayed-postinsts as well. Hence, the postinst code is not executed.

When I use the fix at the end of this post, the behavior is as expected. However, I am not an expert in this area of the project and want to collect your feedback first, before proposing to merge.

PS: a pointer to read-only-rootfs-delayed-postinsts in the docu ( https://docs.yoctoproject.org/dev/dev-manual/read-only-rootfs.html#post-installation-scripts-and-read-only-root-filesystem ) would be very helpful.

Best regards
-Tobias

From 608050984c5be67f506a0877fadbbe0b61575e54 Mon Sep 17 00:00:00 2001
From: "Gassner, Tobias.ext" <tobias.gassner.ext@karlstorz.com>
Date: Tue, 25 Jun 2024 13:30:17 +0200
Subject: [PATCH] keep delayed-postinsts when
read-only-rootfs-delayed-postinsts is set for a read only rootfs

Signed-off-by: Gassner, Tobias.ext <tobias.gassner.ext@karlstorz.com>
---
meta/lib/oe/rootfs.py | 4 ++++
1 file changed, 4 insertions(+)

--
2.45.2

Comments

Alexander Kanavin June 25, 2024, 1:16 p.m. UTC | #1
I’m not exactly sure, but is one supposed to specify one or the other, but
not both at the same time?

Alex

On Tue 25. Jun 2024 at 15.08, Gassner, Tobias.ext via lists.yoctoproject.org
<Tobias.Gassner.ext=karlstorz.com@lists.yoctoproject.org> wrote:

> Hi,
>
> we specify read-only-rootfs and use an overlayFS to* "make the roofts
> writable"*. We also want to execute a postinstall script for our package
> on the target:
>
> pkg_postinst_ontarget:${PN}() {
>
>     #some code...
> }
>
> in order for bitbake to not complain that a read-only rootfs and
> pkg_postinst_ontarget don't work together, we also specify
> read-only-rootfs-delayed-postinsts
> <https://docs.yoctoproject.org/dev/ref-manual/features.html>
>
> However, it seems that the run-postinsts package is removed by the _uninstall_unneeded
> function (in file meta/lib/oe/rootfs.py), because the image_rorfs flag
> only checks for read-only-rootfs and not for read-only-rootfs-delayed-postinsts
> as well. Hence, the postinst code is not executed.
>
> When I use the fix at the end of this post, the behavior is as expected.
> However, I am not an expert in this area of the project and want to collect
> your feedback first, before proposing to merge.
>
> PS: a pointer to read-only-rootfs-delayed-postinsts in the docu
> <https://docs.yoctoproject.org/dev/dev-manual/read-only-rootfs.html#post-installation-scripts-and-read-only-root-filesystem> would
> be very helpful.
>
>
> Best regards
> -Tobias
>
>
>
> From 608050984c5be67f506a0877fadbbe0b61575e54 Mon Sep 17 00:00:00 2001
> From: "Gassner, Tobias.ext" <tobias.gassner.ext@karlstorz.com>
> Date: Tue, 25 Jun 2024 13:30:17 +0200
> Subject: [PATCH] keep delayed-postinsts when
>  read-only-rootfs-delayed-postinsts is set for a read only rootfs
>
> Signed-off-by: Gassner, Tobias.ext <tobias.gassner.ext@karlstorz.com>
> ---
>  meta/lib/oe/rootfs.py | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/meta/lib/oe/rootfs.py b/meta/lib/oe/rootfs.py
> index 8cd48f9450..5abce4ad7d 100644
> --- a/meta/lib/oe/rootfs.py
> +++ b/meta/lib/oe/rootfs.py
> @@ -269,7 +269,11 @@ class Rootfs(object, metaclass=ABCMeta):
>                  self.pm.remove(["run-postinsts"])
>
>          image_rorfs = bb.utils.contains("IMAGE_FEATURES",
> "read-only-rootfs",
> +                                        True, False, self.d) and \
> +                      not bb.utils.contains("IMAGE_FEATURES",
> +
>  "read-only-rootfs-delayed-postinsts",
>                                          True, False, self.d)
> +
>          image_rorfs_force = self.d.getVar('FORCE_RO_REMOVE')
>
>          if image_rorfs or image_rorfs_force == "1":
>
>
> --
> 2.45.2
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#13391):
> https://lists.yoctoproject.org/g/poky/message/13391
> Mute This Topic: https://lists.yoctoproject.org/mt/106869018/1686489
> Group Owner: poky+owner@lists.yoctoproject.org
> Unsubscribe: https://lists.yoctoproject.org/g/poky/unsub [
> alex.kanavin@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
>
Gassner, Tobias.ext June 25, 2024, 1:43 p.m. UTC | #2
Hi,

(sent again, to post on group as well)

the docu ( https://docs.yoctoproject.org/dev/ref-manual/features.html ) on read-only-rootfs-delayed-postinsts says:

> 
> 
> 
> read-only-rootfs-delayed-postinsts: when specified in *conjunction* with read-only-rootfs
> , [...]
> 
> 
> 

so I guess I have to specify both.

Greetings
-Tobias
Alexander Kanavin June 25, 2024, 1:56 p.m. UTC | #3
Right. I know nothing about it, I would only suggest to grep the poky
tree for read-only-rootfs-delayed-postinsts to see how it's
implemented, and whether tests exist for it (and if they do, then how
do they set things up). Then you have the full picture.

Alex

On Tue, 25 Jun 2024 at 15:43, Gassner, Tobias.ext via
lists.yoctoproject.org
<Tobias.Gassner.ext=karlstorz.com@lists.yoctoproject.org> wrote:
>
> Hi,
>
> (sent again, to post on group as well)
>
> the docu on read-only-rootfs-delayed-postinsts says:
>
> read-only-rootfs-delayed-postinsts: when specified in conjunction with read-only-rootfs, [...]
>
> so I guess I have to specify both.
>
> Greetings
> -Tobias
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#13393): https://lists.yoctoproject.org/g/poky/message/13393
> Mute This Topic: https://lists.yoctoproject.org/mt/106869018/1686489
> Group Owner: poky+owner@lists.yoctoproject.org
> Unsubscribe: https://lists.yoctoproject.org/g/poky/unsub [alex.kanavin@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
Gassner, Tobias.ext June 26, 2024, 8:02 a.m. UTC | #4
Hi Alex,

> 
> I would only suggest to grep the poky tree for
> read-only-rootfs-delayed-postinsts to see how it's implemented
> 

already did before my first post. Basically, the only place in all of poky where this feature is used is in rootfs.py to turn off a bb.fatal when you have a delayed postinstall script and a read-only rootfs. This is also what the doc says

> 
> read-only-rootfs-delayed-postinsts: when specified in conjunction with read-only-rootfs
> , specifies that post-install scripts are still permitted (this assumes
> that the root filesystem will be made writeable for the first boot; *this
> feature does not do anything to ensure that - it just disables the check
> for post-install scripts* )

The _uninstall_unneeded method in rootfs.py removes packages with postinstall steps if read-only-rootfs is set. However, as I suggested in my patch, the check should also take into account the read-only-rootfs-delayed-postinsts feature, which allows postinstall code even for read-only rootfs.
Alexander Kanavin June 26, 2024, 9:46 a.m. UTC | #5
On Wed, 26 Jun 2024 at 10:03, Gassner, Tobias.ext via
lists.yoctoproject.org
<Tobias.Gassner.ext=karlstorz.com@lists.yoctoproject.org> wrote:
> read-only-rootfs-delayed-postinsts: when specified in conjunction with read-only-rootfs, specifies that post-install scripts are still permitted (this assumes that the root filesystem will be made writeable for the first boot; this feature does not do anything to ensure that - it just disables the check for post-install scripts)
>
> The _uninstall_unneeded method in rootfs.py removes packages with postinstall steps if read-only-rootfs is set. However, as I suggested in my patch, the check should also take into account the read-only-rootfs-delayed-postinsts feature, which allows postinstall code even for read-only rootfs.

It's possible this used to work when it was first added, then
regressed via lack of tests. Can you check if this can be
added/modified in meta/lib/oeqa/selftest/cases/buildoptions.py or
meta/lib/oeqa/selftest/cases/overlayfs.py ?

Alex
diff mbox series

Patch

diff --git a/meta/lib/oe/rootfs.py b/meta/lib/oe/rootfs.py
index 8cd48f9450..5abce4ad7d 100644
--- a/meta/lib/oe/rootfs.py
+++ b/meta/lib/oe/rootfs.py
@@ -269,7 +269,11 @@  class Rootfs(object, metaclass=ABCMeta):
self.pm.remove(["run-postinsts"])

image_rorfs = bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs",
+                                        True, False, self.d) and \
+                      not bb.utils.contains("IMAGE_FEATURES",
+                                        "read-only-rootfs-delayed-postinsts",
True, False, self.d)
+
image_rorfs_force = self.d.getVar('FORCE_RO_REMOVE')

if image_rorfs or image_rorfs_force == "1":