Subversion Repositories configs

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 - 1
#!/bin/sh
2
#
3
# Licensed under the GPLv2
4
#
5
# Copyright 2008, Red Hat, Inc.
6
# Jeremy Katz <katzj@redhat.com>
7
 
8
emergency_shell()
9
{
10
    exec >/dev/console 2>&1 </dev/console
11
    echo ; echo
12
    echo $@
13
    source_all emergency
14
    echo
15
    if getarg rdshell || getarg rdbreak; then
16
        echo "Dropping to debug shell."
17
        echo
18
        sh -i
19
    else
20
        echo "Boot has failed, sleeping forever."
21
        while :; do sleep 365d;done
22
    fi
23
}
24
 
25
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
26
export TERM=linux
27
NEWROOT="/sysroot"
28
 
29
trap "emergency_shell Signal caught!" 0
30
 
31
. /lib/dracut-lib.sh
32
 
33
mknod /dev/null c 1 3
34
 
35
# mount some important things
36
mount -t proc /proc /proc >/dev/null 2>&1
37
mount -t sysfs /sys /sys >/dev/null 2>&1
38
 
39
if [ ! -c /dev/ptmx ]; then
40
    # try to mount devtmpfs
41
    if ! mount -t devtmpfs -omode=0755 udev /dev >/dev/null 2>&1; then
42
        # if it failed fall back to normal tmpfs
43
	mount -t tmpfs -omode=0755 udev /dev >/dev/null 2>&1
44
	# Make some basic devices first, let udev handle the rest
45
	mknod /dev/null c 1 3
46
	mknod /dev/ptmx c 5 2
47
	mknod /dev/console c 5 1
48
	mknod /dev/kmsg c 1 11
49
    fi
50
fi
51
 
52
if getarg rdinitdebug; then
53
    set -x
54
fi
55
 
56
mkdir /dev/shm
57
mkdir /dev/pts
58
mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts >/dev/null 2>&1
59
 
60
UDEVVERSION=$(udevadm --version)
61
 
62
source_conf /etc/conf.d
63
 
64
# run scriptlets to parse the command line
65
getarg 'rdbreak=cmdline' && emergency_shell "Break before cmdline"
66
source_all cmdline
67
 
68
[ -z "$root" ] && die "No or empty root= argument"
69
[ -z "$rootok" ] && die "Don't know how to handle 'root=$root'"
70
 
71
# Network root scripts may need updated root= options,
72
# so deposit them where they can see them (udev purges the env)
73
{
74
    echo "root='$root'"
75
    echo "rflags='$rflags'"
76
    echo "fstype='$fstype'"
77
    echo "netroot='$netroot'"
78
    echo "NEWROOT='$NEWROOT'"
79
} > /tmp/root.info
80
 
81
# pre-udev scripts run before udev starts, and are run only once.
82
getarg 'rdbreak=pre-udev' && emergency_shell "Break before pre-udev"
83
source_all pre-udev
84
 
85
# start up udev and trigger cold plugs
86
udevd --daemon
87
 
88
UDEV_LOG_PRIO_ARG=--log-priority
89
UDEV_QUEUE_EMPTY="udevadm settle --timeout=0"
90
 
91
if [ $UDEVVERSION -lt 140 ]; then
92
   UDEV_LOG_PRIO_ARG=--log_priority
93
   UDEV_QUEUE_EMPTY="udevadm settle --timeout=1"
94
fi
95
 
96
getarg rdudevinfo && udevadm control $UDEV_LOG_PRIO_ARG=info
97
getarg rdudevdebug && udevadm control $UDEV_LOG_PRIO_ARG=debug
98
 
99
getarg 'rdbreak=pre-trigger' && emergency_shell "Break before pre-trigger"
100
source_all pre-trigger
101
 
102
# then the rest
103
udevadm trigger $udevtriggeropts  >/dev/null 2>&1
104
 
105
getarg 'rdbreak=initqueue' && emergency_shell "Break before initqueue"
106
 
107
i=0
108
while :; do
109
    # bail out, if we have mounted the root filesystem
110
    [ -d "$NEWROOT/proc" ] && break;
111
 
112
    # check if root can be mounted
113
    [ -e /dev/root ] && break;
114
 
115
    if [ $UDEVVERSION -ge 143 ]; then
116
        udevadm settle --exit-if-exists=/initqueue/work --exit-if-exists=/dev/root
117
    else
118
        udevadm settle --timeout=30
119
    fi
120
 
121
    # bail out, if we have mounted the root filesystem
122
    [ -d "$NEWROOT/proc" ] && break;
123
    # check if root can be mounted
124
    [ -e /dev/root ] && break;
125
 
126
    unset queuetriggered
127
    if [ -f /initqueue/work ]; then
128
        rm /initqueue/work
129
	queuetriggered="1"
130
    fi
131
 
132
    for job in /initqueue/*.sh; do
133
	[ -e "$job" ] || break
134
        job=$job . $job
135
 
136
        # bail out, if we have mounted the root filesystem
137
        [ -d "$NEWROOT/proc" ] && break;
138
        # check if root can be mounted
139
        [ -e /dev/root ] && break;
140
    done
141
 
142
    [ -n "$queuetriggered" ] && continue
143
 
144
    if $UDEV_QUEUE_EMPTY >/dev/null 2>&1; then
145
        # no more udev jobs
146
        sleep 0.5
147
        i=$(($i+1))
148
        [ $i -gt 20 ] \
149
            && { flock -s 9 ; emergency_shell "No root device found"; } 9>/.console_lock
150
    fi
151
done
152
unset job
153
unset queuetriggered
154
 
155
# pre-mount happens before we try to mount the root filesystem,
156
# and happens once.
157
getarg 'rdbreak=pre-mount' && emergency_shell "Break pre-mount"
158
source_all pre-mount
159
 
160
 
161
getarg 'rdbreak=mount' && emergency_shell "Break mount"
162
# mount scripts actually try to mount the root filesystem, and may
163
# be sourced any number of times. As soon as one suceeds, no more are sourced.
164
i=0
165
while :; do
166
    [ -d "$NEWROOT/proc" ] && break;
167
    for f in /mount/*.sh; do
168
       [ -f "$f" ] && . "$f"
169
       [ -d "$NEWROOT/proc" ] && break;
170
    done
171
 
172
    i=$(($i+1))
173
    [ $i -gt 20 ] \
174
        && { flock -s 9 ; emergency_shell "Can't mount root filesystem"; } 9>/.console_lock
175
done
176
 
177
# We have the root file system mounted under $NEWROOT, so copy
178
# the vmcore there and call it a day
179
#
180
DATEDIR=`date +%d.%m.%y-%T`
181
mkdir -p $NEWROOT/var/crash/$DATEDIR
182
cp /proc/vmcore /var/crash/$DATEDIR/vmcore
183
 
184
# Once the copy is done, just reboot the system
185
reboot -f