summaryrefslogtreecommitdiff
path: root/packages/slugos-init/files
diff options
context:
space:
mode:
authorMike Westerhof <mwester@dls.net>2008-12-07 20:26:53 -0600
committerMike Westerhof <mwester@dls.net>2008-12-07 20:28:14 -0600
commit3c4e7b4bbb9501ec04a301fdb623d2483c6649e4 (patch)
tree51269a364bc0a8d247b48c55a714025c2f6c10eb /packages/slugos-init/files
parent1a8a75a3944336819c7cc346a0925febb39953e9 (diff)
slugos-init: drop boot/kexec, alway mount /proc and /sys
Diffstat (limited to 'packages/slugos-init/files')
-rw-r--r--packages/slugos-init/files/boot/disk22
-rw-r--r--packages/slugos-init/files/boot/flash7
-rw-r--r--packages/slugos-init/files/boot/network20
-rw-r--r--packages/slugos-init/files/boot/nfs14
-rw-r--r--packages/slugos-init/files/boot/ram34
-rw-r--r--packages/slugos-init/files/functions27
6 files changed, 76 insertions, 48 deletions
diff --git a/packages/slugos-init/files/boot/disk b/packages/slugos-init/files/boot/disk
index 34c002ba0b..1829033d4e 100644
--- a/packages/slugos-init/files/boot/disk
+++ b/packages/slugos-init/files/boot/disk
@@ -2,22 +2,24 @@
# boot from the hard disk partition "$1" (which
# must be given) using options from the rest of
# the command line.
-#
+
# Use the standard init path (see /etc/init.d/rcS)
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
-#
+
+# Mount required fileystems if necessary
+[ -e /proc/cpuinfo ] || mount -t proc proc /proc
+[ -e /sys/class ] || mount -t sysfs sysfs /sys
+
# Load the helper functions
. /etc/default/functions
. /etc/default/modulefunctions
-#
+
leds boot system
-#
+
if test -n "$1"
then
device="$1"
shift
- # proc is needed for UUID mount and module load
- mount -t proc proc /proc
# load USB & SCSI storage modules (/proc required!)
echo "boot: loading modules required for disk boot"
loaddiskmods
@@ -39,10 +41,10 @@ then
mdadm -As --auto=md $device
fi
fi
- #
+
# fire the boot
echo "boot: rootfs: mount $* $device [$UUID]"
- #
+
# Mount read-write because before exec'ing init
# If a UUID is given (in the environment) this
# is used in preference to the device, but if
@@ -70,8 +72,12 @@ then
fi
# Failure: unmount the partition
umount /mnt
+ # Remount /proc and /sys if necessary
+ [ -e /proc/cpuinfo ] || mount -t proc proc /proc
+ [ -e /sys/class ] || mount -t sysfs sysfs /sys
fi
fi
+
# fallback - use the flash boot
leds beep -f 1000 -r 2
exec /boot/flash
diff --git a/packages/slugos-init/files/boot/flash b/packages/slugos-init/files/boot/flash
index 37a1055763..1390597ce7 100644
--- a/packages/slugos-init/files/boot/flash
+++ b/packages/slugos-init/files/boot/flash
@@ -2,10 +2,17 @@
# boot from the current (flash) root partition
# nothing need be done apart from setting the
# system LED status correctly
+
+# Mount required filesystems if necessary
+[ -e /proc/cpuinfo ] || mount -t proc proc /proc
+[ -e /sys/class ] || mount -t sysfs sysfs /sys
+
leds beep
. /etc/default/functions
leds boot system
+
test -x /sbin/init && exec /sbin/init
+
# fallback if /sbin/init has been deleted (bad!)
leds boot system panic
exec <>/dev/console >&0 2>&0
diff --git a/packages/slugos-init/files/boot/network b/packages/slugos-init/files/boot/network
index 48aa9dd7d5..b8054a0056 100644
--- a/packages/slugos-init/files/boot/network
+++ b/packages/slugos-init/files/boot/network
@@ -3,27 +3,21 @@
# netconsole logging and NFS boot. This runs out
# of flash, but that's ok because the script doesn't
# leave any process running.
-#
+
# NOTE: /etc/default/functions defines ifup as a shell
# function!
. /etc/default/functions
-#
-# /proc is needed for the module loading, and /sys is
-# necessary to load firmware (if required).
-mount -t proc proc /proc
-mount -t sysfs sysfs /sys
-#
+
# We may need to load the network driver modules here
. /etc/default/modulefunctions
loadnetmods
-#
-#
+
# Now all the information for booting should be in the configuration
# file. Config the loopback and network interfaces.
ifconfig lo 127.0.0.1 up
iface="$(config iface)"
test -z "$iface" && exit 1
-#
+
# Fire up a process in the background to load the firmware if necessary.
# If this system doesn't require the NPE-B firmware, no problem, the
# background process will simply go away in two seconds. If it requires
@@ -42,10 +36,6 @@ sysf="/sys/class/firmware/$iface"
) &
# Trigger the firmware load proactively
ifconfig "$iface" up
-#
-# Unmount /sys and /proc before we leave
-umount /sys
-umount /proc
-#
+
ifup "$iface"
# exit code is true only if the interface config has succeeded
diff --git a/packages/slugos-init/files/boot/nfs b/packages/slugos-init/files/boot/nfs
index e0f05754c5..7f91889315 100644
--- a/packages/slugos-init/files/boot/nfs
+++ b/packages/slugos-init/files/boot/nfs
@@ -2,15 +2,20 @@
# boot from the nfs partition "$1" (which
# must be given) using options from the rest of
# the command line.
-#
+
# Use the standard init path (see /etc/init.d/rcS)
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
-#
+
+# Mount required fileystems if necessary
+[ -e /proc/cpuinfo ] || mount -t proc proc /proc
+[ -e /sys/class ] || mount -t sysfs sysfs /sys
+
+# Load the helper functions
. /etc/default/functions
. /etc/default/modulefunctions
-#
+
leds boot system
-#
+
if /boot/network
then
# load the nfs kernel module
@@ -20,6 +25,7 @@ then
# now succeed (possibly), use /boot/disk
exec /boot/disk "$@"
fi
+
# fallback - use the flash boot
leds beep -f 1000 -r 2
exec /boot/flash
diff --git a/packages/slugos-init/files/boot/ram b/packages/slugos-init/files/boot/ram
index 2583edf852..0a8fe1d25d 100644
--- a/packages/slugos-init/files/boot/ram
+++ b/packages/slugos-init/files/boot/ram
@@ -2,22 +2,26 @@
# boot from the hard disk partition "$1" (which
# must be given) using options from the rest of
# the command line.
-#
+
# Use the standard init path (see /etc/init.d/rcS)
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
-#
+
+# Mount required fileystems if necessary
+[ -e /proc/cpuinfo ] || mount -t proc proc /proc
+[ -e /sys/class ] || mount -t sysfs sysfs /sys
+
# Load the helper functions
. /etc/default/functions
-#
+
leds beep -r 2
leds boot system
-#
+
if test -n "$1"
then
device="$1"
shift
echo "boot: rootfs: mount $* $device"
- #
+
# prepare the device. This uses tmpfs to avoid dependency
# on non-built-in file systems and because tmpfs can expand
# to bigger than the 10MByte ram0 partition used before.
@@ -26,27 +30,35 @@ then
then
cd /
# filter out boot (with zimage), linuxrc and anything
- # below /var, keep dev or the boot will fail (note that
- # nothing is mounted this early in the bootstrap).
+ # below /var, keep dev or the boot will fail. Take
+ # care that nothing is mounted at this point!
+ umount /proc
+ umount /sys
find . -xdev -print |
sed '\@^./boot/@d;\@^./boot$@d;\@^./linuxrc@d;\@^./var/@d' |
cpio -p -d -m -u /mnt
# busybox find with -xdev will not print the name of the
# mountpoint, so create the empty dir manually if required.
test -d /mnt/mnt || mkdir /mnt/mnt
- # checkmount checks for sh, init and no .recovery plus
- # either mnt or initrd, mnt must exist!
- if checkmount /mnt
+ # checkmount checks for sh, chroot, init, /dev
+ # and /mnt (i.e. /mnt/mnt in this case).
+ # minimaldevnodes checks (and creates if required)
+ # a few mandatory /dev nodes we may need.
+ if checkmount /mnt && minimaldevnodes /mnt
then
# pivot to /mnt
cd /
swivel mnt mnt
# swivel failed
fi
- # Failure: unmount the partition.
+ # Failure: unmount the partition
umount /mnt
+ # Remount /proc and /sys if necessary
+ [ -e /proc/cpuinfo ] || mount -t proc proc /proc
+ [ -e /sys/class ] || mount -t sysfs sysfs /sys
fi
fi
+
# fallback - use the flash boot
leds beep -f 1000 -r 2
exec /boot/flash
diff --git a/packages/slugos-init/files/functions b/packages/slugos-init/files/functions
index 253526995f..38a3b4d166 100644
--- a/packages/slugos-init/files/functions
+++ b/packages/slugos-init/files/functions
@@ -199,17 +199,18 @@ minimaldevnodes(){
# NOTE: the arguments must be paths relative to /, bad things
# will happen if the arguments themselves start with /
# Pivot to a new root. This does all the fancy pivot_root stuff
-# including closing streams and does a umount /proc - it doesn't
-# matter if this fails (failure codes are ignored), but if /proc
-# was mounted it must be restored by the caller on return.
-# Normally this function never returns!
+# including closing streams and does a umount of /proc and /sys -
+# it doesn't matter if this fails (failure codes are ignored),
+# but if /proc and/or /sys was mounted it must be restored by the
+# caller on return. Normally this function never returns!
# On return 0,1,2 are connected to /dev/console - this may not
# have been true before!
swivel(){
cd "$1"
exec <&- >&- 2>&-
- # This is just-in-case the called mounted /proc and was
- # unable to close it because of the streams
+ # This is just-in-case the caller mounted either /proc or
+ # /sys, and was unable to close them
+ umount /sys 2>/dev/null
umount /proc 2>/dev/null
if pivot_root . "$2"
then
@@ -241,11 +242,17 @@ swivel(){
test -x sbin/init && exec sbin/init
test -x etc/init && exec etc/init
test -x bin/init && exec bin/init
+ # Problematic failure! The chroot worked, but the
+ # exec failed. Nothing to do but blink the LEDs.
+ # (Use a wildcard because the LED names depend on
+ # the version of the kernel in use.)
mount -t sysfs sysfs /mnt
- echo -n timer >/mnt/class/leds/ready/trigger
- echo -n timer >/mnt/class/leds/status/trigger
- echo -n 80 >/mnt/class/leds/ready/frequency
- echo -n 80 >/mnt/class/leds/status/frequency
+ for i in /mnt/class/leds/*[ready\|status]
+ do
+ echo -n timer >$i/trigger
+ echo -n 60 >$i/delay_on
+ echo -n 30 >$i/delay_off
+ done
umount /mnt
sync;sync;sync
exit 1"