[PATCH] initramfs-fsck-hook: bump version and improve error handling

52 views
Skip to first unread message

Rakesh Kumar

unread,
Sep 6, 2024, 5:39:38 AM9/6/24
to isar-...@googlegroups.com, jan.k...@siemens.com, cedric.h...@siemens.com, Rakesh Kumar
* Bump initramfs-fsck-hook version from 0.2 to 0.3.
* Renamed the package from initramfs-fsck-hook-ext4 to initramfs-fsck-ext4
for better readability.
* Improved error handling in the hook script by introducing the
hook_error() function to handle failures during copy_exec calls.
* Corrected the path for fsck from /sbin/fsck to /usr/sbin/fsck to
reflect the correct location of the binary.

The script now provides clear error messages and exits on failure,
preventing silent errors during the initramfs setup.

Signed-off-by: Rakesh Kumar <kumar....@siemens.com>
---
...sck.ext4.hook => initramfs-fsck-ext4.hook} | 21 +++++++------------
....triggers => initramfs-fsck-ext4.triggers} | 0
.../initramfs-fsck-ext4_0.3.bb | 19 +++++++++++++++++
.../initramfs-fsck-hook-ext4_0.2.bb | 18 ----------------
4 files changed, 26 insertions(+), 32 deletions(-)
rename meta/recipes-support/initramfs-fsck-hook/files/{initramfs.fsck.ext4.hook => initramfs-fsck-ext4.hook} (51%)
rename meta/recipes-support/initramfs-fsck-hook/files/{initramfs-fsck-hook-ext4.triggers => initramfs-fsck-ext4.triggers} (100%)
create mode 100644 meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-ext4_0.3.bb
delete mode 100644 meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb

diff --git a/meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook b/meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-ext4.hook
similarity index 51%
rename from meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook
rename to meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-ext4.hook
index 259b73b4..e81f06f9 100644
--- a/meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook
+++ b/meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-ext4.hook
@@ -5,8 +5,6 @@

#!/bin/sh

-set -e
-
PREREQ=""

prereqs()
@@ -24,16 +22,11 @@ esac
. /usr/share/initramfs-tools/scripts/functions
. /usr/share/initramfs-tools/hook-functions

-if [ ! -x /sbin/fsck ]; then
- echo "Warning: couldn't find /sbin/fsck!"
- exit 0
-fi
-
-copy_exec /sbin/fsck
-copy_exec /sbin/logsave
+hook_error() {
+ echo "(ERROR): $1" >&2
+ exit 1
+}

-if prog="$(command -v fsck.ext4)"; then
- copy_exec "$prog"
-else
- echo "Warning: /sbin/fsck.ext4 doesn't exist, can't install to initramfs, ignoring."
-fi
+copy_exec /usr/sbin/fsck || hook_error "Unable to copy /usr/sbin/fsck"
+copy_exec /usr/sbin/logsave || hook_error "Unable to copy /usr/sbin/logsave"
+copy_exec /usr/sbin/fsck.ext4 || hook_error "Unable to copy /usr/sbin/fsck.ext4"
diff --git a/meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers b/meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-ext4.triggers
similarity index 100%
rename from meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers
rename to meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-ext4.triggers
diff --git a/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-ext4_0.3.bb b/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-ext4_0.3.bb
new file mode 100644
index 00000000..c2136f9d
--- /dev/null
+++ b/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-ext4_0.3.bb
@@ -0,0 +1,19 @@
+# This software is a part of ISAR.
+# Copyright (C) Siemens AG, 2019
+#
+# SPDX-License-Identifier: MIT
+
+
+DESCRIPTION = "Recipe to add fsck hook to the initramfs"
+
+DEBIAN_DEPENDS = "e2fsprogs,initramfs-tools"
+
+inherit dpkg-raw
+SRC_URI = "file://${PN}.triggers \
+ file://${PN}.hook \
+ "
+do_install[cleandirs] += "${D}/etc/initramfs-tools/hooks"
+
+do_install() {
+ install -m 0755 ${WORKDIR}/${PN}.hook ${D}/etc/initramfs-tools/hooks/
+}
diff --git a/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb b/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb
deleted file mode 100644
index 9860dbc8..00000000
--- a/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb
+++ /dev/null
@@ -1,18 +0,0 @@
-# This software is a part of ISAR.
-# Copyright (C) Siemens AG, 2019
-#
-# SPDX-License-Identifier: MIT
-
-
-DESCRIPTION = "Recipe to add fsck hook to the initramfs"
-
-inherit dpkg-raw
-SRC_URI = "file://initramfs-fsck-hook-ext4.triggers \
- file://initramfs.fsck.ext4.hook \
- "
-
-
-do_install() {
- install -m 0755 -d ${D}/etc/initramfs-tools/hooks
- install -m 0740 ${WORKDIR}/initramfs.fsck.ext4.hook ${D}/etc/initramfs-tools/hooks/fsck.ext4.hook
-}
--
2.39.2

