cdroot 1.11 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
# PROVIDE: cdroot
# BEFORE: disks
# KEYWORD: FreeBSD

#
# rc.cdroot
# Inspired by FreeBSD 4.x rc.cdroot and FreesBIE cdboot for 5.x
#

hier=/usr/local/bin/hier
if [ ! -x $hier ]; then
	hier=/usr/site/bin/hier
	if [ ! -x $hier ]; then
		echo "no hier: dropping into /bin/sh"
		/bin/sh
	fi
fi

# chkerr:
#
# Routine to check for error
#
#	checks error code and drops into shell on failure.
#	if shell exits, terminates script as well as /etc/rc.
#
chkerr() {
	case $1 in
	0)
		;;
	*)
		echo "$2 failed: dropping into /bin/sh"
		/bin/sh
		# RESUME
		;;
	esac
}

mkmfs() {
	FS=$1
	FSSIZE=$2
	DOFSCOPY=$3

	if [ $DOFSCOPY -eq 1 ]; then
		$hier cp $FS /tmp/$FS
		chkerr $? "${FS}: hier save"
	fi
	echo "Generating ${FS} via md"
	MDDEVICE=`/sbin/mdconfig -a -t malloc -s ${FSSIZE}m`
	/sbin/newfs -i 1024 /dev/${MDDEVICE} > /dev/null
	chkerr $? "${FS}: newfs"
	/sbin/mount /dev/${MDDEVICE} ${FS}
	chkerr $? "${FS}: mount"
	if [ $DOFSCOPY -eq 1 ]; then
		$hier mv /tmp/$FS $FS
		chkerr $? "${FS}: hier restore"
	fi
}

cd /

mkmfs /tmp 4 0
mkmfs /root 1 1
mkmfs /etc 4 1
mkmfs /var 4 1

mkmfs /proj 1 0
mkmfs /users 1 0
mkmfs /groups 1 0

exit 0