Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 25 Mar 2001 23:08:06 -0800
From:      Mike Smith <msmith@freebsd.org>
To:        MIHIRA Sanpei Yoshiro <sanpei@sanpei.org>
Cc:        current@freebsd.org
Subject:   Re: use md device in /etc/rc.diskless{1,2} 
Message-ID:  <200103260708.f2Q78D601140@mass.dis.org>
In-Reply-To: Your message of "Mon, 26 Mar 2001 13:13:55 %2B0900." <20010326.131355.70225941.sanpei@sanpei.org> 

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multipart MIME message.

--==_Exmh_-19347581240
Content-Type: text/plain; charset=us-ascii

> Hi.
> 
>   I have diskless-PC which was used /boot/pxeboot.  But latest
> FreeBSD-current is output below messages and some fsck_nfs problem.
> 
> WARNING: MFS is being phased out in preference for md devices
> WARNING: Please see mdconfig(8) for details
> WARNING: Continuing in 15 seconds
> 
>   Does someone already rewrite and use mdconfig in /etc/rc.diskless1
> and diskless2?

Yes, please find attached; if someone wants to clean these up and commit 
them, I'd be greatly indebted.

You also need to apply this diff to /etc/rc (warning, cut-n-paste damage):

--- rc  Sun Dec 17 00:24:49 2000
+++ /local0/pxeroot5/etc/rc     Tue Jan 23 17:52:20 2001
@@ -201,7 +201,7 @@
 # Run custom disk mounting function here
 #
 if [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then
-               sh ${diskless_mount}
+               . ${diskless_mount}
 fi


--==_Exmh_-19347581240
Content-Type: text/plain ; name="rc.diskless2"; charset=us-ascii
Content-Description: rc.diskless2
Content-Disposition: attachment; filename="rc.diskless2"

# $FreeBSD: src/etc/rc.diskless2,v 1.6 2000/04/27 08:43:48 sheldonh Exp $
#
# rc.diskless2
#
# Build filesystems for diskless operation, potentially more complicated
# than can be handled by /etc/fstab.
#

# Reconstruct /var
mkmd ${diskless_var_size} /var
mtree -p /var -eU -f /etc/mtree/BSD.var.dist 2>&1 >/dev/null
touch /var/log/messages

# Copy the templated /dev into a locally-writable version
mkmd ${diskless_dev_size} /mnt
cp -Rp /dev/* /mnt
umount /mnt
mount $md_filesystem /dev

# Build a small /tmp
mkmd ${diskless_tmp_size} /tmp

--==_Exmh_-19347581240
Content-Type: text/plain ; name="rc.diskless1"; charset=us-ascii
Content-Description: rc.diskless1
Content-Disposition: attachment; filename="rc.diskless1"

# $FreeBSD: src/etc/rc.diskless1,v 1.5 2000/01/06 18:17:38 luigi Exp $
#
# /etc/rc.diskless1 - general BOOTP startup
#
# BOOTP has mounted / for us.  Assume a read-only mount.  We must then
# - figure out our IP by querying the interface
# - fill /mnt (writable) with files from /etc, and then update
#   per-machine files from /conf/*/ where * is the IP of the host,
#   the IP of the subnet, "default", or nothing.
# - mount /mnt over /etc so we can see the new files.
#
# WARNING: I think you should not change /etc/rc or strange things could
# happen.
#
# The operator is in charge of setting /conf/*/etc/* things as appropriate.
# Typically rc.conf and fstab need to be changed, but possibly
# also other files such as inetd.conf etc.

# 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
}

# mkmd:
#
# Builds an md(4) disk of the size in $1
# Labels and newfs' it.
# Mounts it on the destination in $2
# Returns the name of the created md device in md_device
# Returns the name of the device containing the filesystem in md_filesystem
mkmd() {
	md_device=`mdconfig -a -t malloc -s $1`
	chkerr $? "configuring md device"
	disklabel -rw $md_device auto
	chkerr $? "labelling md device"
	md_filesystem=/dev/$md_device"c"
	newfs $md_filesystem 2>&1 >/dev/null
	chkerr $? "making md device filesystem"
	mount $md_filesystem $2
	chkerr $? "mounting md filesystem on $2"
}

# DEBUGGING
#
# set -v

# Figure out our interface and IP.
#
bootp_ifc=""
bootp_ipa=""
bootp_ipbca=""
iflist=`ifconfig -l`
for i in ${iflist} ; do
    set `ifconfig ${i}`
    while [ $# -ge 1 ] ; do
        if [ "${bootp_ifc}" = "" -a "$1" = "inet" ] ; then
            bootp_ifc=${i} ; bootp_ipa=${2} ; shift
        fi
        if [ "${bootp_ipbca}" = "" -a "$1" = "broadcast" ] ; then
            bootp_ipbca=$2; shift
        fi
        shift
    done
    if [ "${bootp_ifc}" != "" ] ; then
        break
    fi
done
echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca}"

# Build a writable copy of /etc from the initial /etc and files obtained
# from /conf/<ip address>/etc or /conf/<broadcast>/etc or /conf/etc.
#
mkmd 4m /mnt
cp -Rp /etc/* /mnt
chkerr $? "copy /etc template"

if [ -d /conf/${bootp_ipa} ] ; then
        cp -Rp /conf/${bootp_ipa}/etc/* /mnt
elif [ -d /conf/${bootp_ipbca} ] ; then
        cp -Rp /conf/${bootp_ipbca}/etc/* /mnt
else
        cp -Rp /conf/default/etc/* /mnt
fi

# Make the new filesystem available as /etc
#
umount /mnt
mount $md_filesystem /etc

# Tell /etc/rc to run the specified script after
# it does its mounts but before it does anything
# else.
#
# This script is responsible for setting up the
# diskless mount environment.  This can be
# overriden by /conf/ME/rc.conf.local if, for
# example, you do not want to run the standard
# system /etc/rc.diskless2

diskless_mount="/etc/rc.diskless2"

--==_Exmh_-19347581240
Content-Type: text/plain; charset=us-ascii

... every activity meets with opposition, everyone who acts has his
rivals and unfortunately opponents also.  But not because people want
to be opponents, rather because the tasks and relationships force
people to take different points of view.  [Dr. Fritz Todt]
           V I C T O R Y   N O T   V E N G E A N C E

--==_Exmh_-19347581240--



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200103260708.f2Q78D601140>