diff mbox series

[isar-cip-core,1/1] make method to find /var mount configurable

Message ID 20230919034336.2545650-1-felix.moessbauer@siemens.com (mailing list archive)
State Superseded
Headers show
Series [isar-cip-core,1/1] make method to find /var mount configurable | expand

Commit Message

MOESSBAUER, Felix Sept. 19, 2023, 3:43 a.m. UTC
Previously, the /var mount is only located by the partition label. This
is problematic, as collisions on this label might happen when working
with multiple disks. This patch makes the method to find the /var
partition configurable. By that, downstream implementations can use UUID
or PARTUUID based mounting.

For backwards compatibility we keep the current label-based mounting as
default.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
While debugging this, I found many more locations where mounts happen
based on the disk label but not the UUID. All that should be changed to
UUID or PARTUUID based mounting in the future. However, we do not have
stable UUIDs for a long time in cip-core, so all that must be
implemented in a backwards compatible manner. Otherwise the swupdate
paths breaks.

In addition, all the UUIDs should be provided by the user and not via a
default in cip-core. Otherwise collisions are likely to happen in the
field.

Note on testing: This patch has been tested in a MTDA setup, where
another swupdate image (of a different product) has been attached via an
sdwire interface. As the sdwire interfaces automatically connects the
storage to the host after reboot, the wrong /var got mounted before
having this patch.

Best regards,
Felix Moessbauer
Siemens AG

 .../initramfs-overlay-hook/files/overlay.script.tmpl | 12 ++++++------
 .../initramfs-overlay-hook_0.1.bb                    |  5 +++--
 2 files changed, 9 insertions(+), 8 deletions(-)

Comments

MOESSBAUER, Felix Oct. 7, 2023, 5:37 a.m. UTC | #1
Any news on this?

Felix

