source: hybrid/branches/releng-9.0/nanobsd/tools/prepare-nfs.sh@ 10441

Last change on this file since 10441 was 10441, checked in by rick, 13 years ago

The pf_flags are not always included causing the external definitions like
-Dif=foo not to be included, yielding false errors in the config files.

The needs to become an send-pr(1) patch, or otherwise reported (also not fixed
in CURRENT/HEAD yet).

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
File size: 2.5 KB
Line 
1#!/bin/sh
2# Get nanobsd image ready to be booted from NFS
3# NFS instructions at
4# http://www.wirelessleiden.nl/projects/nodefactory/wiki/TestingViaNFS
5
6IMAGE_BASE="/usr/obj/nanobsd.wleiden"
7IMAGE_SLICE="${IMAGE_BASE}/_.disk.image"
8IMAGE_FULL="${IMAGE_BASE}/_.disk.full"
9IMAGE_NFS="${IMAGE_SLICE}-nfs"
10# Structure: $NFSBASE
11# ./cfg = /cfg mounpoint
12# ./base = / mountpoint
13# ./nfs = /nfs mountpoint
14NFSBASE='/usr/data'
15MNT="${NFSBASE}/base"
16CFG="${NFSBASE}/cfg"
17NFS="${NFSBASE}/nfs"
18
19p_err() {
20 echo "[ERROR] $*" 1>&2
21}
22
23usage() {
24 (
25 echo "Usage: $0 [-fn]"
26 echo " -f force umount, memory device whipes"
27 echo " -n do not delete/clean cfg partition"
28 echo " -u unload/eject procedure"
29 ) 1>&2
30 exit 2
31}
32
33# No Root, no fun
34if [ `id -u` -ne 0 ]; then
35 p_err "Root only"
36 exit 1
37fi
38
39# Argument parsing using getopts
40OPT_FORCE=0
41OPT_CLEAN=1
42OPT_UNLOAD=0
43while getopts "hfnu" OPT; do
44 case "$OPT" in
45 f) OPT_FORCE=1;;
46 n) OPT_CLEAN=0;;
47 u) OPT_UNLOAD=1;;
48 h) usage;;
49 \?) usage;;
50 esac
51done
52
53
54# Eeks, we are going to be nasty, hold your horses
55if [ $OPT_FORCE -eq 1 -o $OPT_UNLOAD -eq 1 ]; then
56 umount -f $MNT
57 for MD in `mdconfig -l -v | grep "${IMAGE_NFS}" | awk '{print $1}'`; do
58 mdconfig -d -u $MD
59 done
60fi
61
62if [ $OPT_UNLOAD -eq 1 ]; then
63 echo "All done"
64 exit 1;
65fi
66
67# If mount point is already used, bail out
68if mount | grep -q "${MNT}"; then
69 p_err "'${MNT}' already mounted"
70 exit 1
71fi
72
73# If target nfs image is mounted somehow, bail out
74if mdconfig -l -v | grep -q "${IMAGE_NFS}"; then
75 MD=`mdconfig -l -v | grep "${IMAGE_NFS}" | cut -c -4`
76 p_err "'${IMAGE_NFS}' already mounted at '$MD'"
77 exit 1
78fi
79
80
81# Prepare image for use with NFS
82cp -v ${IMAGE_SLICE} ${IMAGE_NFS}
83
84MD=`mdconfig -a -t vnode -f ${IMAGE_NFS}`
85mount /dev/${MD}a ${MNT}
86
87# Config files lives at NFS location
88echo "mount -t nfs -o ro 192.168.4.1:${CFG}" > ${MNT}/conf/default/etc/remount
89
90# Create nfs mount location
91mkdir ${MNT}/nfs
92
93# $MNT, $CFG, $NFS lives at nfs
94(
95echo "192.168.4.1:${MNT} / nfs ro 0 0"
96echo "192.168.4.1:${CFG} /cfg nfs rw,noauto 0 0"
97echo "192.168.4.1:${NFS} /nfs nfs rw 0 0"
98) > /${MNT}/conf/base/etc/fstab
99
100if [ ${OPT_CLEAN} -eq 1 ]; then
101 echo "DELETING all files at ${CFG}, start fresh ;-)"
102 rm -vfR ${CFG}/*
103else
104 echo "PRESERVING all files at ${CFG}"
105fi
106
107echo "DELETING all files at ${NFS}, start fresh ;-)"
108rm -vfR ${NFS}/*
109
110# Allow build images to be used directy via NFS
111ln -f ${IMAGE_SLICE} ${NFS}/`basename ${IMAGE_SLICE}`
112ln -f ${IMAGE_FULL} ${NFS}/`basename ${IMAGE_FULL}`
113
114# XXX: Proper unmounting after all has finished
Note: See TracBrowser for help on using the repository browser.