summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluigi <luigi@FreeBSD.org>2006-12-03 23:50:29 +0000
committerluigi <luigi@FreeBSD.org>2006-12-03 23:50:29 +0000
commit517e9da299c252c370346915199f5c4712533357 (patch)
tree89640c63c8e50aad302ee76d9594dd68b0c42e60
parentded74f7ed853b2dd1444c4e63c776e1070ebaa14 (diff)
downloadFreeBSD-src-517e9da299c252c370346915199f5c4712533357.zip
FreeBSD-src-517e9da299c252c370346915199f5c4712533357.tar.gz
- put some common code in a function handle_remount();
- add better checks on non-existing directories to prevent error messages at run time; - introduce a function log() to help debugging diskless booting when things don't work; - modify the parsing of diskless_remount so you can add mount_nfs options after the pathname. You could use 'remount' to do something similar, but this way is more convenient because you don't have to hardwire the server name in the command. - document the above. I have been running the above in a diskless lab since february on RELENG_6. MFC after: 1 week
-rw-r--r--etc/rc.initdiskless81
1 files changed, 43 insertions, 38 deletions
diff --git a/etc/rc.initdiskless b/etc/rc.initdiskless
index 90ac718..744d767 100644
--- a/etc/rc.initdiskless
+++ b/etc/rc.initdiskless
@@ -70,12 +70,13 @@
# then /dev/ad0s3 will be be mounted on /conf/1.2.3.4/foo/
#
# /conf/T/M/diskless_remount
-# The contents of the file points to an NFS filesystem. E.g. if
-# /conf/base/etc/diskless_remount contains "foo.com:/etc",
-# then foo.com:/etc will be be mounted on /conf/base/etc/
-# If the file contains a pathname starting with "/", then
-# the root path is prepended to it; this allows relocation of
-# the root filesystem without changing configuration files.
+# The contents of the file points to an NFS filesystem,
+# possibly followed by mount_nfs options. If the server name
+# is omitted, the script will prepend the root path used when
+# booting. E.g. if you booted from foo.com:/path/to/root,
+# an entry for /conf/base/etc/diskless_remount could be any of
+# foo.com:/path/to/root/etc
+# /etc -o ro
# Because mount_nfs understands ".." in paths, it is
# possible to mount from locations above the NFS root with
# paths such as "/../../etc".
@@ -132,6 +133,14 @@
dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
+# DEBUGGING
+# log something on stdout if verbose.
+o_verbose=0 # set to 1 or 2 if you want more debugging
+log() {
+ [ ${o_verbose} -gt 0 ] && echo "*** $* ***"
+ [ ${o_verbose} -gt 1 ] && read -p "=== Press enter to continue" foo
+}
+
# chkerr:
#
# Routine to check for error
@@ -151,6 +160,23 @@ chkerr() {
esac
}
+# The list of filesystems to umount after the copy
+to_umount=""
+
+handle_remount() { # $1 = mount point
+ local nfspt mountopts b
+ b=$1
+ log handle_remount $1
+ [ -d $b -a -f $b/diskless_remount ] || return
+ read nfspt mountopts < $b/diskless_remount
+ log "nfspt ${nfspt} mountopts ${mountopts}"
+ # prepend the nfs root if not present
+ [ `expr "$nfspt" : '\(.\)'` = "/" ] && nfspt="${nfsroot}${nfspt}"
+ mount_nfs $mountopts $nfspt $b
+ chkerr $? "mount_nfs $nfspt $b"
+ to_umount="$b ${to_umount}"
+}
+
# Create a generic memory disk
#
mount_md() {
@@ -160,16 +186,16 @@ mount_md() {
# Create the memory filesystem if it has not already been created
#
create_md() {
- if [ "x`eval echo \\$md_created_$1`" = "x" ]; then
+ [ "x`eval echo \\$md_created_$1`" = "x" ] || return # only once
if [ "x`eval echo \\$md_size_$1`" = "x" ]; then
md_size=10240
else
md_size=`eval echo \\$md_size_$1`
fi
+ log create_md $1 with size $md_size
mount_md $md_size /$1
/bin/chmod 755 /$1
eval md_created_$1=created
- fi
}
# DEBUGGING
@@ -205,7 +231,7 @@ if [ ${dlv:=0} -ne 0 ] ; then
echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca} ${class}"
fi
-# Figure out our NFS root path
+log Figure out our NFS root path
#
set -- `mount -t nfs`
while [ $# -ge 1 ] ; do
@@ -228,19 +254,8 @@ if [ -n "${bootp_ipa}" ]; then
templates="${templates} ${bootp_ipa} ip/${bootp_ipa}"
fi
-# The list of filesystems to umount after the copy
-to_umount=""
-
# If /conf/diskless_remount exists, remount all of /conf.
-if [ -d /conf -a -f /conf/diskless_remount ]; then
- nfspt=`/bin/cat /conf/diskless_remount`
- if [ `expr "$nfspt" : '\(.\)'` = "/" ]; then
- nfspt="${nfsroot}${nfspt}"
- fi
- mount_nfs $nfspt /conf
- chkerr $? "mount_nfs $nfspt /conf"
- to_umount="/conf"
-fi
+handle_remount /conf
# Resolve templates in /conf/base, /conf/default, /conf/${bootp_ipbca},
# and /conf/${bootp_ipa}. For each subdirectory found within these
@@ -262,18 +277,17 @@ fi
# it before attemping to the remount. This allows the root to be
# relocated without needing to change the remount files.
#
+log "templates are ${templates}"
for i in ${templates} ; do
for j in /conf/$i/* ; do
+ [ -d $j ] || continue
+
# memory filesystem size specification
- #
subdir=${j##*/}
- if [ -d $j -a -f $j/md_size ]; then
- eval md_size_$subdir=`cat $j/md_size`
- fi
+ [ -f $j/md_size ] && eval md_size_$subdir=`cat $j/md_size`
- # remount
- #
- if [ -d $j -a -f $j/remount ]; then
+ # remount. Beware, the command is in the file itself!
+ if [ -f $j/remount ]; then
nfspt=`/bin/cat $j/remount`
$nfspt $j
chkerr $? "$nfspt $j"
@@ -281,16 +295,7 @@ for i in ${templates} ; do
fi
# NFS remount
- #
- if [ -d $j -a -f $j/diskless_remount ]; then
- nfspt=`/bin/cat $j/diskless_remount`
- if [ `expr "$nfspt" : '\(.\)'` = "/" ]; then
- nfspt="${nfsroot}${nfspt}"
- fi
- mount_nfs $nfspt $j
- chkerr $? "mount_nfs $nfspt $j"
- to_umount="$j ${to_umount}"
- fi
+ handle_remount $j
done
done
OpenPOWER on IntegriCloud