All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH openbmc 0/9] Initfs fsck v3
@ 2016-02-09 18:00 OpenBMC Patches
  2016-02-09 18:00 ` [PATCH openbmc 1/9] obmc-initfs: shutdown: don't follow links OpenBMC Patches
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: OpenBMC Patches @ 2016-02-09 18:00 UTC (permalink / raw)
  To: openbmc

This series of patches to the obmc init, shutdown, and update scripts adds several features, including

Run fsck on the read write filesystem before mounting.
More information on what to do and options when init fails
Consistent location of update images even during init repair cases

Plus these developer features
All mount arguments consolidated into variables
Clean unmount when testing rofs image in RAM (from the /run file system)
Other clean ups

This version splits the first commit into 3 changes, and updates the messages to have more whitespace and a more explicit statement of the chroot test along with commit message edits.
It corrects a missed variable conversion of rwdir in update and loops on the chroot test.

https://github.com/openbmc/openbmc/pull/169

Milton Miller (9):
  obmc-initfs: shutdown: don't follow links
  obmc-initfs: shutdown: use absolute paths
  obmc-initfs: init: check init is an executable file
  obmc-initfs: look for images in /run/initramfs/image-
  obmc-initfs: use varables for paths and mount arguments
  obmc-initfs: factor debug and takeover
  obmc-initfs: run fsck on read/write file system
  obmc-initfs: run update as a sub-script
  obmc-initfs: shutdown when rofs is a loop mounted image in /run

 .../obmc-phosphor-initfs/files/obmc-init.sh        | 106 ++++++++++++++++-----
 .../obmc-phosphor-initfs/files/obmc-shutdown.sh    |  22 +++--
 .../obmc-phosphor-initfs/files/obmc-update.sh      |  59 ++++++------
 3 files changed, 126 insertions(+), 61 deletions(-)

-- 
2.6.4

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH openbmc 1/9] obmc-initfs: shutdown: don't follow links
  2016-02-09 18:00 [PATCH openbmc 0/9] Initfs fsck v3 OpenBMC Patches
@ 2016-02-09 18:00 ` OpenBMC Patches
  2016-02-09 18:00 ` [PATCH openbmc 2/9] obmc-initfs: shutdown: use absolute paths OpenBMC Patches
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: OpenBMC Patches @ 2016-02-09 18:00 UTC (permalink / raw)
  To: openbmc

From: Milton Miller <miltonm@us.ibm.com>

When creating the synlink for the u-boot-env image, don't
follow any symlinks.

Signed-off-by: Milton Miller <miltonm@us.ibm.com>
---
 .../common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh
index cc076fd..d29db26 100644
--- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh
@@ -27,7 +27,7 @@ set +x
 if test -s /run/fw_env -a -c /run/mtd:u-boot-env -a ! -e /image-u-boot-env &&
 	! cmp /run/mtd:u-boot-env /run/fw_env
 then
-	ln -s /run/fw_env /image-u-boot-env
+	ln -sn /run/fw_env /image-u-boot-env
 fi
 
 if test -x /update && ls image-* > /dev/null 2>&1
-- 
2.6.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH openbmc 2/9] obmc-initfs: shutdown: use absolute paths
  2016-02-09 18:00 [PATCH openbmc 0/9] Initfs fsck v3 OpenBMC Patches
  2016-02-09 18:00 ` [PATCH openbmc 1/9] obmc-initfs: shutdown: don't follow links OpenBMC Patches
@ 2016-02-09 18:00 ` OpenBMC Patches
  2016-02-09 18:00 ` [PATCH openbmc 3/9] obmc-initfs: init: check init is an executable file OpenBMC Patches
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: OpenBMC Patches @ 2016-02-09 18:00 UTC (permalink / raw)
  To: openbmc

From: Milton Miller <miltonm@us.ibm.com>

In shutdown, cd to / like init and update, but do not switch
paths to assume this.  Instead switch a few more paths to be
absolute.  This will clarify the expcted execution environment
and the location of files being tested.  It also provides
consistency when calling /update and creating and testing
the /image- symlinks.

