[1/1] Fix permissions when splitting rootfs folders across partitions.

Message ID 20220421160543.2718864-1-felix.moessbauer@siemens.com
State New
Headers show
Series [1/1] Fix permissions when splitting rootfs folders across partitions. | expand

Commit Message

Felix Moessbauer April 21, 2022, 4:05 p.m. UTC
This patches ensures that the file database containing the file and
folder usernames and permissions is always located relative to the
source and not to the appended rootfs-dir.

Prior to this patch, the database was not found when using -rootfs-dir
in the WIC script, leading to erronous file permissions and ownership.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
 scripts/lib/wic/plugins/source/rootfs.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Luca Ceresoli April 22, 2022, 9:32 a.m. UTC | #1
Hello Felix,

Il giorno Thu, 21 Apr 2022 18:05:43 +0200
"Felix Moessbauer" <felix.moessbauer@siemens.com> ha scritto:

> This patches ensures that the file database containing the file and
> folder usernames and permissions is always located relative to the
> source and not to the appended rootfs-dir.
> 
> Prior to this patch, the database was not found when using -rootfs-dir
> in the WIC script, leading to erronous file permissions and ownership.
> 
> Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>

Autobuilder testing showed some errors, perhaps due to this patch:

  KeyError: 'ROOTFS_DIR'

See the full logs at:
https://autobuilder.yoctoproject.org/typhoon/#/builders/86/builds/3450/steps/14/logs/stdio
https://autobuilder.yoctoproject.org/typhoon/#/builders/87/builds/3489/steps/15/logs/stdio
https://autobuilder.yoctoproject.org/typhoon/#/builders/80/builds/3431/steps/14/logs/stdio
https://autobuilder.yoctoproject.org/typhoon/#/builders/79/builds/3482/steps/15/logs/stdio

Would you mind looking at what is happening?

Best regards.
Richard Purdie April 22, 2022, 12:35 p.m. UTC | #2
On Thu, 2022-04-21 at 18:05 +0200, Felix Moessbauer wrote:
> This patches ensures that the file database containing the file and
> folder usernames and permissions is always located relative to the
> source and not to the appended rootfs-dir.
> 
> Prior to this patch, the database was not found when using -rootfs-dir
> in the WIC script, leading to erronous file permissions and ownership.
> 
> Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> ---
>  scripts/lib/wic/plugins/source/rootfs.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

As well as fixing the test failure, for future reference the shortlog for this
also needs to read something like:

wic/plugins/rootfs: Fix permissions when splitting rootfs folders across partitions

just so we can easily see which area of the code a change is related to.

Cheers,

Richard
Felix Moessbauer April 22, 2022, 12:49 p.m. UTC | #3
> -----Original Message-----
> From: Luca Ceresoli <luca.ceresoli@bootlin.com>
> Sent: Friday, April 22, 2022 11:33 AM
> To: Moessbauer, Felix (T CED SES-DE) <felix.moessbauer@siemens.com>
> Cc: openembedded-core@lists.openembedded.org; Kiszka, Jan (T CED)
> <jan.kiszka@siemens.com>; Schild, Henning (T CED SES-DE)
> <henning.schild@siemens.com>; Schmidt, Adriaan (T CED SES-DE)
> <adriaan.schmidt@siemens.com>
> Subject: Re: [OE-core] [PATCH 1/1] Fix permissions when splitting rootfs folders
> across partitions.
> 
> Hello Felix,
> 
> Il giorno Thu, 21 Apr 2022 18:05:43 +0200 "Felix Moessbauer"
> <felix.moessbauer@siemens.com> ha scritto:
> 
> > This patches ensures that the file database containing the file and
> > folder usernames and permissions is always located relative to the
> > source and not to the appended rootfs-dir.
> >
> > Prior to this patch, the database was not found when using -rootfs-dir
> > in the WIC script, leading to erronous file permissions and ownership.
> >
> > Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> 
> Autobuilder testing showed some errors, perhaps due to this patch:
> 
>   KeyError: 'ROOTFS_DIR'
> 
> See the full logs at: 
> Would you mind looking at what is happening?

Hi Luca,

Thanks for testing this.

While I could easily fix this issue with some if / else, it brings me to a more fundamental question:
The use-case we need this patch for is a partition layout where folders like /tmp, /home should be placed on dedicated partitions.
As these folders originate from the same rootfs (i.e. image recipe), I tried the following wic script to achieve the layout:

[...]
part / --use-uuid --source rootfs --fstype ext4  --exclude-path=tmp/
part /tmp --use-uuid --source rootfs --rootfs-dir=${IMAGE_ROOTFS}/tmp
[...]

This obviously requires that the pseudo dir is located relative to "${IMAGE_ROOTFS}" but not to "=${IMAGE_ROOTFS}/tmp".
But while this pattern is a top answer on stackoverflow [1], there is also a note on the ML that this is not supported but instead recipes should be used to split the rootfs [2].

Felix

[1] https://stackoverflow.com/questions/56187209/yocto-create-and-populate-a-separate-home-partition
[2] https://www.yoctoproject.org/pipermail/yocto/2016-March/029300.html

> 
> Best regards.
> --
> Luca Ceresoli, Bootlin
> Embedded Linux and Kernel engineering
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbootlin.c
> om%2F&amp;data=05%7C01%7Cfelix.moessbauer%40siemens.com%7C42464ff
> f659f4d18db9808da244312b4%7C38ae3bcd95794fd4addab42e1495d55a%7C1
> %7C0%7C637862167736296029%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4
> wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C
> %7C%7C&amp;sdata=ru3bzQkMbII6D3kBpkB7unbzP9mgnu6k2Y%2BnZjHOqR0%
> 3D&amp;reserved=0

Patch

diff --git a/scripts/lib/wic/plugins/source/rootfs.py b/scripts/lib/wic/plugins/source/rootfs.py
index 2e34e715ca..efcc220c48 100644
--- a/scripts/lib/wic/plugins/source/rootfs.py
+++ b/scripts/lib/wic/plugins/source/rootfs.py
@@ -95,7 +95,7 @@  class RootfsPlugin(SourcePlugin):
 
         part.rootfs_dir = cls.__get_rootfs_dir(rootfs_dir)
         part.has_fstab = os.path.exists(os.path.join(part.rootfs_dir, "etc/fstab"))
-        pseudo_dir = os.path.join(part.rootfs_dir, "../pseudo")
+        pseudo_dir = os.path.join(krootfs_dir['ROOTFS_DIR'], "../pseudo")
         if not os.path.lexists(pseudo_dir):
             logger.warn("%s folder does not exist. "
                         "Usernames and permissions will be invalid " % pseudo_dir)