On Tue, 2023-09-19 at 03:43 +0000, Felix Moessbauer wrote:
> Previously, the /var mount is only located by the partition label.
> This
> is problematic, as collisions on this label might happen when working
> with multiple disks. This patch makes the method to find the /var
> partition configurable. By that, downstream implementations can use
> UUID
> or PARTUUID based mounting.
> 
> For backwards compatibility we keep the current label-based mounting
> as
> default.
> 
> Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> ---
> While debugging this, I found many more locations where mounts happen
> based on the disk label but not the UUID. All that should be changed
> to
> UUID or PARTUUID based mounting in the future. However, we do not
> have
> stable UUIDs for a long time in cip-core, so all that must be
> implemented in a backwards compatible manner. Otherwise the swupdate
> paths breaks.
> 
> In addition, all the UUIDs should be provided by the user and not via
> a
> default in cip-core. Otherwise collisions are likely to happen in the
> field.
> 
> Note on testing: This patch has been tested in a MTDA setup, where
> another swupdate image (of a different product) has been attached via
> an
> sdwire interface. As the sdwire interfaces automatically connects the
> storage to the host after reboot, the wrong /var got mounted before
> having this patch.
> 
> Best regards,
> Felix Moessbauer
> Siemens AG
> 
>  .../initramfs-overlay-hook/files/overlay.script.tmpl | 12 ++++++----
> --
>  .../initramfs-overlay-hook_0.1.bb                    |  5 +++--
>  2 files changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/recipes-initramfs/initramfs-overlay-
> hook/files/overlay.script.tmpl b/recipes-initramfs/initramfs-overlay-
> hook/files/overlay.script.tmpl
> index 71d2599..d7da6fb 100644
> --- a/recipes-initramfs/initramfs-overlay-
> hook/files/overlay.script.tmpl
> +++ b/recipes-initramfs/initramfs-overlay-
> hook/files/overlay.script.tmpl
> @@ -27,17 +27,17 @@ esac
>  . /scripts/functions
>  
>  
> -ovl_partition_label="${INITRAMFS_OVERLAY_STORAGE_PARTITION_LABEL}"
> +ovl_partition_device="${INITRAMFS_OVERLAY_STORAGE_DEVICE}"
>  ovl_storage_path="${INITRAMFS_OVERLAY_STORAGE_PATH}"
>  ovl_lower_dirs="${INITRAMFS_OVERLAY_PATHS}"
>  
>  root_mount_storage=${rootmnt}${ovl_storage_path}
>  
> -if ! mountpoint -q "${rootmnt}/${ovl_partition_label}"; then
> -       if ! mount -t $(get_fstype /dev/disk/by-
> label/${ovl_partition_label}) \
> -                /dev/disk/by-label/${ovl_partition_label} \
> -                ${rootmnt}/${ovl_partition_label}; then
> -               panic "Can't mount /${ovl_partition_label} partition
> - overlay will not work!"
> +if ! mountpoint -q "${rootmnt}/var"; then
> +       if ! mount -t $(get_fstype ${ovl_partition_device}) \
> +                ${ovl_partition_device} \
> +                ${rootmnt}/var; then
> +               panic "Can't mount /var partition - overlay will not
> work!"
>         fi
>  fi
>  
> diff --git a/recipes-initramfs/initramfs-overlay-hook/initramfs-
> overlay-hook_0.1.bb b/recipes-initramfs/initramfs-overlay-
> hook/initramfs-overlay-hook_0.1.bb
> index 566bd15..9e78dc8 100644
> --- a/recipes-initramfs/initramfs-overlay-hook/initramfs-overlay-
> hook_0.1.bb
> +++ b/recipes-initramfs/initramfs-overlay-hook/initramfs-overlay-
> hook_0.1.bb
> @@ -19,12 +19,13 @@ SRC_URI += " \
>  
>  INITRAMFS_OVERLAY_PATHS ??= "/etc"
>  INITRAMFS_OVERLAY_STORAGE_PATH ??= "/var/local"
> -INITRAMFS_OVERLAY_STORAGE_PARTITION_LABEL ??= "var"
> +# override this to switch to UUID or PARTUUID based mounts
> +INITRAMFS_OVERLAY_STORAGE_DEVICE ??= "/dev/disk/by-label/var"
>  
>  TEMPLATE_FILES = "overlay.script.tmpl"
>  TEMPLATE_VARS += " INITRAMFS_OVERLAY_STORAGE_PATH \
>      INITRAMFS_OVERLAY_PATHS \
> -    INITRAMFS_OVERLAY_STORAGE_PARTITION_LABEL"
> +    INITRAMFS_OVERLAY_STORAGE_DEVICE"
>  
>  DEBIAN_DEPENDS = "initramfs-tools, awk, coreutils, util-linux"
>
Jan Kiszka Oct. 7, 2023, 5:41 a.m. UTC | #2
On 07.10.23 07:37, MOESSBAUER, Felix (T CED INW-CN) wrote:
> Any news on this?
> 

Never reached my inbox, therefore missed. But I also received no other
reactions/reviews.

And as you are writing that there are more cases: Don't they need
similar adjustments?

Jan

