Skip to contentSkip to conversation

initramfs fixes

PATCH New Ross Burton 1 participant 3 messages Sep 27, 2012

lore
Share & tools
lore
#0 lore raw

cover initramfs fixes

A colleague was working on an initramfs-based yocto system and encounting some issues because the initial script is quite fragile.

Attached are two patches to make it less fragile, and drop you to a shell if it does break.

The following changes since commit 55b3e7bf48a67c0ce42308b8332262fbe4eccd24:

dbus: disable all X11 when native (2012-09-26 21:23:37 +0100)

are available in the git repository at:

git://git.yoctoproject.org/poky-contrib ross/initramfs

for you to fetch changes up to 265e1e50186d5982b40d87f37f0662a0e09a7daa:

initramfs: Make mkdir not fail (2012-09-27 15:17:35 +0100)

----------------------------------------------------------------
Damien Lespiau (2):
initrd: Spawn an emergency shell when something goes wrong
initramfs: Make mkdir not fail

 meta/recipes-core/initrdscripts/files/init-live.sh |   17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

Damien Lespiau (2):
initrd: Spawn an emergency shell when something goes wrong
initramfs: Make mkdir not fail

 meta/recipes-core/initrdscripts/files/init-live.sh |   17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
Signature · 1 line
1.7.10
#1 lore raw

PATCH 1/2 initrd: Spawn an emergency shell when something goes wrong

From: Damien Lespiau <[email protected]>

set -e allows to exit if a command fails. We install a trap and execute emergency_shell() when either the init script exits or when ctrl-c is typed (say if we are stuck somewhere and we want to debug it).

---
 meta/recipes-core/initrdscripts/files/init-live.sh |   11 +++++++++++
 1 file changed, 11 insertions(+)
meta/recipes-core/initrdscripts/files/init-live.sh +11 -0
index 3fba7dc..fb7af31 100644
@@ -2,6 +2,17 @@
 
 PATH=/sbin:/bin:/usr/sbin:/usr/bin
 
+emergency_shell()
+{
+    echo "Bug in initramfs /init detected. Dropping to a shell. Good luck!"
+    echo
+    sh
+}
+trap "emergency_shell" 0 2
+
+# exit immediately if a command fails
+set -e
+
 ROOT_MOUNT="/rootfs/"
 ROOT_IMAGE="rootfs.img"
 MOUNT="/bin/mount"
Signature · 1 line
1.7.10
#2 lore raw

PATCH 2/2 initramfs: Make mkdir not fail

In reply to Ross Burton

From: Damien Lespiau <[email protected]>

This patch make "mkdir foo" not fail if foo already exists.

---
 meta/recipes-core/initrdscripts/files/init-live.sh |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
meta/recipes-core/initrdscripts/files/init-live.sh +3 -3
index fb7af31..2639308 100644
@@ -21,15 +21,15 @@ ISOLINUX=""
 UNIONFS="no"
 
 early_setup() {
-    mkdir /proc
-    mkdir /sys
+    mkdir -p /proc
+    mkdir -p /sys
     mount -t proc proc /proc
     mount -t sysfs sysfs /sys
 
     # support modular kernel
     modprobe isofs 2> /dev/null
 
-    mkdir /run
+    mkdir -p /run
     udevd --daemon
     udevadm trigger --action=add
 }
Signature · 1 line
1.7.10