diff mbox series

[isar-cip-core,v3,6/8] overlay: add prerequisite 'encrypt_partition'

Message ID 20230224162832.327030-7-Quirin.Gylstorff@siemens.com (mailing list archive)
State Changes Requested
Headers show
Series Encrypt Partition in initramfs | expand

Commit Message

Gylstorff Quirin Feb. 24, 2023, 4:28 p.m. UTC
From: Quirin Gylstorff <quirin.gylstorff@siemens.com>

If /var shall be encrypted encrypt_partition needs to be executed
before the overlay script.

If the prerequisite is not available the overlay script will be executed.

Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
---
 .../initramfs-overlay-hook/files/overlay.hook        |  1 +
 .../initramfs-overlay-hook/files/overlay.script.tmpl | 12 +++++++-----
 2 files changed, 8 insertions(+), 5 deletions(-)

Comments

Jan Kiszka Feb. 27, 2023, 7:24 a.m. UTC | #1
On 24.02.23 17:28, Quirin Gylstorff wrote:
> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> 
> If /var shall be encrypted encrypt_partition needs to be executed
> before the overlay script.
> 
> If the prerequisite is not available the overlay script will be executed.
> 
> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> ---
>  .../initramfs-overlay-hook/files/overlay.hook        |  1 +
>  .../initramfs-overlay-hook/files/overlay.script.tmpl | 12 +++++++-----
>  2 files changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook b/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
> index 5bec258..bc6a682 100644
> --- a/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
> +++ b/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
> @@ -23,4 +23,5 @@ esac
>  . /usr/share/initramfs-tools/hook-functions
>  
>  manual_add_modules overlay
> +copy_exec /usr/bin/grep
>  copy_exec /usr/bin/awk
> diff --git a/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl b/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
> index 87ec72f..9739197 100644
> --- a/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
> +++ b/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
> @@ -9,7 +9,7 @@
>  #  Quirin Gylstorff <quirin.gylstorff@siemens.com>
>  #
>  
> -PREREQ=""
> +PREREQ="encrypt_partition"
>  
>  prereqs()
>  {
> @@ -33,10 +33,12 @@ ovl_lower_dirs="${INITRAMFS_OVERLAY_PATHS}"
>  
>  root_mount_storage=${rootmnt}${ovl_storage_path}
>  
> -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 ! grep -q "${rootmnt}/${ovl_partition_label}" /proc/mounts ; then

Maybe use mountpoint instead? More lightweight than grep.

> +	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!"
> +	fi
>  fi
>  
>  for ovl_lower_dir in ${ovl_lower_dirs}; do

Jan
diff mbox series

Patch

diff --git a/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook b/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
index 5bec258..bc6a682 100644
--- a/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
+++ b/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
@@ -23,4 +23,5 @@  esac
 . /usr/share/initramfs-tools/hook-functions
 
 manual_add_modules overlay
+copy_exec /usr/bin/grep
 copy_exec /usr/bin/awk
diff --git a/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl b/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
index 87ec72f..9739197 100644
--- a/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
+++ b/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
@@ -9,7 +9,7 @@ 
 #  Quirin Gylstorff <quirin.gylstorff@siemens.com>
 #
 
-PREREQ=""
+PREREQ="encrypt_partition"
 
 prereqs()
 {
@@ -33,10 +33,12 @@  ovl_lower_dirs="${INITRAMFS_OVERLAY_PATHS}"
 
 root_mount_storage=${rootmnt}${ovl_storage_path}
 
-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 ! grep -q "${rootmnt}/${ovl_partition_label}" /proc/mounts ; 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!"
+	fi
 fi
 
 for ovl_lower_dir in ${ovl_lower_dirs}; do