Signed-off-by: Milton Miller <miltonm@us.ibm.com>
---
 .../recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh     | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh
index d29db26..c550e06 100644
--- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh
@@ -5,10 +5,11 @@ echo shutdown: "$@"
 export PS1=shutdown-sh#\ 
 # exec bin/sh
 
+cd /
 if [ ! -e /proc/mounts ]
 then
 	mkdir -p /proc
-	mount  proc proc -tproc
+	mount  proc /proc -tproc
 	umount_proc=1
 else
 	umount_proc=
@@ -30,7 +31,7 @@ then
 	ln -sn /run/fw_env /image-u-boot-env
 fi
 
-if test -x /update && ls image-* > /dev/null 2>&1
+if test -x /update && ls /image-* > /dev/null 2>&1
 then
 	exec /update ${1+"$@"}
 fi
-- 
2.6.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH openbmc 3/9] obmc-initfs: init: check init is an executable file
  2016-02-09 18:00 [PATCH openbmc 0/9] Initfs fsck v3 OpenBMC Patches
  2016-02-09 18:00 ` [PATCH openbmc 1/9] obmc-initfs: shutdown: don't follow links OpenBMC Patches
  2016-02-09 18:00 ` [PATCH openbmc 2/9] obmc-initfs: shutdown: use absolute paths OpenBMC Patches
@ 2016-02-09 18:00 ` OpenBMC Patches
  2016-02-09 18:00 ` [PATCH openbmc 4/9] obmc-initfs: look for images in /run/initramfs/image- OpenBMC Patches
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: OpenBMC Patches @ 2016-02-09 18:00 UTC (permalink / raw)
  To: openbmc

From: Milton Miller <miltonm@us.ibm.com>

In init, check the new init is an executable file with non-zero
size in addition to the shell being executable with its shared
libraries.

Signed-off-by: Milton Miller <miltonm@us.ibm.com>
---
 .../common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh  | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh
index 0dc4c35..eed8cf5 100644
--- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh
@@ -69,9 +69,10 @@ mkdir -p $work
 
 mount -t overlay -o lowerdir=$rodir,upperdir=$upper,workdir=$work cow /root
 
-if ! chroot /root /bin/sh -c exit
+if ! chroot /root /bin/sh -c "test -x /sbin/init -a -s /sbin/init"
 then
-	echo 'chroot test failed; invoking emergency shell.'
+	echo "Unable to confirm /sbin/init is an executable non-empty file."
+	echo "Change Root test failed!  Invoking emergency shell."
 	PS1=rescue#\  sulogin
 fi
 
-- 
2.6.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH openbmc 4/9] obmc-initfs: look for images in /run/initramfs/image-
  2016-02-09 18:00 [PATCH openbmc 0/9] Initfs fsck v3 OpenBMC Patches
                   ` (2 preceding siblings ...)
  2016-02-09 18:00 ` [PATCH openbmc 3/9] obmc-initfs: init: check init is an executable file OpenBMC Patches
@ 2016-02-09 18:00 ` OpenBMC Patches
  2016-02-09 18:00 ` [PATCH openbmc 5/9] obmc-initfs: use varables for paths and mount arguments OpenBMC Patches
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: OpenBMC Patches @ 2016-02-09 18:00 UTC (permalink / raw)
  To: openbmc

From: Milton Miller <miltonm@us.ibm.com>

Teach update to look for /run/initramfs/image- not /image-*.

When describing how to recover from a corrupted flash by grabbing
the images and running update from the init debug shell, it
became apparent that while at systemd shutdown /run/initramfs/
is mounted at /, it is not the case during init.  Use the
variable image to hold this pathname.

Signed-off-by: Milton Miller <miltonm@us.ibm.com>
---
 .../obmc-phosphor-initfs/files/obmc-shutdown.sh              |  7 ++++---
 .../obmc-phosphor-initfs/files/obmc-update.sh                | 12 ++++++------
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh
index c550e06..d530265 100644
--- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh
@@ -25,13 +25,14 @@ do
 done
 set +x
 