> Felix
> 
> On Tue, 2023-09-19 at 03:43 +0000, Felix Moessbauer wrote:
>> Previously, the /var mount is only located by the partition label.
>> This
>> is problematic, as collisions on this label might happen when working
>> with multiple disks. This patch makes the method to find the /var
>> partition configurable. By that, downstream implementations can use
>> UUID
>> or PARTUUID based mounting.
>>
>> For backwards compatibility we keep the current label-based mounting
>> as
>> default.
>>
>> Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
>> ---
>> While debugging this, I found many more locations where mounts happen
>> based on the disk label but not the UUID. All that should be changed
>> to
>> UUID or PARTUUID based mounting in the future. However, we do not
>> have
>> stable UUIDs for a long time in cip-core, so all that must be
>> implemented in a backwards compatible manner. Otherwise the swupdate
>> paths breaks.
>>
>> In addition, all the UUIDs should be provided by the user and not via
>> a
>> default in cip-core. Otherwise collisions are likely to happen in the
>> field.
>>
>> Note on testing: This patch has been tested in a MTDA setup, where
>> another swupdate image (of a different product) has been attached via
>> an
>> sdwire interface. As the sdwire interfaces automatically connects the
>> storage to the host after reboot, the wrong /var got mounted before
>> having this patch.
>>
>> Best regards,
>> Felix Moessbauer
>> Siemens AG
>>
>>  .../initramfs-overlay-hook/files/overlay.script.tmpl | 12 ++++++----
>> --
>>  .../initramfs-overlay-hook_0.1.bb                    |  5 +++--
>>  2 files changed, 9 insertions(+), 8 deletions(-)
>>
>> diff --git a/recipes-initramfs/initramfs-overlay-
>> hook/files/overlay.script.tmpl b/recipes-initramfs/initramfs-overlay-
>> hook/files/overlay.script.tmpl
>> index 71d2599..d7da6fb 100644
>> --- a/recipes-initramfs/initramfs-overlay-
>> hook/files/overlay.script.tmpl
>> +++ b/recipes-initramfs/initramfs-overlay-
>> hook/files/overlay.script.tmpl
>> @@ -27,17 +27,17 @@ esac
>>  . /scripts/functions
>>
>>
>> -ovl_partition_label="${INITRAMFS_OVERLAY_STORAGE_PARTITION_LABEL}"
>> +ovl_partition_device="${INITRAMFS_OVERLAY_STORAGE_DEVICE}"
>>  ovl_storage_path="${INITRAMFS_OVERLAY_STORAGE_PATH}"
>>  ovl_lower_dirs="${INITRAMFS_OVERLAY_PATHS}"
>>
>>  root_mount_storage=${rootmnt}${ovl_storage_path}
>>
>> -if ! mountpoint -q "${rootmnt}/${ovl_partition_label}"; then
>> -       if ! mount -t $(get_fstype /dev/disk/by-
>> label/${ovl_partition_label}) \
>> -                /dev/disk/by-label/${ovl_partition_label} \
>> -                ${rootmnt}/${ovl_partition_label}; then
>> -               panic "Can't mount /${ovl_partition_label} partition
>> - overlay will not work!"
>> +if ! mountpoint -q "${rootmnt}/var"; then
>> +       if ! mount -t $(get_fstype ${ovl_partition_device}) \
>> +                ${ovl_partition_device} \
>> +                ${rootmnt}/var; then
>> +               panic "Can't mount /var partition - overlay will not
>> work!"
>>         fi
>>  fi
>>
>> diff --git a/recipes-initramfs/initramfs-overlay-hook/initramfs-
>> overlay-hook_0.1.bb b/recipes-initramfs/initramfs-overlay-
>> hook/initramfs-overlay-hook_0.1.bb
>> index 566bd15..9e78dc8 100644
>> --- a/recipes-initramfs/initramfs-overlay-hook/initramfs-overlay-
>> hook_0.1.bb
>> +++ b/recipes-initramfs/initramfs-overlay-hook/initramfs-overlay-
>> hook_0.1.bb
>> @@ -19,12 +19,13 @@ SRC_URI += " \
>>
>>  INITRAMFS_OVERLAY_PATHS ??= "/etc"
>>  INITRAMFS_OVERLAY_STORAGE_PATH ??= "/var/local"
>> -INITRAMFS_OVERLAY_STORAGE_PARTITION_LABEL ??= "var"
>> +# override this to switch to UUID or PARTUUID based mounts
>> +INITRAMFS_OVERLAY_STORAGE_DEVICE ??= "/dev/disk/by-label/var"
>>
>>  TEMPLATE_FILES = "overlay.script.tmpl"
>>  TEMPLATE_VARS += " INITRAMFS_OVERLAY_STORAGE_PATH \
>>      INITRAMFS_OVERLAY_PATHS \
>> -    INITRAMFS_OVERLAY_STORAGE_PARTITION_LABEL"
>> +    INITRAMFS_OVERLAY_STORAGE_DEVICE"
>>
>>  DEBIAN_DEPENDS = "initramfs-tools, awk, coreutils, util-linux"
>>
>
MOESSBAUER, Felix Oct. 7, 2023, 5:48 a.m. UTC | #3
On Sat, 2023-10-07 at 07:41 +0200, Jan Kiszka wrote:
> On 07.10.23 07:37, MOESSBAUER, Felix (T CED INW-CN) wrote:
> > Any news on this?
> > 
> 
> Never reached my inbox, therefore missed. But I also received no
> other
> reactions/reviews.
> 
> And as you are writing that there are more cases: Don't they need
> similar adjustments?

Yes, but I cannot provide these as I do not have a test setup for the
secure boot stuff. I prefer to merge this first and then discuss about
similar issues in the other initrd scripts.

Felix

