You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

97 lines
2.6 KiB

#!/bin/sh
#
# Licensed under the GPLv2
#
# Copyright 2008, Red Hat, Inc.
# Jeremy Katz <katzj@redhat.com>
emergency_shell()
{
echo ; echo
echo "Bug in initramfs /init detected. Dropping to a shell. Good luck!"
echo
sh -i
}
getarg() {
local o line
for o in $CMDLINE; do
[ "$o" = "$1" ] && return 0
[ "${o%%=*}" = "${1%=}" ] && { echo ${o#*=}; return 0; }
done
return 1
}
source_all() {
local f
[ "$1" ] && [ -d "/$1" ] || return
for f in "/$1"/*.sh; do [ -f "$f" ] && . "$f"; done
}
echo "Starting initrd..."
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
export TERM=linux
CONSOLE=/dev/console
[ -c $CONSOLE ] && exec >$CONSOLE 2>&1 <$CONSOLE
trap "emergency_shell" 0
# mount some important things
mount -t proc /proc /proc
mount -t sysfs /sys /sys
mount -t tmpfs -omode=0755 udev /dev
read CMDLINE </proc/cmdline;
# Make some basic devices first, let udev handle the rest
mknod /dev/ptmx c 5 2
mknod /dev/null c 1 3
mknod /dev/console c 5 1
mkdir /dev/pts
mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts
# pre-udev scripts run before udev starts, and are run only once.
getarg 'break=pre-udev' && emergency_shell
source_all pre-udev
# start up udev and trigger cold plugs
udevd --daemon
udevadm trigger >/dev/null 2>&1
udevadm settle --timeout=30 >/dev/null 2>&1
NEWROOT="/sysroot"
# pre-mount happens before we try to mount the root filesystem,
# and happens once.
getarg 'break=pre-mount' && emergency_shell
source_all pre-mount
getarg 'break=mount' && 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.
# Try to find init.
for i in "$(getarg init=)" /sbin/init /etc/init /init /bin/sh; do
[ -f "$NEWROOT$i" -a -x "$NEWROOT$i" ] && { INIT="$i"; break; }
done
[ "$INIT" ] || {
echo "Cannot find init! Please check to make sure you passed"
echo "a valid root filesystem! Dropping to a shell."
emergency_shell
}
# pre pivot scripts are sourced just before we switch over to the new root.
getarg 'break=pre-pivot' && emergency_shell
source_all pre-pivot
getarg break && emergency_shell
echo "Switching to real root filesystem $root"
exec switch_root "$NEWROOT" "$INIT" $CMDLINE || {
# davej doesn't like initrd bugs
echo "Something went very badly wrong in the initrd. Please "
echo "file a bug against mkinitrd."
emergency_shell
}