#!/bin/sh # # $Id: cdroot_mount,v 1.2 2002/08/04 20:56:04 bsd Exp $ # # Copyright 2001, 2002 Brian S. Dean # All Rights Reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY BRIAN S. DEAN ``AS IS'' AND ANY # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BRIAN S. DEAN BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH # DAMAGE. # # Author : Brian Dean # Date : 14 April, 2001 # # If there is a global system configuration file, suck it in. # if [ -r /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf source_rc_confs elif [ -r /etc/rc.conf ]; then . /etc/rc.conf fi # figure out our IP address ipaddr="" set `ifconfig -a` while [ "$#" -ge 1 ]; do if [ "$1" = "inet" -a "${ipaddr}" = "" ]; then ipaddr=$2; shift; fi shift; done # find our hostname from /etc/hosts if [ -n "${ipaddr}" ]; then set `/bin/cat /etc/hosts` while [ "$#" -ge 1 ]; do if [ "${ipaddr}" = "$1" ]; then hostname=$2; echo $hostname shift; fi shift; done fi if [ -n "$hostname" ]; then /bin/hostname $hostname else echo "Can't find hostname for IP $ipaddr in /etc/hosts" /bin/hostname 'cdroot' fi echo hostname = `/bin/hostname` # # Determine if we have a local disk to use as /var, /tmp and /local # if [ "$cdroot_uselocaldisk" = "YES" ]; then DISK=`dmesg | grep ^ad0:` if [ -n "$DISK" ]; then DISK=ad0 else DISK=`dmesg | grep ^da0:` if [ -n "$DISK" ]; then DISK=da0 fi fi else DISK="" fi populate_var () { /usr/sbin/mtree -deU -f /etc/mtree/BSD.var.dist -p /var /usr/sbin/mtree -deU -f /etc/mtree/BSD.sendmail.dist -p / TOUCH=`/bin/cat /etc/newsyslog.conf | /usr/bin/grep -v '^#' | \ /usr/bin/grep /var/log | /usr/bin/tr '\t' ' ' | \ /usr/bin/cut -f1 -d' '` for i in $TOUCH; do if [ ! -f "$i" ]; then echo "Creating $i ..." echo -n "" >> $i fi done } if [ -z "$DISK" ]; then # # We are totally diskless, set up /var as an MFS # /sbin/mount_mfs -s $VAR_MFS -T qp120at dummy /var populate_var else # # We have a disk, initialize it if needed and set up /var there. # Also, create a paritition for /tmp and /local and swap. # /etc/cdroot_initdisk ${DISK} var:a:128 swap:b:128 tmp:e:128 local:f:0 /sbin/fsck -y /dev/${DISK}s1a /sbin/mount /dev/${DISK}s1a /var populate_var /sbin/swapon /dev/${DISK}s1b /sbin/fsck -y /dev/${DISK}s1e /sbin/umount /tmp /sbin/mount /dev/${DISK}s1e /tmp /bin/chmod a+rwx,a-t /tmp /sbin/fsck -y /dev/${DISK}s1f /sbin/mount /dev/${DISK}s1f /local fi