Blame | Last modification | View Log | RSS feed
#!/bin/sh## Licensed under the GPLv2## Copyright 2008, Red Hat, Inc.# Jeremy Katz <katzj@redhat.com>emergency_shell(){exec >/dev/console 2>&1 </dev/consoleecho ; echoecho $@source_all emergencyechoif getarg rdshell || getarg rdbreak; thenecho "Dropping to debug shell."echosh -ielseecho "Boot has failed, sleeping forever."while :; do sleep 365d;donefi}export PATH=/sbin:/bin:/usr/sbin:/usr/binexport TERM=linuxNEWROOT="/sysroot"trap "emergency_shell Signal caught!" 0. /lib/dracut-lib.shmknod /dev/null c 1 3# mount some important thingsmount -t proc /proc /proc >/dev/null 2>&1mount -t sysfs /sys /sys >/dev/null 2>&1if [ ! -c /dev/ptmx ]; then# try to mount devtmpfsif ! mount -t devtmpfs -omode=0755 udev /dev >/dev/null 2>&1; then# if it failed fall back to normal tmpfsmount -t tmpfs -omode=0755 udev /dev >/dev/null 2>&1# Make some basic devices first, let udev handle the restmknod /dev/null c 1 3mknod /dev/ptmx c 5 2mknod /dev/console c 5 1mknod /dev/kmsg c 1 11fifiif getarg rdinitdebug; thenset -xfimkdir /dev/shmmkdir /dev/ptsmount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts >/dev/null 2>&1UDEVVERSION=$(udevadm --version)source_conf /etc/conf.d# run scriptlets to parse the command linegetarg 'rdbreak=cmdline' && emergency_shell "Break before cmdline"source_all cmdline[ -z "$root" ] && die "No or empty root= argument"[ -z "$rootok" ] && die "Don't know how to handle 'root=$root'"# Network root scripts may need updated root= options,# so deposit them where they can see them (udev purges the env){echo "root='$root'"echo "rflags='$rflags'"echo "fstype='$fstype'"echo "netroot='$netroot'"echo "NEWROOT='$NEWROOT'"} > /tmp/root.info# pre-udev scripts run before udev starts, and are run only once.getarg 'rdbreak=pre-udev' && emergency_shell "Break before pre-udev"source_all pre-udev# start up udev and trigger cold plugsudevd --daemonUDEV_LOG_PRIO_ARG=--log-priorityUDEV_QUEUE_EMPTY="udevadm settle --timeout=0"if [ $UDEVVERSION -lt 140 ]; thenUDEV_LOG_PRIO_ARG=--log_priorityUDEV_QUEUE_EMPTY="udevadm settle --timeout=1"figetarg rdudevinfo && udevadm control $UDEV_LOG_PRIO_ARG=infogetarg rdudevdebug && udevadm control $UDEV_LOG_PRIO_ARG=debuggetarg 'rdbreak=pre-trigger' && emergency_shell "Break before pre-trigger"source_all pre-trigger# then the restudevadm trigger $udevtriggeropts >/dev/null 2>&1getarg 'rdbreak=initqueue' && emergency_shell "Break before initqueue"i=0while :; do# bail out, if we have mounted the root filesystem[ -d "$NEWROOT/proc" ] && break;# check if root can be mounted[ -e /dev/root ] && break;if [ $UDEVVERSION -ge 143 ]; thenudevadm settle --exit-if-exists=/initqueue/work --exit-if-exists=/dev/rootelseudevadm settle --timeout=30fi# bail out, if we have mounted the root filesystem[ -d "$NEWROOT/proc" ] && break;# check if root can be mounted[ -e /dev/root ] && break;unset queuetriggeredif [ -f /initqueue/work ]; thenrm /initqueue/workqueuetriggered="1"fifor job in /initqueue/*.sh; do[ -e "$job" ] || breakjob=$job . $job# bail out, if we have mounted the root filesystem[ -d "$NEWROOT/proc" ] && break;# check if root can be mounted[ -e /dev/root ] && break;done[ -n "$queuetriggered" ] && continueif $UDEV_QUEUE_EMPTY >/dev/null 2>&1; then# no more udev jobssleep 0.5i=$(($i+1))[ $i -gt 20 ] \&& { flock -s 9 ; emergency_shell "No root device found"; } 9>/.console_lockfidoneunset jobunset queuetriggered# pre-mount happens before we try to mount the root filesystem,# and happens once.getarg 'rdbreak=pre-mount' && emergency_shell "Break pre-mount"source_all pre-mountgetarg 'rdbreak=mount' && emergency_shell "Break mount"# 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.i=0while :; do[ -d "$NEWROOT/proc" ] && break;for f in /mount/*.sh; do[ -f "$f" ] && . "$f"[ -d "$NEWROOT/proc" ] && break;donei=$(($i+1))[ $i -gt 20 ] \&& { flock -s 9 ; emergency_shell "Can't mount root filesystem"; } 9>/.console_lockdone# We have the root file system mounted under $NEWROOT, so copy# the vmcore there and call it a day#DATEDIR=`date +%d.%m.%y-%T`mkdir -p $NEWROOT/var/crash/$DATEDIRcp /proc/vmcore /var/crash/$DATEDIR/vmcore# Once the copy is done, just reboot the systemreboot -f