Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Oct 2009 09:13:11 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        Rink Springer <rink@freebsd.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r198317 - head/usr.sbin/sysinstall
Message-ID:  <200910210913.12038.jhb@freebsd.org>
In-Reply-To: <200910211110.n9LBAYG6097426@svn.freebsd.org>
References:  <200910211110.n9LBAYG6097426@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wednesday 21 October 2009 7:10:34 am Rink Springer wrote:
> Author: rink
> Date: Wed Oct 21 11:10:34 2009
> New Revision: 198317
> URL: http://svn.freebsd.org/changeset/base/198317
> 
> Log:
>   Introduce 'netDev=ANY' support for scripted (install.cfg) installs, which 
results in the first ethernet interface with physical link being selected.
>   
>   While here, fix a minor typo causing an 'if' to be missed.
>   
>   Submitted by:	randi

Note that in the case of PXE you can use a shell script to automatically use 
the PXE interface.  I do this in my scripts here at work.  install.cfg 
contains:

# Figure out our installation media and configure it.
command=/bin/sh /stand/domedia.sh
system
configFile=/stand/media.cfg
loadConfig

And domedia.sh contains this code to figure out which network interface to use 
if a kernel environment variable is set to indicate an NFS install (vs a CD 
install, the scripts support both) (Note that I have added kenv and dialog to 
my mfsroot):

#!/bin/sh
#
# Figure out which install media we want to use.

netif=`kenv -q install.netif`
nfspath=`kenv -q install.nfspath`

# Determine if a given network interface has link
# XXX: some drivers only report link if the interface is UP
netif_up()
{
	local status

	status=`ifconfig $1 | sed -ne '/status:/p'`
	case $status in
		*active*)
			return 0
			;;
	esac
	return 1
}

# Returns true if a given network interface has the specified MAC address.
macmatch()
{
	local addr

	addr=`ifconfig $1 | sed -ne '/	ether /{s///;p;}'`
	[ "$addr" = "$2" ]
	return $?
}

# If 'nfspath' is set, assume we are using NFS, otherwise, assume we
# are installing from a CD.
if [ -n "${nfspath}" ]; then
	# If netif isn't set, try to guess at a sane value.
	if [ -z "${netif}" ]; then
		# This is set by the loader when booting via PXE
		macaddr=`kenv -q boot.netif.hwaddr`
		macif=""
		count=0
		upcount=0
		ifaces=""
		upifaces=""
		for ifn in `ifconfig -l`; do
			case $ifn in
				lo0)
					# Ignore loopback
					;;
				*)
					count=$((count + 1))
					ifaces="${ifaces} ${ifn}"
					if netif_up $ifn; then
						upcount=$((upcount + 1))
						upifaces="${upifaces} ${ifn}"
					fi
					if [ -n "$macaddr" ] && \
					    macmatch $ifn $macaddr; then
						macif="$ifn"
					fi
					;;
			esac
		done

		# If there is only a single interface, use that.  If
		# we booted via PXE and the MAC address for PXE
		# matches the MAC address of an interface, use that.
		# Finally, if only one interface has link, use that.
		# If all of those tests fail, pop up a menu.
		if [ $count -eq 1 ]; then
			# The echo trims extra spaces
			netif=`echo $ifaces`
		elif [ -n "$macif" ]; then
			netif="$macif"
		elif [ $upcount -eq 1 ]; then
			# The echo trims extra spaces
			netif=`echo $upifaces`
		else
			# Build the menu
			ifmenu=""
			for ifn in $ifaces; do
				ifmenu="${ifmenu} ${ifn} Network"
			done

			# Run the menu
			while [ -z "${netif}" ]; do
				rm -f /stand/netif
				dialog --menu "Select the network interface to use for NFS." \
				    $((count + 7)) 50 $((count)) ${ifmenu} 2> \
				    /stand/netif
				if [ $? -eq 0 ]; then
					netif=`cat /stand/netif`
				fi
			done
		fi
	fi

	cat > /stand/media.cfg <<EOF
nfs=${nfspath}
netDev=${netif}
tryDHCP=YES
mediaSetNFS
EOF
else
	cat > /stand/media.cfg <<EOF
mediaSetCDROM
EOF
fi

But this does show how you can do all sorts of creative things for scripted 
installs w/o having to hack up sysinstall directly.

-- 
John Baldwin



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