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