-if test -s /run/fw_env -a -c /run/mtd:u-boot-env -a ! -e /image-u-boot-env &&
+image=/run/initramfs/image-
+if test -s /run/fw_env -a -c /run/mtd:u-boot-env -a ! -e ${image}u-boot-env &&
 	! cmp /run/mtd:u-boot-env /run/fw_env
 then
-	ln -sn /run/fw_env /image-u-boot-env
+	ln -sn /run/fw_env ${image}u-boot-env
 fi
 
-if test -x /update && ls /image-* > /dev/null 2>&1
+if test -x /update && ls $image* > /dev/null 2>&1
 then
 	exec /update ${1+"$@"}
 fi
diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh
index 1122e83..f83b1ad 100755
--- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh
@@ -61,10 +61,10 @@ then
 	umount rw
 fi
 
-
-for f in image-*
+image=/run/initramfs/image-
+for f in $image*
 do
-	m=$(findmtd ${f#image-})
+	m=$(findmtd ${f#$image})
 	if test -z "$m"
 	then
 		echo 1>&2  "Unable to find mtd partiton for $f"
@@ -72,10 +72,10 @@ do
 	fi
 done
 
-for f in image-*
+for f in $image*
 do
-	m=$(findmtd ${f#image-})
-	echo "Updating ${f#image-}"
+	m=$(findmtd ${f#$image})
+	echo "Updating ${f#$image}..."
 	# flasheraseall /dev/$m && dd if=$f of=/dev/$m
 	flashcp -v $f /dev/$m
 done
-- 
2.6.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH openbmc 5/9] obmc-initfs: use varables for paths and mount arguments
  2016-02-09 18:00 [PATCH openbmc 0/9] Initfs fsck v3 OpenBMC Patches
                   ` (3 preceding siblings ...)
  2016-02-09 18:00 ` [PATCH openbmc 4/9] obmc-initfs: look for images in /run/initramfs/image- OpenBMC Patches
@ 2016-02-09 18:00 ` OpenBMC Patches
  2016-02-09 18:00 ` [PATCH openbmc 6/9] obmc-initfs: factor debug and takeover OpenBMC Patches
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: OpenBMC Patches @ 2016-02-09 18:00 UTC (permalink / raw)
  To: openbmc

From: Milton Miller <miltonm@us.ibm.com>

Create variables for all mount parameters and paths related to
the read-only and read-write mounts, including fs type, full
device name, and options.  Reorder mount arguments to always
place options last.

Also add variables for update save directory and real init.

This allows easy testing of a file systems by changing a few
parameters including making the rofs an image in ram.

Signed-off-by: Milton Miller <miltonm@us.ibm.com>
---
 .../obmc-phosphor-initfs/files/obmc-init.sh        | 22 ++++++++++-----
 .../obmc-phosphor-initfs/files/obmc-update.sh      | 32 ++++++++++++----------
 2 files changed, 33 insertions(+), 21 deletions(-)

diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh
index eed8cf5..bc7138c 100644
--- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh
@@ -1,12 +1,13 @@
 #!/bin/sh
 
+fslist="proc sys dev run"
 rodir=run/initramfs/ro
 rwdir=run/initramfs/rw
 upper=$rwdir/cow
 work=$rwdir/work
 
 cd /
-mkdir -p sys proc dev run
+mkdir -p $fslist
 mount dev dev -tdevtmpfs
 mount sys sys -tsysfs
 mount proc proc -tproc
@@ -39,13 +40,20 @@ fi
 rofs=$(findmtd rofs)
 rwfs=$(findmtd rwfs)
 
+rodev=/dev/mtdblock${rofs#mtd}
+rwdev=/dev/mtdblock${rwfs#mtd}
+
 rofst=squashfs
 rwfst=ext4
+roopts=ro
+rwopts=rw
+
+init=/sbin/init
 
 echo rofs = $rofs $rofst   rwfs = $rwfs $rwfst
 
 if grep -w debug-init-sh /proc/cmdline ||
-	! mount -o rw /dev/mtdblock${rwfs#mtd} $rwdir -t $rwfst
+	! mount $rwdev $rwdir -t $rwfst -o $rwopts
 then
 	echo Please mount the rw file system on $rwdir from this shell
 	while ! sulogin && ! test -f /takeover
@@ -61,7 +69,7 @@ then
 	exec /bin/sh
 fi
 
-mount -o ro /dev/mtdblock${rofs#mtd} $rodir -t $rofst
+mount $rodev $rodir -t $rofst -o $roopts
 
 rm -rf $work
 mkdir -p $upper
@@ -69,18 +77,18 @@ mkdir -p $work
 
 mount -t overlay -o lowerdir=$rodir,upperdir=$upper,workdir=$work cow /root
 
-if ! chroot /root /bin/sh -c "test -x /sbin/init -a -s /sbin/init"
+if ! chroot /root /bin/sh -c "test -x '$init' -a -s '$init'"
 then
 	echo "Unable to confirm /sbin/init is an executable non-empty file."
 	echo "Change Root test failed!  Invoking emergency shell."
 	PS1=rescue#\  sulogin
 fi
 
-for f in sys dev proc run
+for f in $fslist
 do
 	mount --move $f root/$f
 done
 
-# switch_root /root /sbin/init
-exec chroot /root /sbin/init
+# switch_root /root $init
+exec chroot /root $init
 
diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh
index f83b1ad..32e83e6 100755
--- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh
@@ -35,30 +35,35 @@ findmtd() {
 	echo $m
 }
 
-rofs=$(findmtd rofs)
 rwfs=$(findmtd rwfs)
 
-rofst=squahsfs
+rwdev=/dev/mtdblock${rwfs#mtd}
 rwfst=ext4
+rwopts=rw
+rorwopts=ro${rwopts#rw}
+
+rwdir=rw
+upper=$rwdir/cow
+save=save/${upper##*/}
 
 if test -n "$rwfs" && test -s whitelist
 then
 
-	mkdir -p rw
-	mount /dev/mtdblock${rwfs#mtd} rw -oro -t $rwfst
+	mkdir -p $rwdir
+	mount $rwdev $rwdir -t $rwfst -o $rorwopts
 
 	while read f
 	do
-		if ! test -e rw/cow/$f
+		if ! test -e $upper/$f
 		then
 			continue
 		fi
-		d="save/cow/$f"
+		d="$save/$f"
 		mkdir -p "${d%/*}"
-		cp -rp rw/cow/$f "${d%/*}/"
+		cp -rp $upper/$f "${d%/*}/"
 	done < whitelist
 
-	umount rw
+	umount $rwdir
 fi
 
 image=/run/initramfs/image-
@@ -67,7 +72,7 @@ do
 	m=$(findmtd ${f#$image})
 	if test -z "$m"
 	then
-		echo 1>&2  "Unable to find mtd partiton for $f"
+		echo 1>&2  "Unable to find mtd partiton for ${f##*/}."
 		exec /bin/sh
 	fi
 done
@@ -80,12 +85,11 @@ do
 	flashcp -v $f /dev/$m
 done
 
-
-if test -d save/cow
+if test -d $save
 then
-	mount /dev/mtdblock${rwfs#mtd} rw -o rw -t $rwfst
-	cp -rp save/cow/. rw/cow/
-	umount rw
+	mount $rwdev $rwdir -t $rwfst -o $rwopts
+	cp -rp $save/. $upper/
+	umount $rwdir
 fi
 
 # Execute the command systemd told us to ...
-- 
2.6.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH openbmc 6/9] obmc-initfs: factor debug and takeover
  2016-02-09 18:00 [PATCH openbmc 0/9] Initfs fsck v3 OpenBMC Patches
                   ` (4 preceding siblings ...)
  2016-02-09 18:00 ` [PATCH openbmc 5/9] obmc-initfs: use varables for paths and mount arguments OpenBMC Patches
@ 2016-02-09 18:00 ` OpenBMC Patches
  2016-02-09 18:00 ` [PATCH openbmc 7/9] obmc-initfs: run fsck on read/write file system OpenBMC Patches
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: OpenBMC Patches @ 2016-02-09 18:00 UTC (permalink / raw)
  To: openbmc

From: Milton Miller <miltonm@us.ibm.com>

Factor out sulogin and init takeover with a message.  This is
mostly a refactor and message update.   It also makes the repair
opportunity logic consistent in asking for a password during init
and looping over the chroot verification.

Signed-off-by: Milton Miller <miltonm@us.ibm.com>
---
 .../obmc-phosphor-initfs/files/obmc-init.sh        | 66 ++++++++++++++++------
 1 file changed, 49 insertions(+), 17 deletions(-)

diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh
index bc7138c..4c2a98a 100644
--- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh
@@ -30,6 +30,34 @@ findmtd() {
 	echo $m
 }
 
+debug_takeover() {
+	echo "$@"
+	test -n "$@" && echo Enter password to try to manually fix.
+	cat << HERE
+After fixing run exit to continue this script, or reboot -f to retry, or
+touch /takeover and exit to become PID 1 allowing editing of this script.
+HERE
+
+	while ! sulogin && ! test -f /takeover
+	do
+		echo getty failed, retrying
+	done
+
+	# Touch /takeover in the above getty to become pid 1
+	if test -e /takeover
+	then
+		cat << HERE
+
+Takeover of init requested.  Executing /bin/sh as PID 1.
+When finished exec new init or cleanup and run reboot -f.
+
+Warning: No job control!  Shell exit will panic the system!
+HERE
+		export PS1=init#\ 
+		exec /bin/sh
+	fi
+}
+
 env=$(findmtd u-boot-env)
 if test -n $env
 then
@@ -52,21 +80,20 @@ init=/sbin/init
 
 echo rofs = $rofs $rofst   rwfs = $rwfs $rwfst
 
-if grep -w debug-init-sh /proc/cmdline ||
-	! mount $rwdev $rwdir -t $rwfst -o $rwopts
+if grep -w debug-init-sh /proc/cmdline
 then
-	echo Please mount the rw file system on $rwdir from this shell
-	while ! sulogin && ! test -f /takeover
-	do
-		echo getty failed, retrying
-	done
+	debug_takeover "Debug initial shell requested by command line."
 fi
 
-# Touch /takeover in the above getty to become pid 1
-if test -e /takeover
+if ! mount $rwdev $rwdir -t $rwfst -o $rwopts
 then
-	export PS1=init#\ 
-	exec /bin/sh
+	msg="$(cat)" << HERE
+
+Mounting read-write $rwdev filesystem failed.  Please fix and run
+	mount $rwdev $rwdir -t $rwfs -o $rwopts
+to to continue, or do change nothing to run from RAM for this boot.
+HERE
+	debug_takeover "$msg"
 fi
 
 mount $rodev $rodir -t $rofst -o $roopts
@@ -77,12 +104,17 @@ mkdir -p $work
 
 mount -t overlay -o lowerdir=$rodir,upperdir=$upper,workdir=$work cow /root
 
-if ! chroot /root /bin/sh -c "test -x '$init' -a -s '$init'"
-then
-	echo "Unable to confirm /sbin/init is an executable non-empty file."
-	echo "Change Root test failed!  Invoking emergency shell."
-	PS1=rescue#\  sulogin
-fi
+while ! chroot /root /bin/sh -c "test -x '$init' -a -s '$init'"
+do
+	msg="$(cat)" << HERE
+
+Unable to confirm /sbin/init is an executable non-empty file
+in merged file system mounted at /root.
+
+Change Root test failed!  Invoking emergency shell.
+HERE
+	debug_takeover "$msg"
+done
 
 for f in $fslist
 do
-- 
2.6.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH openbmc 7/9] obmc-initfs: run fsck on read/write file system
  2016-02-09 18:00 [PATCH openbmc 0/9] Initfs fsck v3 OpenBMC Patches
                   ` (5 preceding siblings ...)
  2016-02-09 18:00 ` [PATCH openbmc 6/9] obmc-initfs: factor debug and takeover OpenBMC Patches
@ 2016-02-09 18:00 ` OpenBMC Patches
  2016-02-09 18:00 ` [PATCH openbmc 8/9] obmc-initfs: run update as a sub-script OpenBMC Patches
  2016-02-09 18:00 ` [PATCH openbmc 9/9] obmc-initfs: shutdown when rofs is a loop mounted image in /run OpenBMC Patches
  8 siblings, 0 replies; 10+ messages in thread
From: OpenBMC Patches @ 2016-02-09 18:00 UTC (permalink / raw)
  To: openbmc

From: Milton Miller <miltonm@us.ibm.com>

Good practice is to run fsck to repair minor damage and make a
filesystem consistent before mounting it.  We don't have space
in the initramfs to add fsck, but we can mount the read-only
reference partition first and run fsck from there.

Signed-off-by: Milton Miller <miltonm@us.ibm.com>
---
 .../obmc-phosphor-initfs/files/obmc-init.sh        | 29 +++++++++++++++++++---
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh
index 4c2a98a..6750de3 100644
--- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh
@@ -77,6 +77,8 @@ roopts=ro
 rwopts=rw
 
 init=/sbin/init
+fsck=/sbin/fsck.$rwfst
+fsckopts=-a
 
 echo rofs = $rofs $rofst   rwfs = $rwfs $rwfst
 
@@ -85,6 +87,28 @@ then
 	debug_takeover "Debug initial shell requested by command line."
 fi
 
+mount $rodev $rodir -t $rofst -o $roopts
+
+if test -x $rodir$fsck
+then
+	for fs in $fslist
+	do
+		mount --bind $fs $rodir/$fs
+	done
+	chroot $rodir $fsck $fsckopts $rwdev
+	rc=$?
+	for fs in $fslist
+	do
+		umount $rodir/$fs
+	done
+	if test $rc -gt 1
+	then
+		debug_takeover "fsck of read-write fs on $rwdev failed (rc=$rc)"
+	fi
+else
+	echo "No '$fsck' in read only fs, skipping fsck."
+fi
+
 if ! mount $rwdev $rwdir -t $rwfst -o $rwopts
 then
 	msg="$(cat)" << HERE
@@ -96,11 +120,8 @@ HERE
 	debug_takeover "$msg"
 fi
 
-mount $rodev $rodir -t $rofst -o $roopts
-
 rm -rf $work
-mkdir -p $upper
-mkdir -p $work
+mkdir -p $upper $work
 
 mount -t overlay -o lowerdir=$rodir,upperdir=$upper,workdir=$work cow /root
 
-- 
2.6.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH openbmc 8/9] obmc-initfs: run update as a sub-script
  2016-02-09 18:00 [PATCH openbmc 0/9] Initfs fsck v3 OpenBMC Patches
                   ` (6 preceding siblings ...)
  2016-02-09 18:00 ` [PATCH openbmc 7/9] obmc-initfs: run fsck on read/write file system OpenBMC Patches
@ 2016-02-09 18:00 ` OpenBMC Patches
  2016-02-09 18:00 ` [PATCH openbmc 9/9] obmc-initfs: shutdown when rofs is a loop mounted image in /run OpenBMC Patches
  8 siblings, 0 replies; 10+ messages in thread
From: OpenBMC Patches @ 2016-02-09 18:00 UTC (permalink / raw)
  To: openbmc

From: Milton Miller <miltonm@us.ibm.com>

The update script has replicated logic to do the final reboot, kexec,
halt, or poweroff command.  Instead of transferring control via exec
just call it as a normal command, and return to shutdown for the
final mounted fs debug print and command.

Signed-off-by: Milton Miller <miltonm@us.ibm.com>
---
 .../obmc-phosphor-initfs/files/obmc-shutdown.sh           |  3 +--
 .../obmc-phosphor-initfs/files/obmc-update.sh             | 15 ++++-----------
 2 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh
index d530265..7d1157a 100644
--- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh
@@ -34,7 +34,7 @@ fi
 
 if test -x /update && ls $image* > /dev/null 2>&1
 then
-	exec /update ${1+"$@"}
+	/update ${1+"$@"}
 fi
 
 echo Remaining mounts:
@@ -43,7 +43,6 @@ cat /proc/mounts
 test "umount_proc" && umount /proc && rmdir /proc
 
 
-
 # Execute the command systemd told us to ...
 if test -d /oldroot  && test "$1"
 then
diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh
index 32e83e6..face06d 100755
--- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh
@@ -92,19 +92,12 @@ then
 	umount $rwdir
 fi
 
-# Execute the command systemd told us to ...
-if test -d /oldroot && test -x "/sbin/$1" && test -f "/sbin/$1"
-then
-	if test "$1" == kexec
-	then
-		/sbin/$1 -f -e
-	else
-		/sbin/$1 -f
-	fi
-fi
+exit
 
+# NOT REACHED without edit
+# NOT REACHED without edit
 
-echo "Execute ${1-reboot} -f if all is ok"
+echo "Flash completed.  Inspect, cleanup and reboot -f to continue."
 
 export PS1=update-sh#\ 
 exec /bin/sh
-- 
2.6.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH openbmc 9/9] obmc-initfs: shutdown when rofs is a loop mounted image in /run
  2016-02-09 18:00 [PATCH openbmc 0/9] Initfs fsck v3 OpenBMC Patches
                   ` (7 preceding siblings ...)
  2016-02-09 18:00 ` [PATCH openbmc 8/9] obmc-initfs: run update as a sub-script OpenBMC Patches
@ 2016-02-09 18:00 ` OpenBMC Patches
  8 siblings, 0 replies; 10+ messages in thread
From: OpenBMC Patches @ 2016-02-09 18:00 UTC (permalink / raw)
  To: openbmc

From: Milton Miller <miltonm@us.ibm.com>

If one sets rodir=/run/image-rofs roopts=ro,loop and transfers
an image one can run from a base image in ram.  However, the
shutdown will fail to unmount /run because it is busy and then
fails to unmount /cow which causes oldroot to be still mounted.

By moving the mount to the side everything cleans up (as long
as there are no other mounts under run, and systemd-shutdown
tried to do as much as possible).

Signed-off-by: Milton Miller <miltonm@us.ibm.com>
---
 .../recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh
index 7d1157a..3eff1ea 100644
--- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh
+++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh
@@ -15,11 +15,16 @@ else
 	umount_proc=
 fi
 
-# remove an empty oldroot, that means we are not invoked from systemd-shutdown
+# Remove an empty oldroot, that means we are not invoked from systemd-shutdown
 rmdir /oldroot 2>/dev/null
 
+# Move /oldroot/run to /mnt in case it has the underlying rofs loop mounted.
+# Ordered before /oldroot the overlay is unmounted before the loop mount
+mkdir -p /mnt
+mount --move /oldroot/run /mnt
+
 set -x
-for f in $( awk '/oldroot/ { print $2 }' < /proc/mounts | sort -r )
+for f in $( awk '/oldroot|mnt/ { print $2 }' < /proc/mounts | sort -r )
 do
 	umount $f
 done
-- 
2.6.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-02-09 18:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-09 18:00 [PATCH openbmc 0/9] Initfs fsck v3 OpenBMC Patches
2016-02-09 18:00 ` [PATCH openbmc 1/9] obmc-initfs: shutdown: don't follow links OpenBMC Patches
2016-02-09 18:00 ` [PATCH openbmc 2/9] obmc-initfs: shutdown: use absolute paths OpenBMC Patches
2016-02-09 18:00 ` [PATCH openbmc 3/9] obmc-initfs: init: check init is an executable file OpenBMC Patches
2016-02-09 18:00 ` [PATCH openbmc 4/9] obmc-initfs: look for images in /run/initramfs/image- OpenBMC Patches
2016-02-09 18:00 ` [PATCH openbmc 5/9] obmc-initfs: use varables for paths and mount arguments OpenBMC Patches
2016-02-09 18:00 ` [PATCH openbmc 6/9] obmc-initfs: factor debug and takeover OpenBMC Patches
2016-02-09 18:00 ` [PATCH openbmc 7/9] obmc-initfs: run fsck on read/write file system OpenBMC Patches
2016-02-09 18:00 ` [PATCH openbmc 8/9] obmc-initfs: run update as a sub-script OpenBMC Patches
2016-02-09 18:00 ` [PATCH openbmc 9/9] obmc-initfs: shutdown when rofs is a loop mounted image in /run OpenBMC Patches

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.