diff mbox series

[isar-cip-core,v2,2/2] initramfs-overlay-hook: Check file system of INITRAMFS_OVERLAY_STORAGE_DEVICE

Message ID 20240626134141.74487-2-clara.kowalsky@siemens.com (mailing list archive)
State New
Headers show
Series [isar-cip-core,v2,1/2] initramfs-overlay-hook: Add INITRAMFS_OVERLAY_MOUNT_OPTION | expand

Commit Message

Kowalsky, Clara June 26, 2024, 1:41 p.m. UTC
In case of ext*, this detects and fixes file system errors in the
partition device before doing the partition mount.

Signed-off-by: Clara Kowalsky <clara.kowalsky@siemens.com>
---
 .../initramfs-overlay-hook/files/overlay.hook          | 10 ++++++++--
 .../initramfs-overlay-hook/files/overlay.script.tmpl   |  8 +++++++-
 2 files changed, 15 insertions(+), 3 deletions(-)

Comments

Jan Kiszka June 26, 2024, 1:56 p.m. UTC | #1
On 26.06.24 15:41, Clara Kowalsky wrote:
> In case of ext*, this detects and fixes file system errors in the
> partition device before doing the partition mount.
> 
> Signed-off-by: Clara Kowalsky <clara.kowalsky@siemens.com>
> ---
>  .../initramfs-overlay-hook/files/overlay.hook          | 10 ++++++++--
>  .../initramfs-overlay-hook/files/overlay.script.tmpl   |  8 +++++++-
>  2 files changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook b/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
> index 8b00ecf..1a54853 100644
> --- a/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
> +++ b/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
> @@ -22,6 +22,12 @@ 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"
> diff --git a/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl b/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
> index 42eb59c..6b404c6 100644
> --- a/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
> +++ b/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
> @@ -34,9 +34,15 @@ ovl_mount_option="${INITRAMFS_OVERLAY_MOUNT_OPTION}"
>  
>  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 "$partition_fstype"; then
> +			panic "E2fsck on ${ovl_partition_device} not successful!"

Err, this will break the boot without even a chance to go back to
factory state, no?

Jan

> +		fi
> +	fi
> +	if ! mount -t ${partition_fstype} \
>  		 -o ${ovl_mount_option} \
>  		 ${ovl_partition_device} \
>  		 ${rootmnt}${storage_mount_point}; then
Gylstorff Quirin June 28, 2024, 11:58 a.m. UTC | #2
On 6/26/24 3:56 PM, Jan Kiszka wrote:
> On 26.06.24 15:41, Clara Kowalsky wrote:
>> In case of ext*, this detects and fixes file system errors in the
>> partition device before doing the partition mount.
>>
>> Signed-off-by: Clara Kowalsky <clara.kowalsky@siemens.com>
>> ---
>>   .../initramfs-overlay-hook/files/overlay.hook          | 10 ++++++++--
>>   .../initramfs-overlay-hook/files/overlay.script.tmpl   |  8 +++++++-
>>   2 files changed, 15 insertions(+), 3 deletions(-)
>>
>> diff --git a/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook b/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
>> index 8b00ecf..1a54853 100644
>> --- a/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
>> +++ b/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
>> @@ -22,6 +22,12 @@ 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"
>> diff --git a/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl b/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
>> index 42eb59c..6b404c6 100644
>> --- a/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
>> +++ b/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
>> @@ -34,9 +34,15 @@ ovl_mount_option="${INITRAMFS_OVERLAY_MOUNT_OPTION}"
>>   
>>   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 "$partition_fstype"; then
>> +			panic "E2fsck on ${ovl_partition_device} not successful!"
> 
> Err, this will break the boot without even a chance to go back to
> factory state, no?
I would add a hook to a script which defines the action in case we 
cannot recover.

Quirin
> 
> Jan
> 
>> +		fi
>> +	fi
>> +	if ! mount -t ${partition_fstype} \
>>   		 -o ${ovl_mount_option} \
>>   		 ${ovl_partition_device} \
>>   		 ${rootmnt}${storage_mount_point}; then
>
Jan Kiszka June 28, 2024, 12:02 p.m. UTC | #3
On 28.06.24 13:58, Gylstorff Quirin wrote:
> 
> 
> On 6/26/24 3:56 PM, Jan Kiszka wrote:
>> On 26.06.24 15:41, Clara Kowalsky wrote:
>>> In case of ext*, this detects and fixes file system errors in the
>>> partition device before doing the partition mount.
>>>
>>> Signed-off-by: Clara Kowalsky <clara.kowalsky@siemens.com>
>>> ---
>>>   .../initramfs-overlay-hook/files/overlay.hook          | 10 ++++++++--
>>>   .../initramfs-overlay-hook/files/overlay.script.tmpl   |  8 +++++++-
>>>   2 files changed, 15 insertions(+), 3 deletions(-)
>>>
>>> diff --git
>>> a/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
>>> b/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
>>> index 8b00ecf..1a54853 100644
>>> --- a/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
>>> +++ b/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
>>> @@ -22,6 +22,12 @@ 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"
>>> diff --git
>>> a/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
>>> b/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
>>> index 42eb59c..6b404c6 100644
>>> --- a/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
>>> +++ b/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
>>> @@ -34,9 +34,15 @@ ovl_mount_option="${INITRAMFS_OVERLAY_MOUNT_OPTION}"
>>>     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 "$partition_fstype"; then
>>> +            panic "E2fsck on ${ovl_partition_device} not successful!"
>>
>> Err, this will break the boot without even a chance to go back to
>> factory state, no?
> I would add a hook to a script which defines the action in case we
> cannot recover.
> 

...and maybe already provide a default action that reformats (thus
wipes) the state.

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 8b00ecf..1a54853 100644
--- a/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
+++ b/recipes-initramfs/initramfs-overlay-hook/files/overlay.hook
@@ -22,6 +22,12 @@  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"
diff --git a/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl b/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
index 42eb59c..6b404c6 100644
--- a/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
+++ b/recipes-initramfs/initramfs-overlay-hook/files/overlay.script.tmpl
@@ -34,9 +34,15 @@  ovl_mount_option="${INITRAMFS_OVERLAY_MOUNT_OPTION}"
 
 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 "$partition_fstype"; then
+			panic "E2fsck on ${ovl_partition_device} not successful!"
+		fi
+	fi
+	if ! mount -t ${partition_fstype} \
 		 -o ${ovl_mount_option} \
 		 ${ovl_partition_device} \
 		 ${rootmnt}${storage_mount_point}; then