#!/bin/sh # --- SDE-COPYRIGHT-NOTE-BEGIN --- # This copyright note is auto-generated by ./scripts/Create-CopyPatch. # # Filename: target/early/initramfs/init.sh # Copyright (C) 2007 - 2011 The OpenSDE Project # # More information can be found in the files COPYING and README. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. A copy of the # GNU General Public License can be found in the file COPYING. # --- SDE-COPYRIGHT-NOTE-END --- export PATH=/usr/bin:/usr/sbin:/bin:/sbin modules= root= mode= init=/sbin/init NOCOLOR= initargs="$*" want_mdadm= want_lvm= want_shell= # read kernel arguments [ -e /proc/cmdline ] || mount -n -t proc none /proc set -- $( cat /proc/cmdline ) for x; do v="${x#*=}" case "$x" in root=*) root="$v" ;; init=*) init="$v" ;; rw|ro) mode="$x" ;; modules=*) modules=$( echo "$v" | tr ',' ' ' ) ;; nocolor) export NOCOLOR=yes ;; initrdopt=*) for y in $( echo "$v" | tr ',' ' ' ); do case "$y" in mdadm) want_mdadm=yes ;; mdadm=*) want_mdadm="${y#mdadm=}" ;; lvm) want_lvm=yes ;; lvm=*) want_lvm="${y#lvm=}" ;; shell) want_shell=yes ;; shell=*) want_shell="${y#shell=}" ;; esac done ;; esac done . /etc/rc.d/functions.in banner "Starting Early User Space environment" title "Mounting /proc and /sys" check mount -n -t sysfs none /sys status [ -x /bin/dmesg ] && /bin/dmesg -n 3 if grep -q devtmpfs /proc/filesystems; then title "Preparing /dev (devtmpfs)" check mount -n -t devtmpfs devtmpfs /dev status else title "Preparing /dev (tmpfs)" check mount -n -t tmpfs none /dev status title "Populating initial device nodes" check mdev -s status fi title "Setting mdev as kernel hotplug helper" echo "/sbin/mdev" > /proc/sys/kernel/hotplug status if [ -x /sbin/modprobe -a -n "$modules" ]; then title "Preloading requested kernel modules" for x in $modules; do echo -n " $x" check modprobe -q $x done status fi title "Triggering coldplug" find /sys/devices -name "uevent" | while read x; do echo -n "add" > $x; done status sleep 2 [ -n "$root" ] || echo "No root device defined." if [ ! -e "$root" ]; then if [ "$want_mdadm" = yes ]; then title "Detecting possible RAID devices" check mdadm -E --scan > /etc/mdadm.conf status fi if [ "$want_mdadm" != no -a -s /etc/mdadm.conf ]; then # try activating software raids title "Activating RAID devices" modprobe -q md-mod 2> /dev/null check mdadm -As --auto=yes status fi fi if [ ! -e "$root" ]; then if [ "$want_lvm" = yes ]; then title "Detecting possible LVM devices" check lvm vgscan status fi if [ "$want_lvm" != no -a -d /etc/lvm/archive ]; then title "Activating LVM devices" modprobe -q dm_mod 2> /dev/null check lvm vgchange -ay status fi fi if [ -n "$root" ]; then # give it a second chance to appear (delay 2s) [ -e "$root" ] || sleep 2; if [ -e "$root" ]; then # store detected root filesystem in ROOT_FS_TYPE eval ROOT_FS_$(blkid $root | cut -d ' ' -f3) title "Mounting $root (${ROOT_FS_TYPE:-unknown}) " [ -z "$ROOT_FS_TYPE" ] || modprobe -q "$ROOT_FS_TYPE" 2> /dev/null check mount ${ROOT_FS_TYPE:+-t $ROOT_FS_TYPE} ${mode:+-o $mode} "$root" /rootfs status else echo "root device ($root) not found on time." fi fi # wait for /sbin/init while [ ! -x "/rootfs$init" ]; do # one shell is enough want_shell=no echo "Please mount root device on /rootfs and exit to continue" setsid /bin/sh < /dev/console > /dev/console 2> /dev/console done if [ "$want_shell" = yes ]; then echo "A last-minute shell was requested, please exit to continue" setsid /bin/sh < /dev/console > /dev/console 2> /dev/console fi title "Cleaning up" check mount -t none -o move /dev /rootfs/dev check mount -t none -o move /sys /rootfs/sys check mount -t none -o move /proc /rootfs/proc status exec switch_root /rootfs "$init" $initargs #FIXME: what if it fails?