> 
> Jan
> 
> > Felix
> > 
> > On Tue, 2023-09-19 at 03:43 +0000, Felix Moessbauer wrote:
> > > Previously, the /var mount is only located by the partition
> > > label.
> > > This
> > > is problematic, as collisions on this label might happen when
> > > working
> > > with multiple disks. This patch makes the method to find the /var
> > > partition configurable. By that, downstream implementations can
> > > use
> > > UUID
> > > or PARTUUID based mounting.
> > > 
> > > For backwards compatibility we keep the current label-based
> > > mounting
> > > as
> > > default.
> > > 
> > > Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> > > ---
> > > While debugging this, I found many more locations where mounts
> > > happen
> > > based on the disk label but not the UUID. All that should be
> > > changed
> > > to
> > > UUID or PARTUUID based mounting in the future. However, we do not
> > > have
> > > stable UUIDs for a long time in cip-core, so all that must be
> > > implemented in a backwards compatible manner. Otherwise the
> > > swupdate
> > > paths breaks.
> > > 
> > > In addition, all the UUIDs should be provided by the user and not
> > > via
> > > a
> > > default in cip-core. Otherwise collisions are likely to happen in
> > > the
> > > field.
> > > 
> > > Note on testing: This patch has been tested in a MTDA setup,
> > > where
> > > another swupdate image (of a different product) has been attached
> > > via
> > > an
> > > sdwire interface. As the sdwire interfaces automatically connects
> > > the
> > > storage to the host after reboot, the wrong /var got mounted
> > > before
> > > having this patch.
> > > 
> > > Best regards,
> > > Felix Moessbauer
> > > Siemens AG
> > > 
> > >  .../initramfs-overlay-hook/files/overlay.script.tmpl | 12
> > > ++++++----
> > > --
> > >  .../initramfs-overlay-hook_0.1.bb                    |  5 +++--
> > >  2 files changed, 9 insertions(+), 8 deletions(-)
> > > 
> > > diff --git a/recipes-initramfs/initramfs-overlay-
> > > hook/files/overlay.script.tmpl b/recipes-initramfs/initramfs-
> > > overlay-
> > > hook/files/overlay.script.tmpl
> > > index 71d2599..d7da6fb 100644
> > > --- a/recipes-initramfs/initramfs-overlay-
> > > hook/files/overlay.script.tmpl
> > > +++ b/recipes-initramfs/initramfs-overlay-
> > > hook/files/overlay.script.tmpl
> > > @@ -27,17 +27,17 @@ esac
> > >  . /scripts/functions
> > > 
> > > 
> > > -
> > > ovl_partition_label="${INITRAMFS_OVERLAY_STORAGE_PARTITION_LABEL}"
> > > +ovl_partition_device="${INITRAMFS_OVERLAY_STORAGE_DEVICE}"
> > >  ovl_storage_path="${INITRAMFS_OVERLAY_STORAGE_PATH}"
> > >  ovl_lower_dirs="${INITRAMFS_OVERLAY_PATHS}"
> > > 
> > >  root_mount_storage=${rootmnt}${ovl_storage_path}
> > > 
> > > -if ! mountpoint -q "${rootmnt}/${ovl_partition_label}"; then
> > > -       if ! mount -t $(get_fstype /dev/disk/by-
> > > label/${ovl_partition_label}) \
> > > -                /dev/disk/by-label/${ovl_partition_label} \
> > > -                ${rootmnt}/${ovl_partition_label}; then
> > > -               panic "Can't mount /${ovl_partition_label}
> > > partition
> > > - overlay will not work!"
> > > +if ! mountpoint -q "${rootmnt}/var"; then
> > > +       if ! mount -t $(get_fstype ${ovl_partition_device}) \
> > > +                ${ovl_partition_device} \
> > > +                ${rootmnt}/var; then
> > > +               panic "Can't mount /var partition - overlay will
> > > not
> > > work!"
> > >         fi
> > >  fi
> > > 
> > > diff --git a/recipes-initramfs/initramfs-overlay-hook/initramfs-
> > > overlay-hook_0.1.bb b/recipes-initramfs/initramfs-overlay-
> > > hook/initramfs-overlay-hook_0.1.bb
> > > index 566bd15..9e78dc8 100644
> > > --- a/recipes-initramfs/initramfs-overlay-hook/initramfs-overlay-
> > > hook_0.1.bb
> > > +++ b/recipes-initramfs/initramfs-overlay-hook/initramfs-overlay-
> > > hook_0.1.bb
> > > @@ -19,12 +19,13 @@ SRC_URI += " \
> > > 
> > >  INITRAMFS_OVERLAY_PATHS ??= "/etc"
> > >  INITRAMFS_OVERLAY_STORAGE_PATH ??= "/var/local"
> > > -INITRAMFS_OVERLAY_STORAGE_PARTITION_LABEL ??= "var"
> > > +# override this to switch to UUID or PARTUUID based mounts
> > > +INITRAMFS_OVERLAY_STORAGE_DEVICE ??= "/dev/disk/by-label/var"
> > > 
> > >  TEMPLATE_FILES = "overlay.script.tmpl"
> > >  TEMPLATE_VARS += " INITRAMFS_OVERLAY_STORAGE_PATH \
> > >      INITRAMFS_OVERLAY_PATHS \
> > > -    INITRAMFS_OVERLAY_STORAGE_PARTITION_LABEL"
> > > +    INITRAMFS_OVERLAY_STORAGE_DEVICE"
> > > 
> > >  DEBIAN_DEPENDS = "initramfs-tools, awk, coreutils, util-linux"
> > > 
> > 
>
diff mbox series

