--- /dev/null
+#!/bin/sh
+[ "$root" ] || {
+ root=$(getarg root); root=${root#root=}
+ case $root in
+ LABEL=*) root=${root#LABEL=}
+ root="$(echo $root |sed 's,/,\\x2f,g')"
+ root="/dev/disk/by-label/${root}" ;;
+ UUID=*) root="/dev/disk/by-uuid/${root#UUID=}" ;;
+ '') echo "Warning: no root specified"
+ root="/dev/sda1" ;;
+ esac
+}
+
+[ "$rflags" ] || {
+ if rflags="$(getarg rootflags)"; then
+ rflags="${rflags#rootflags=}"
+ getarg rw >/dev/null && rflags="${rflags},rw" || rflags="${rflags},ro"
+ else
+ getarg rw >/dev/null && rflags=rw || rflags=ro
+ fi
+}
+
+[ "$fstype" ] || {
+ fstype="$(getarg rootfstype)" && fstype="-t ${fstype#rootfstype=}"
+}
+
+[ -e "$root" ] && {
+ ln -sf "$root" /dev/root
+ mount $fstype -o $rflags /dev/root $NEWROOT && ROOTFS_MOUNTED=yes
+}
mknod /dev/tty1 c 4 1
mknod /dev/null c 1 3
+# pre-udev scripts run before udev starts, and are run only once.
source_all pre-udev
# start up udev and trigger cold plugs
udevd --daemon
udevadm trigger >/dev/null 2>&1
+udevadm settle --timeout=30
-# mount the rootfs
NEWROOT="/sysroot"
-
-# FIXME: there's got to be a better way ...
-# it'd be nice if we had a udev rule that just did all of the bits for
-# figuring out what the specified root is and linking it /dev/root
-root=$(getarg root); root=${root#root=}
-case $root in
- LABEL=*) root=${root#LABEL=}
- root="$(echo $root |sed 's,/,\\x2f,g')"
- root="/dev/disk/by-label/${root}" ;;
- UUID=*) root="/dev/disk/by-uuid/${root#UUID=}" ;;
- '') echo "Warning: no root specified"
- root="/dev/sda1" ;;
-esac
-
-# should we have a timeout?
-tries=0
-echo "Waiting up to 30 seconds for $root to become available"
-udevadm settle --timeout=30
+# pre-mount happens before we try to mount the root filesystem,
+# and happens once.
source_all pre-mount
-echo "Trying to mount rootfs $root"
-if rflags="$(getarg rootflags)"; then
- rflags="${rflags#rootflags=}"
- getarg rw >/dev/null && rflags="${rflags},rw" || rflags="${rflags},ro"
-else
- getarg rw >/dev/null && rflags=rw || rflags=ro
-fi
-[ -e "$root" ] || emergency_shell
-ln -s "$root" /dev/root
-fstype="$(getarg rootfstype)" && fstype="-t ${fstype#rootfstype=}"
-mount $fstype -o $rflags /dev/root $NEWROOT || emergency_shell
+# mount scripts actually try to mount the root filesystem, and may
+# be sourced any number of times. As soon as one suceeds, no more are sourced.
+while :; do
+ for f in /mount/*.sh; do
+ [ -x "$f" ] && . "$f";
+ [ "$ROOTFS_MOUNTED" ] && break;
+ done
+ [ "$ROOTFS_MOUNTED" ] && break;
+ sleep 1
+done
+
+# by the time we get here, the root filesystem should be mounted.
INIT=$(getarg init)
[ "$INIT" ] || {
emergency_shell
}
}
-
+
+# pre pivot scripts are sourced just before we switch over to the new root.
source_all pre-pivot
echo "Switching to real root filesystem $root"
exec switch_root "$NEWROOT" "$INIT" $CMDLINE || {