Jan Kiszka

unread,
Sep 6, 2024, 5:56:25 AM9/6/24
to Rakesh Kumar, isar-...@googlegroups.com, cedric.h...@siemens.com
On 06.09.24 11:39, Rakesh Kumar wrote:
> * Bump initramfs-fsck-hook version from 0.2 to 0.3.
> * Renamed the package from initramfs-fsck-hook-ext4 to initramfs-fsck-ext4
> for better readability.
> * Improved error handling in the hook script by introducing the
> hook_error() function to handle failures during copy_exec calls.
> * Corrected the path for fsck from /sbin/fsck to /usr/sbin/fsck to
> reflect the correct location of the binary.

4 topics, 4 patches. Well, maybe 3. But not just 1.

Jan
Siemens AG, Technology
Linux Expert Center

Rakesh Kumar

unread,
Sep 7, 2024, 12:51:31 PM9/7/24
to isar-...@googlegroups.com, jan.k...@siemens.com, cedric.h...@siemens.com, Rakesh Kumar
* Bump initramfs-fsck-hook version from 0.2 to 0.3.
* Renamed package from initramfs-fsck-hook-ext4 to initramfs-fsck-ext4
for better readability.
* Renamed hook and trigger files for better readability.

Signed-off-by: Rakesh Kumar <kumar....@siemens.com>
---
...sck.ext4.hook => initramfs-fsck-ext4.hook} | 0
....triggers => initramfs-fsck-ext4.triggers} | 0
.../initramfs-fsck-ext4_0.3.bb | 20 +++++++++++++++++++
.../initramfs-fsck-hook-ext4_0.2.bb | 18 -----------------
4 files changed, 20 insertions(+), 18 deletions(-)
rename meta/recipes-support/initramfs-fsck-hook/files/{initramfs.fsck.ext4.hook => initramfs-fsck-ext4.hook} (100%)
rename meta/recipes-support/initramfs-fsck-hook/files/{initramfs-fsck-hook-ext4.triggers => initramfs-fsck-ext4.triggers} (100%)
create mode 100644 meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-ext4_0.3.bb
delete mode 100644 meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb

diff --git a/meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook b/meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-ext4.hook
similarity index 100%
rename from meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook
rename to meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-ext4.hook
diff --git a/meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers b/meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-ext4.triggers
similarity index 100%
rename from meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers
rename to meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-ext4.triggers
diff --git a/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-ext4_0.3.bb b/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-ext4_0.3.bb
new file mode 100644
index 00000000..de19828c
--- /dev/null
+++ b/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-ext4_0.3.bb
@@ -0,0 +1,20 @@
2.39.2

Rakesh Kumar

unread,
Sep 7, 2024, 12:51:35 PM9/7/24
to isar-...@googlegroups.com, jan.k...@siemens.com, cedric.h...@siemens.com, Rakesh Kumar
* Used hook_error() function to improve error handling during
copy_exec calls in the initramfs hook script.
* Corrected the path for fsck from /sbin/fsck to /usr/sbin/fsck.