Patch

diff --git a/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl b/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
index 71d2599..d7da6fb 100644
--- a/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
+++ b/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
@@ -27,17 +27,17 @@  esac
 . /scripts/functions
 
 
-ovl_partition_label="${INITRAMFS_OVERLAY_STORAGE_PARTITION_LABEL}"
+ovl_partition_device="${INITRAMFS_OVERLAY_STORAGE_DEVICE}"
 ovl_storage_path="${INITRAMFS_OVERLAY_STORAGE_PATH}"
 ovl_lower_dirs="${INITRAMFS_OVERLAY_PATHS}"
 
 root_mount_storage=${rootmnt}${ovl_storage_path}
 
-if ! mountpoint -q "${rootmnt}/${ovl_partition_label}"; then
-	if ! mount -t $(get_fstype /dev/disk/by-label/${ovl_partition_label}) \
-		 /dev/disk/by-label/${ovl_partition_label} \
-		 ${rootmnt}/${ovl_partition_label}; then
-		panic "Can't mount /${ovl_partition_label} partition - overlay will not work!"
+if ! mountpoint -q "${rootmnt}/var"; then
+	if ! mount -t $(get_fstype ${ovl_partition_device}) \
+		 ${ovl_partition_device} \
+		 ${rootmnt}/var; then
+		panic "Can't mount /var partition - overlay will not work!"
 	fi
 fi
 
diff --git a/recipes-initramfs/initramfs-overlay-hook/initramfs-overlay-hook_0.1.bb b/recipes-initramfs/initramfs-overlay-hook/initramfs-overlay-hook_0.1.bb
index 566bd15..9e78dc8 100644
--- a/recipes-initramfs/initramfs-overlay-hook/initramfs-overlay-hook_0.1.bb
+++ b/recipes-initramfs/initramfs-overlay-hook/initramfs-overlay-hook_0.1.bb
@@ -19,12 +19,13 @@  SRC_URI += " \
 
 INITRAMFS_OVERLAY_PATHS ??= "/etc"
 INITRAMFS_OVERLAY_STORAGE_PATH ??= "/var/local"
-INITRAMFS_OVERLAY_STORAGE_PARTITION_LABEL ??= "var"
+# override this to switch to UUID or PARTUUID based mounts
+INITRAMFS_OVERLAY_STORAGE_DEVICE ??= "/dev/disk/by-label/var"
 
 TEMPLATE_FILES = "overlay.script.tmpl"
 TEMPLATE_VARS += " INITRAMFS_OVERLAY_STORAGE_PATH \
     INITRAMFS_OVERLAY_PATHS \
-    INITRAMFS_OVERLAY_STORAGE_PARTITION_LABEL"
+    INITRAMFS_OVERLAY_STORAGE_DEVICE"
 
 DEBIAN_DEPENDS = "initramfs-tools, awk, coreutils, util-linux"