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