diff mbox series

wic-imager-direct.py: use fstab update also for root device

Message ID 20220929125750.3338743-1-f_l_k@t-online.de
State New
Headers show
Series wic-imager-direct.py: use fstab update also for root device | expand

Commit Message

Markus Volk Sept. 29, 2022, 12:57 p.m. UTC
Remove the hardcoded root device entry from fstab when updating to
avoid duplicate entries.

Signed-off-by: Markus Volk <f_l_k@t-online.de>
---
 scripts/lib/wic/plugins/imager/direct.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Alexander Kanavin Sept. 29, 2022, 1:08 p.m. UTC | #1
Can you describe in more detail what the problem is (e.g. an example
of incorrect output), and what changes with this patch?

Alex

On Thu, 29 Sept 2022 at 14:58, Markus Volk <f_l_k@t-online.de> wrote:
>
> Remove the hardcoded root device entry from fstab when updating to
> avoid duplicate entries.
>
> Signed-off-by: Markus Volk <f_l_k@t-online.de>
> ---
>  scripts/lib/wic/plugins/imager/direct.py | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
> index da483daed5..fd86a094d9 100644
> --- a/scripts/lib/wic/plugins/imager/direct.py
> +++ b/scripts/lib/wic/plugins/imager/direct.py
> @@ -117,7 +117,7 @@ class DirectPlugin(ImagerPlugin):
>          updated = False
>          for part in self.parts:
>              if not part.realnum or not part.mountpoint \
> -               or part.mountpoint == "/" or not part.mountpoint.startswith('/'):
> +               or not part.mountpoint.startswith('/'):
>                  continue
>
>              if part.use_uuid:
> @@ -145,6 +145,11 @@ class DirectPlugin(ImagerPlugin):
>              fstab_lines.append(line)
>              updated = True
>
> +        for line in fstab_lines:
> +            if '/dev/root' in line:
> +                fstab_lines.remove(line)
> +                updated = True
> +
>          if updated:
>              self.updated_fstab_path = os.path.join(self.workdir, "fstab")
>              with open(self.updated_fstab_path, "w") as f:
> --
> 2.34.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#171186): https://lists.openembedded.org/g/openembedded-core/message/171186
> Mute This Topic: https://lists.openembedded.org/mt/93993381/1686489
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [alex.kanavin@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
Markus Volk Sept. 29, 2022, 3:10 p.m. UTC | #2
Sure. I've sent a v2

Am Do, 29. Sep 2022 um 15:08:48 +0200 schrieb Alexander Kanavin 
<alex.kanavin@gmail.com>:
> Can you describe in more detail what the problem is (e.g. an example
> of incorrect output), and what changes with this patch?
> 
> Alex
> 
> On Thu, 29 Sept 2022 at 14:58, Markus Volk <f_l_k@t-online.de 
> <mailto:f_l_k@t-online.de>> wrote:
>> 
>>  Remove the hardcoded root device entry from fstab when updating to
>>  avoid duplicate entries.
>> 
>>  Signed-off-by: Markus Volk <f_l_k@t-online.de 
>> <mailto:f_l_k@t-online.de>>
>>  ---
>>   scripts/lib/wic/plugins/imager/direct.py | 7 ++++++-
>>   1 file changed, 6 insertions(+), 1 deletion(-)
>> 
>>  diff --git a/scripts/lib/wic/plugins/imager/direct.py 
>> b/scripts/lib/wic/plugins/imager/direct.py
>>  index da483daed5..fd86a094d9 100644
>>  --- a/scripts/lib/wic/plugins/imager/direct.py
>>  +++ b/scripts/lib/wic/plugins/imager/direct.py
>>  @@ -117,7 +117,7 @@ class DirectPlugin(ImagerPlugin):
>>           updated = False
>>           for part in self.parts:
>>               if not part.realnum or not part.mountpoint \
>>  -               or part.mountpoint == "/" or not 
>> part.mountpoint.startswith('/'):
>>  +               or not part.mountpoint.startswith('/'):
>>                   continue
>> 
>>               if part.use_uuid:
>>  @@ -145,6 +145,11 @@ class DirectPlugin(ImagerPlugin):
>>               fstab_lines.append(line)
>>               updated = True
>> 
>>  +        for line in fstab_lines:
>>  +            if '/dev/root' in line:
>>  +                fstab_lines.remove(line)
>>  +                updated = True
>>  +
>>           if updated:
>>               self.updated_fstab_path = os.path.join(self.workdir, 
>> "fstab")
>>               with open(self.updated_fstab_path, "w") as f:
>>  --
>>  2.34.1
>> 
>> 
>> 
>> 
> 
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#171187): 
> <https://lists.openembedded.org/g/openembedded-core/message/171187>
> Mute This Topic: <https://lists.openembedded.org/mt/93993381/3618223>
> Group Owner: openembedded-core+owner@lists.openembedded.org 
> <mailto:openembedded-core+owner@lists.openembedded.org>
> Unsubscribe: 
> <https://lists.openembedded.org/g/openembedded-core/unsub> 
> [f_l_k@t-online.de <mailto:f_l_k@t-online.de>]
> -=-=-=-=-=-=-=-=-=-=-=-
>
Richard Purdie Sept. 29, 2022, 3:32 p.m. UTC | #3
On Thu, 2022-09-29 at 14:57 +0200, Markus Volk wrote:
> Remove the hardcoded root device entry from fstab when updating to
> avoid duplicate entries.
> 
> Signed-off-by: Markus Volk <f_l_k@t-online.de>
> ---
>  scripts/lib/wic/plugins/imager/direct.py | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
> index da483daed5..fd86a094d9 100644
> --- a/scripts/lib/wic/plugins/imager/direct.py
> +++ b/scripts/lib/wic/plugins/imager/direct.py
> @@ -117,7 +117,7 @@ class DirectPlugin(ImagerPlugin):
>          updated = False
>          for part in self.parts:
>              if not part.realnum or not part.mountpoint \
> -               or part.mountpoint == "/" or not part.mountpoint.startswith('/'):
> +               or not part.mountpoint.startswith('/'):
>                  continue
>  
>              if part.use_uuid:
> @@ -145,6 +145,11 @@ class DirectPlugin(ImagerPlugin):
>              fstab_lines.append(line)
>              updated = True
>  
> +        for line in fstab_lines:
> +            if '/dev/root' in line:
> +                fstab_lines.remove(line)
> +                updated = True
> +

Do we need to worry here about whether we're actually adding a new root
entry? Is there a case it does need to be preserved?

Cheers,

Richard
Markus Volk Sept. 29, 2022, 3:56 p.m. UTC | #4
Am Do, 29. Sep 2022 um 16:32:40 +0100 schrieb Richard Purdie 
<richard.purdie@linuxfoundation.org>:
> Do we need to worry here about whether we're actually adding a new 
> root
> entry? Is there a case it does need to be preserved?

wic does run the fstab_update by default and adds entries for all vaild 
partitions. Single partitions can be prohibited using 
'--no-fstab-update' in the .wks file. You can choose to use /dev/foo 
format, uuid (--use-uuid) or label (--use-label). The fstab_update can 
also be disabled globally by setting:

WIC_CREATE_EXTRA_ARGS ?= "--no-fstab-update"

In that case the stock fstab file wont be touched by wic at all.

This has been active for some months now but got reverted here
<https://git.yoctoproject.org/poky/commit/?id=e7619f7650e1f545dccba327bbc8d03a7b34fc4e>

because systemd-fstab-generator got confused by trying to create two 
different '-.mount' files.
Markus Volk Sept. 29, 2022, 4:27 p.m. UTC | #5
In special circumstances this could cause problems with layern and .wks 
configurations if neither '--use-uuid' nor '--use-label' is used and 
the root device is not specified hardcoded. Then the entry is created 
as /dev/sda which can lead to a non-booting system.

But this is then due to a misconfigured layer

>
diff mbox series

Patch

diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
index da483daed5..fd86a094d9 100644
--- a/scripts/lib/wic/plugins/imager/direct.py
+++ b/scripts/lib/wic/plugins/imager/direct.py
@@ -117,7 +117,7 @@  class DirectPlugin(ImagerPlugin):
         updated = False
         for part in self.parts:
             if not part.realnum or not part.mountpoint \
-               or part.mountpoint == "/" or not part.mountpoint.startswith('/'):
+               or not part.mountpoint.startswith('/'):
                 continue
 
             if part.use_uuid:
@@ -145,6 +145,11 @@  class DirectPlugin(ImagerPlugin):
             fstab_lines.append(line)
             updated = True
 
+        for line in fstab_lines:
+            if '/dev/root' in line:
+                fstab_lines.remove(line)
+                updated = True
+
         if updated:
             self.updated_fstab_path = os.path.join(self.workdir, "fstab")
             with open(self.updated_fstab_path, "w") as f: