Skip to contentSkip to conversation

some init/finish enhancements for initramfs-framework

PATCH In review Patrick Ohly 2 participants 9 messages Sep 9, 2015

lore
Share & tools
lore
#0 lore raw

cover some init/finish enhancements for initramfs-framework

While continuing my work in integrating IMA into the initramfs-framework, I found that it is necessary to have more control over the mount parameters. These patches grant that control using the same boot parameters as in the Linux kernel.

For debugging I also found it useful to have more opportunities to get into a shell.

I'm posting these patches because others may also find them useful. If there's no time to review or merge now, feel free to ignore until after the next release. In the meantime, I'll proceed with a local copy of the two files.

The following changes since commit 8402958cd2cb87b8283c8ee4e2d08e1a6717d67a:

pseudo_1.7.3.bb: New version of pseudo (2015-09-06 15:24:28 +0100)

are available in the git repository at:

git://github.com/pohly/openembedded-core initramfs-framework
https://github.com/pohly/openembedded-core/tree/initramfs-framework

Patrick Ohly (4):
initramfs-framework: support rootflags and rootfstype boot parameter
initramfs-framework: support ro boot parameter
initramfs-framework: support init boot parameter
initramfs-framework: support dropping into shell on failure

 .../initrdscripts/initramfs-framework/finish            | 17 +++++++++++++++--
 .../recipes-core/initrdscripts/initramfs-framework/init |  4 ++++
 2 files changed, 19 insertions(+), 2 deletions(-)
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/4 initramfs-framework: support rootflags and rootfstype boot parameter

These two parameters are supported by the kernel
(https://www.kernel.org/doc/Documentation/kernel-parameters.txt). When an initramfs is used, the kernel does not mount the rootfs and the initramfs needs to react to them.

The boot parameters can be set both by the image creator and by users.

Supporting these two parameters is useful:
- rootflags is needed to ensure that the rootfs is already mounted as intended in the time between starting init and init remounting it (as systemd does); this is critical for IMA where iversion must be active already when system starts writing files.
- setting it correctly up-front avoids messages from the kernel ("cannot mount ... as ext2 because ...") when trying to guess the desired type.

For example, assuming that only one of ext4/ext3/ext2 is set,
rootfstype could be set in an image recipe with:
APPEND_append = "${@''.join([' rootfstype=' + i for i in ['ext4', 'ext3', 'ext2'] if i in d.getVar('IMAGE_FSTYPES', True).split()])}"

---
 meta/recipes-core/initrdscripts/initramfs-framework/finish | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
meta/recipes-core/initrdscripts/initramfs-framework/finish +8 -1
index 325f47b..006aef2 100755
@@ -22,7 +22,14 @@ finish_run() {
 			fi
 
 			if [ -e "$bootparam_root" ]; then
-				mount $bootparam_root $ROOTFS_DIR
+				flags=""
+				if [ -n "$bootparam_rootflags" ]; then
+					flags="$flags -o$bootparam_rootflags"
+				fi
+				if [ -n "$bootparam_rootfstype" ]; then
+					flags="$flags -t$bootparam_rootfstype"
+				fi
+				mount $flags $bootparam_root $ROOTFS_DIR
 			else
 				debug "root '$bootparam_root' doesn't exist."
 			fi
Signature · 1 line
2.1.4
#2 lore raw

PATCH 2/4 initramfs-framework: support ro boot parameter

Default is to mount the rootfs read/write. "ro" can be used to turn that into read-only, which is useful on systems where userspace does an fsck before remounting read-write.

Giving both "ro" and "rw" will still mount read-only regardless of the order, because the ordering information is not preserved by the initramfs-framework's boot param support.

---
 meta/recipes-core/initrdscripts/initramfs-framework/finish | 6 ++++++
 1 file changed, 6 insertions(+)
meta/recipes-core/initrdscripts/initramfs-framework/finish +6 -0
index 006aef2..a8806aa 100755
@@ -23,6 +23,12 @@ finish_run() {
 
 			if [ -e "$bootparam_root" ]; then
 				flags=""
+				if [ -n "$bootparam_ro" ]; then
+					if [  -n "$bootparam_rootflags" ]; then
+						bootparam_rootflags="$bootparam_rootflags,"
+					fi
+					bootparam_rootflags="${bootparam_rootflags}ro"
+				fi
 				if [ -n "$bootparam_rootflags" ]; then
 					flags="$flags -o$bootparam_rootflags"
 				fi
Signature · 1 line
2.1.4
Acked-by on v1 2/4
#3 lore raw

Re: [PATCH 2/4] initramfs-framework: support ro boot parameter

Quoted 9 lines · Patrick Ohly

Default is to mount the rootfs read/write. "ro" can be used to turn that into read-only, which is useful on systems where userspace does an fsck before remounting read-write.

Giving both "ro" and "rw" will still mount read-only regardless of the order, because the ordering information is not preserved by the initramfs-framework's boot param support.

Signature · 3 lines
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://code.ossystems.com.br
Mobile: +55 (53) 9981-7854            Mobile: +1 (347) 903-9750
#4 lore raw

PATCH 3/4 initramfs-framework: support init boot parameter

In reply to Patrick Ohly

It can be useful for debugging to override the default /sbin/init. This is something typically done via the init boot parameter which then gets interpreted by the kernel. But when using an initramfs, it is the initramfs which must react to the option.

---
 meta/recipes-core/initrdscripts/initramfs-framework/finish | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meta/recipes-core/initrdscripts/initramfs-framework/finish +1 -1
index a8806aa..e712ff0 100755
@@ -53,7 +53,7 @@ finish_run() {
 		mount --move /sys $ROOTFS_DIR/sys
 
 		cd $ROOTFS_DIR
-		exec switch_root -c /dev/console $ROOTFS_DIR /sbin/init
+		exec switch_root -c /dev/console $ROOTFS_DIR ${bootparam_init:-/sbin/init}
 	else
 		debug "No rootfs has been set"
 	fi
Signature · 1 line
2.1.4
Acked-by on v1 3/4
#5 lore raw

Re: [PATCH 3/4] initramfs-framework: support init boot parameter

Quoted 6 lines · Patrick Ohly

It can be useful for debugging to override the default /sbin/init. This is something typically done via the init boot parameter which then gets interpreted by the kernel. But when using an initramfs, it is the initramfs which must react to the option.

Signature · 3 lines
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://code.ossystems.com.br
Mobile: +55 (53) 9981-7854            Mobile: +1 (347) 903-9750
#6 lore raw

PATCH 4/4 initramfs-framework: support dropping into shell on failure

In reply to Patrick Ohly

When the init_fatal_sh boot parameter is present (i.e. used without value) and a fatal problem occurs inside the initramfs-module, a shell will be started instead of looping forever.

Useful for debugging.

Interestingly enough, the code was already indented to support such an if check...

---
 meta/recipes-core/initrdscripts/initramfs-framework/init | 4 ++++
 1 file changed, 4 insertions(+)
meta/recipes-core/initrdscripts/initramfs-framework/init +4 -0
index e8f4713..9291ad5 100755
@@ -58,9 +58,13 @@ fatal() {
     echo $1 >/dev/console
     echo >/dev/console
 
+    if [ -n "bootparam_init_fatal_sh" ]; then
+        sh
+    else
 	while [ "true" ]; do
 		sleep 3600
 	done
+    fi
 }
 
 # Variables shared amoung modules
Signature · 1 line
2.1.4
Acked-by on v1 4/4
#7 lore raw

Re: [PATCH 4/4] initramfs-framework: support dropping into shell on failure

Quoted 10 lines · Patrick Ohly

When the init_fatal_sh boot parameter is present (i.e. used without value) and a fatal problem occurs inside the initramfs-module, a shell will be started instead of looping forever.

Useful for debugging.

Interestingly enough, the code was already indented to support such an if check...

Signature · 3 lines
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://code.ossystems.com.br
Mobile: +55 (53) 9981-7854            Mobile: +1 (347) 903-9750
Acked-by on v1 1/4
#8 lore raw

Re: [PATCH 1/4] initramfs-framework: support rootflags and rootfstype boot parameter

In reply to Patrick Ohly
Quoted 16 lines · Patrick Ohly

These two parameters are supported by the kernel
(https://www.kernel.org/doc/Documentation/kernel-parameters.txt). When an initramfs is used, the kernel does not mount the rootfs and the initramfs needs to react to them.

The boot parameters can be set both by the image creator and by users.

Supporting these two parameters is useful:
- rootflags is needed to ensure that the rootfs is already mounted as intended in the time between starting init and init remounting it (as systemd does); this is critical for IMA where iversion must be active already when system starts writing files.
- setting it correctly up-front avoids messages from the kernel ("cannot mount ... as ext2 because ...") when trying to guess the desired type.

Quoted 5 lines

For example, assuming that only one of ext4/ext3/ext2 is set,
rootfstype could be set in an image recipe with:
APPEND_append = "${@''.join([' rootfstype=' + i for i in ['ext4', 'ext3', 'ext2'] if i in d.getVar('IMAGE_FSTYPES', True).split()])}"

Signature · 3 lines
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://code.ossystems.com.br
Mobile: +55 (53) 9981-7854            Mobile: +1 (347) 903-9750