* [cip-dev] [isar-cip-core][PATCH v4] initramfs-overlay-hook: Check file system of INITRAMFS_OVERLAY_STORAGE_DEVICE
@ 2024-07-15 13:46 'Clara Kowalsky' via isar-users
2024-07-15 13:51 ` 'Kowalsky, Clara' via isar-users
0 siblings, 1 reply; 2+ messages in thread
From: 'Clara Kowalsky' via isar-users @ 2024-07-15 13:46 UTC (permalink / raw)
To: isar-users; +Cc: quirin.gylstorff, Clara Kowalsky
In case of ext*, this detects and fixes file system errors in the
partition device before doing the partition mount.
If the partition turns out to be broken, the factory state is recovered.
Signed-off-by: Clara Kowalsky <clara.kowalsky@siemens.com>
---
.../initramfs-overlay-hook/files/overlay.hook | 11 +++++++++--
.../files/overlay.script.tmpl | 11 ++++++++++-
.../files/overlay_recovery_action.script | 14 ++++++++++++++
.../initramfs-overlay-hook_0.1.bb | 8 +++++++-
4 files changed, 40 insertions(+), 4 deletions(-)
create mode 100644 recipes-initramfs/initramfs-overlay-hook/files/overlay_recovery_action.script
diff --git a/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook b/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
index 8b00ecf..6f634c5 100644
--- a/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
+++ b/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
@@ -22,6 +22,13 @@ esac
. /usr/share/initramfs-tools/hook-functions
+hook_error() {
+ echo "(ERROR): $1" >&2
+ exit 1
+}
+
manual_add_modules overlay
-copy_exec /usr/bin/mountpoint
-copy_exec /usr/bin/awk
+copy_exec /usr/bin/mountpoint || hook_error "/usr/bin/mountpoint not found"
+copy_exec /usr/bin/awk || hook_error "/usr/bin/awk not found"
+copy_exec /usr/sbin/e2fsck || hook_error "/usr/sbin/e2fsck not found"
+copy_exec /usr/sbin/mke2fs || hook_error "/usr/sbin/mke2fs not found"
diff --git a/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl b/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
index 42eb59c..deda034 100644
--- a/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
+++ b/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
@@ -31,12 +31,21 @@ ovl_partition_device="${INITRAMFS_OVERLAY_STORAGE_DEVICE}"
ovl_storage_path="${INITRAMFS_OVERLAY_STORAGE_PATH}"
ovl_lower_dirs="${INITRAMFS_OVERLAY_PATHS}"
ovl_mount_option="${INITRAMFS_OVERLAY_MOUNT_OPTION}"
+ovl_recovery_script="/scripts/${INITRAMFS_OVERLAY_RECOVERY_SCRIPT}"
root_mount_storage=${rootmnt}${ovl_storage_path}
storage_mount_point="$(echo "${ovl_storage_path}" | awk -F/ '{print FS$2}' )"
+partition_fstype=$(get_fstype "${ovl_partition_device}")
if ! mountpoint -q "${rootmnt}${storage_mount_point}"; then
- if ! mount -t $(get_fstype ${ovl_partition_device}) \
+ if [ "$partition_fstype" = "ext*" ]; then
+ if ! e2fsck -p -f "$ovl_partition_device"; then
+ if [ -f "$ovl_recovery_script" ] && [ -x "$ovl_recovery_script" ]; then
+ "$ovl_recovery_script" "$ovl_partition_device" "$partition_fstype"
+ fi
+ fi
+ fi
+ if ! mount -t ${partition_fstype} \
-o ${ovl_mount_option} \
${ovl_partition_device} \
${rootmnt}${storage_mount_point}; then
diff --git a/recipes-initramfs/initramfs-overlay-hook/files/overlay_recovery_action.script b/recipes-initramfs/initramfs-overlay-hook/files/overlay_recovery_action.script
new file mode 100644
index 0000000..4ef0148
--- /dev/null
+++ b/recipes-initramfs/initramfs-overlay-hook/files/overlay_recovery_action.script
@@ -0,0 +1,14 @@
+#!/bin/sh
+#
+# CIP Core, generic profile
+#
+# Copyright (c) Siemens AG, 2024
+#
+# Authors:
+# Clara Kowalsky <clara.kowalsky@siemens.com>
+#
+
+ovl_partition_device="$1"
+partition_fstype="$2"
+
+mke2fs -t "$partition_fstype" "$ovl_partition_device"
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 955748f..7097130 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
@@ -12,9 +12,12 @@
inherit dpkg-raw
+INITRAMFS_OVERLAY_RECOVERY_SCRIPT ??= "overlay_recovery_action.script"
+
SRC_URI += " \
file://overlay.hook \
file://overlay.script.tmpl \
+ file://${INITRAMFS_OVERLAY_RECOVERY_SCRIPT} \
"
# The variable INITRAMFS_OVERLAY_PATHS contains the directories which are
@@ -35,7 +38,8 @@ TEMPLATE_FILES = "overlay.script.tmpl"
TEMPLATE_VARS += " INITRAMFS_OVERLAY_STORAGE_PATH \
INITRAMFS_OVERLAY_PATHS \
INITRAMFS_OVERLAY_STORAGE_DEVICE \
- INITRAMFS_OVERLAY_MOUNT_OPTION"
+ INITRAMFS_OVERLAY_MOUNT_OPTION \
+ INITRAMFS_OVERLAY_RECOVERY_SCRIPT"
DEBIAN_DEPENDS = "initramfs-tools, awk, coreutils, util-linux"
@@ -48,4 +52,6 @@ do_install() {
"${D}/usr/share/initramfs-tools/hooks/overlay"
install -m 0755 "${WORKDIR}/overlay.script" \
"${D}/usr/share/initramfs-tools/scripts/local-bottom/overlay"
+ install -m 0755 "${WORKDIR}/${INITRAMFS_OVERLAY_RECOVERY_SCRIPT}" \
+ "${D}/usr/share/initramfs-tools/scripts"
}
--
2.45.2
--
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/isar-users/20240715134643.901757-1-clara.kowalsky%40siemens.com.
^ permalink raw reply [flat|nested] 2+ messages in thread
* RE: [cip-dev] [isar-cip-core][PATCH v4] initramfs-overlay-hook: Check file system of INITRAMFS_OVERLAY_STORAGE_DEVICE
2024-07-15 13:46 [cip-dev] [isar-cip-core][PATCH v4] initramfs-overlay-hook: Check file system of INITRAMFS_OVERLAY_STORAGE_DEVICE 'Clara Kowalsky' via isar-users
@ 2024-07-15 13:51 ` 'Kowalsky, Clara' via isar-users
0 siblings, 0 replies; 2+ messages in thread
From: 'Kowalsky, Clara' via isar-users @ 2024-07-15 13:51 UTC (permalink / raw)
To: isar-users; +Cc: quirin.gylstorff
Ups sorry, wrong list. :D
> -----Original Message-----
> From: Kowalsky, Clara (T CED OES-DE) <clara.kowalsky@siemens.com>
> Sent: Monday, July 15, 2024 3:47 PM
> To: isar-users@googlegroups.com
> Cc: Gylstorff, Quirin (T CED OES-DE) <quirin.gylstorff@siemens.com>; Kowalsky,
> Clara (T CED OES-DE) <clara.kowalsky@siemens.com>
> Subject: [cip-dev] [isar-cip-core][PATCH v4] initramfs-overlay-hook: Check file
> system of INITRAMFS_OVERLAY_STORAGE_DEVICE
>
> In case of ext*, this detects and fixes file system errors in the partition device
> before doing the partition mount.
> If the partition turns out to be broken, the factory state is recovered.
>
> Signed-off-by: Clara Kowalsky <clara.kowalsky@siemens.com>
> ---
> .../initramfs-overlay-hook/files/overlay.hook | 11 +++++++++--
> .../files/overlay.script.tmpl | 11 ++++++++++-
> .../files/overlay_recovery_action.script | 14 ++++++++++++++
> .../initramfs-overlay-hook_0.1.bb | 8 +++++++-
> 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 recipes-
> initramfs/initramfs-overlay-hook/files/overlay_recovery_action.script
>
> diff --git a/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook b/recipes-
> initramfs/initramfs-overlay-hook/files/overlay.hook
> index 8b00ecf..6f634c5 100644
> --- a/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
> +++ b/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
> @@ -22,6 +22,13 @@ esac
>
> . /usr/share/initramfs-tools/hook-functions
>
> +hook_error() {
> + echo "(ERROR): $1" >&2
> + exit 1
> +}
> +
> manual_add_modules overlay
> -copy_exec /usr/bin/mountpoint
> -copy_exec /usr/bin/awk
> +copy_exec /usr/bin/mountpoint || hook_error "/usr/bin/mountpoint not found"
> +copy_exec /usr/bin/awk || hook_error "/usr/bin/awk not found"
> +copy_exec /usr/sbin/e2fsck || hook_error "/usr/sbin/e2fsck not found"
> +copy_exec /usr/sbin/mke2fs || hook_error "/usr/sbin/mke2fs not found"
> diff --git a/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
> b/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
> index 42eb59c..deda034 100644
> --- a/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
> +++ b/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
> @@ -31,12 +31,21 @@
> ovl_partition_device="${INITRAMFS_OVERLAY_STORAGE_DEVICE}"
> ovl_storage_path="${INITRAMFS_OVERLAY_STORAGE_PATH}"
> ovl_lower_dirs="${INITRAMFS_OVERLAY_PATHS}"
> ovl_mount_option="${INITRAMFS_OVERLAY_MOUNT_OPTION}"
> +ovl_recovery_script="/scripts/${INITRAMFS_OVERLAY_RECOVERY_SCRIPT}"
>
> root_mount_storage=${rootmnt}${ovl_storage_path}
> storage_mount_point="$(echo "${ovl_storage_path}" | awk -F/ '{print FS$2}' )"
> +partition_fstype=$(get_fstype "${ovl_partition_device}")
>
> if ! mountpoint -q "${rootmnt}${storage_mount_point}"; then
> - if ! mount -t $(get_fstype ${ovl_partition_device}) \
> + if [ "$partition_fstype" = "ext*" ]; then
> + if ! e2fsck -p -f "$ovl_partition_device"; then
> + if [ -f "$ovl_recovery_script" ] && [ -x
> "$ovl_recovery_script" ]; then
> + "$ovl_recovery_script" "$ovl_partition_device"
> "$partition_fstype"
> + fi
> + fi
> + fi
> + if ! mount -t ${partition_fstype} \
> -o ${ovl_mount_option} \
> ${ovl_partition_device} \
> ${rootmnt}${storage_mount_point}; then diff --git a/recipes-
> initramfs/initramfs-overlay-hook/files/overlay_recovery_action.script b/recipes-
> initramfs/initramfs-overlay-hook/files/overlay_recovery_action.script
> new file mode 100644
> index 0000000..4ef0148
> --- /dev/null
> +++ b/recipes-initramfs/initramfs-overlay-hook/files/overlay_recovery_ac
> +++ tion.script
> @@ -0,0 +1,14 @@
> +#!/bin/sh
> +#
> +# CIP Core, generic profile
> +#
> +# Copyright (c) Siemens AG, 2024
> +#
> +# Authors:
> +# Clara Kowalsky <clara.kowalsky@siemens.com> #
> +
> +ovl_partition_device="$1"
> +partition_fstype="$2"
> +
> +mke2fs -t "$partition_fstype" "$ovl_partition_device"
> 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 955748f..7097130 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
> @@ -12,9 +12,12 @@
>
> inherit dpkg-raw
>
> +INITRAMFS_OVERLAY_RECOVERY_SCRIPT ??= "overlay_recovery_action.script"
> +
> SRC_URI += " \
> file://overlay.hook \
> file://overlay.script.tmpl \
> + file://${INITRAMFS_OVERLAY_RECOVERY_SCRIPT} \
> "
>
> # The variable INITRAMFS_OVERLAY_PATHS contains the directories which are
> @@ -35,7 +38,8 @@ TEMPLATE_FILES = "overlay.script.tmpl"
> TEMPLATE_VARS += " INITRAMFS_OVERLAY_STORAGE_PATH \
> INITRAMFS_OVERLAY_PATHS \
> INITRAMFS_OVERLAY_STORAGE_DEVICE \
> - INITRAMFS_OVERLAY_MOUNT_OPTION"
> + INITRAMFS_OVERLAY_MOUNT_OPTION \
> + INITRAMFS_OVERLAY_RECOVERY_SCRIPT"
>
> DEBIAN_DEPENDS = "initramfs-tools, awk, coreutils, util-linux"
>
> @@ -48,4 +52,6 @@ do_install() {
> "${D}/usr/share/initramfs-tools/hooks/overlay"
> install -m 0755 "${WORKDIR}/overlay.script" \
> "${D}/usr/share/initramfs-tools/scripts/local-bottom/overlay"
> + install -m 0755 "${WORKDIR}/${INITRAMFS_OVERLAY_RECOVERY_SCRIPT}" \
> + "${D}/usr/share/initramfs-tools/scripts"
> }
> --
> 2.45.2
--
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/isar-users/AS5PR10MB8173079DF4F1F4E6B8E647FF93A12%40AS5PR10MB8173.EURPRD10.PROD.OUTLOOK.COM.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-07-15 13:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-15 13:46 [cip-dev] [isar-cip-core][PATCH v4] initramfs-overlay-hook: Check file system of INITRAMFS_OVERLAY_STORAGE_DEVICE 'Clara Kowalsky' via isar-users
2024-07-15 13:51 ` 'Kowalsky, Clara' via isar-users
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox