Merge branch 'vendor/OPENSSH'
[dragonfly.git] / initrd / etc / rc
1 #!/bin/sh
2
3 export PATH=/bin:/sbin
4 export HOME=/var/home
5
6 # Where to mount the real root partition
7 export NEW_ROOT=/new_root
8
9 rescue_shell() {
10         echo "Starting the recovery shell ..."
11         cat /etc/motd
12         exec sh
13         exit 0
14 }
15
16 if [ ! -d "$NEW_ROOT" ]; then
17         echo "WARNING: trying to remount / RW and create $NEW_ROOT ..."
18         mount -u -w / &&
19             mkdir $NEW_ROOT ||
20             rescue_shell
21 fi
22
23 echo "Setting up /var directories ..."
24 mount_tmpfs tmpfs /var
25 mkdir /var/db /var/empty /var/home /var/run /var/tmp
26
27 echo "Starting udevd for LVM ..."
28 udevd
29
30 echo "Executing additional rc scripts ..."
31 for rcs in /etc/rc.*; do
32         if [ -x "$rcs" ]; then
33                 . $rcs
34         fi
35 done
36
37 echo "Mounting real root partition at $NEW_ROOT ..."
38
39 IFS=':'
40 REAL_ROOT=$(sysctl -n vfs.real_root)
41 if [ $? -ne 0 ]; then
42         echo "ERROR: vfs.real_root sysctl no exist. The kernel is too old."
43         rescue_shell
44 fi
45 if [ -z "${REAL_ROOT}" ]; then
46         echo "ERROR: vfs.real_root sysctl not set."
47         rescue_shell
48 fi
49 set -- $REAL_ROOT
50 unset IFS
51
52 TYPE=$1
53 if [ "$TYPE" = "local" ]; then
54         FSTYPE=$2
55         MOUNTFROM="/dev/${3#/dev/}"
56         echo "Executing: mount -t $FSTYPE $4 $MOUNTFROM $NEW_ROOT"
57         mount -o ro -t $FSTYPE $4 $MOUNTFROM $NEW_ROOT ||
58             rescue_shell
59 elif [ -x "/etc/rcmount_${TYPE}" ]; then
60         . /etc/rcmount_${TYPE} "$@" ||
61             rescue_shell
62 else
63         echo "ERROR: Unsupported root filesystem type: $TYPE."
64         rescue_shell
65 fi
66
67 echo "Stopping udevd ..."
68 kill $(cat /var/run/udevd.pid)
69
70 echo "Cleaning up and umounting /var ..."
71 rm -rf /var/*
72 umount /var
73
74 echo "Mounting devfs on real root ..."
75 #mount_devfs $NEW_ROOT/dev
76 mount_null /dev $NEW_ROOT/dev