kernel/{hammer2,tmpfs}: Fix ENOTDIR/EISDIR logic.
[dragonfly.git] / initrd / etc / rc
blobd4f08eb6f147a3aa6080606774beecf226909589
1 #!/bin/sh
3 export PATH=/bin:/sbin
4 export HOME=/var/home
6 # Where to mount the real root partition
7 export NEW_ROOT=/new_root
9 rescue_shell() {
10 echo "Starting the recovery shell ..."
11 cat /etc/motd
12 exec sh
13 exit 0
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
23 echo "Setting up /var directories ..."
24 mount_tmpfs tmpfs /var
25 mkdir /var/db /var/empty /var/home /var/run /var/tmp
27 echo "Starting udevd for LVM ..."
28 udevd
30 echo "Executing additional rc scripts ..."
31 for rcs in /etc/rc.*; do
32 if [ -x "$rcs" ]; then
33 . $rcs
35 done
37 echo "Mounting real root partition at $NEW_ROOT ..."
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
45 if [ -z "${REAL_ROOT}" ]; then
46 echo "ERROR: vfs.real_root sysctl not set."
47 rescue_shell
49 set -- $REAL_ROOT
50 unset IFS
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
67 echo "Stopping udevd ..."
68 kill $(cat /var/run/udevd.pid)
70 echo "Cleaning up and umounting /var ..."
71 rm -rf /var/*
72 umount /var
74 echo "Mounting devfs on real root ..."
75 #mount_devfs $NEW_ROOT/dev
76 mount_null /dev $NEW_ROOT/dev