Signed-off-by: Rakesh Kumar <kumar....@siemens.com>
---
.../files/initramfs-fsck-ext4.hook | 21 +++++++------------
1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-ext4.hook b/meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-ext4.hook
index 259b73b4..4762c805 100644
--- a/meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-ext4.hook
+copy_exec /sbin/fsck || hook_error "Unable to copy /usr/sbin/fsck"
+copy_exec /sbin/logsave || hook_error "Unable to copy /usr/sbin/logsave"
+copy_exec /usr/sbin/fsck.ext4 || hook_error "Unable to copy /usr/sbin/fsck.ext4"
--
2.39.2

Rakesh Kumar

unread,
Sep 7, 2024, 1:00:01 PM9/7/24
to isar-...@googlegroups.com, Rakesh Kumar
This patch series makes two significant changes to the initramfs-fsck-hook recipe:
1. Bumps the version from 0.2 to 0.3, renames the package, hook and trigger files for better readability.
2. Used better error handling in the hook script by adding the hook_error() function and correcting the path to /usr/sbin/fsck.

Rakesh Kumar (2):
initramfs-fsck-hook: bump version, rename package and files
initramfs-fsck-hook: improve error handling and correct fsck path

...sck.ext4.hook => initramfs-fsck-ext4.hook} | 21 +++++++------------
....triggers => initramfs-fsck-ext4.triggers} | 0
.../initramfs-fsck-ext4_0.3.bb | 20 ++++++++++++++++++
.../initramfs-fsck-hook-ext4_0.2.bb | 18 ----------------
4 files changed, 27 insertions(+), 32 deletions(-)
rename meta/recipes-support/initramfs-fsck-hook/files/{initramfs.fsck.ext4.hook => initramfs-fsck-ext4.hook} (51%)
rename meta/recipes-support/initramfs-fsck-hook/files/{initramfs-fsck-hook-ext4.triggers => initramfs-fsck-ext4.triggers} (100%)
create mode 100644 meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-ext4_0.3.bb
delete mode 100644 meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb

--
2.39.2

cedric.h...@siemens.com

unread,
Sep 8, 2024, 11:13:41 PM9/8/24
to isar-...@googlegroups.com, Kumar, Rakesh, Kiszka, Jan
On Sat, 2024-09-07 at 22:21 +0530, Rakesh Kumar wrote:
> * Used hook_error() function to improve error handling during
>   copy_exec calls in the initramfs hook script.

Rather than paraphrasing each copy_exec call, I would mimic what Debian
hooks such as /usr/share/initramfs-tools/hooks/{fuse,plymouth} do: have
the hook use "set -e" towards the beginning of the script to simply
abort as soon as a command fail.

set -e
copy_exec ...
copy_exec ...


> * Corrected the path for fsck from /sbin/fsck to /usr/sbin/fsck.

I am sorry but /sbin/fsck is correct

# dpkg -S /usr/sbin/fsck
dpkg-query: no path found matching pattern /usr/sbin/fsck
# dpkg -S /sbin/fsck
util-linux: /sbin/fsck

cedric.h...@siemens.com

unread,
Sep 8, 2024, 11:15:41 PM9/8/24
to isar-...@googlegroups.com, Kumar, Rakesh, Kiszka, Jan
On Sat, 2024-09-07 at 22:21 +0530, Rakesh Kumar wrote:
> * Bump initramfs-fsck-hook version from 0.2 to 0.3.
> * Renamed package from initramfs-fsck-hook-ext4 to initramfs-fsck-
> ext4
>   for better readability.

Chances of breaking downstream layers are too high
> rename from meta/recipes-support/initramfs-fsck-hook/files/initramfs-
> fsck-hook-ext4.triggers
> rename to meta/recipes-support/initramfs-fsck-hook/files/initramfs-
> fsck-ext4.triggers
> diff --git a/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-
> ext4_0.3.bb b/meta/recipes-support/initramfs-fsck-hook/initramfs-
Cedric Hombourger
Siemens AG
www.siemens.com
Reply all
Reply to author
Forward
0 new messages