2 # Copyright (C) 2006 Sam Vilain <sam.vilain@catalyst.net.nz>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; version 2 of the License.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 tmp=$(getopt -o '+d:f:n:a' --long debug,pkgmgmt -n "$0" -- "$@") || exit 1
20 . "$_LIB_VSERVER_BUILD_FUNCTIONS_PKGMGMT"
21 . "$__PKGLIBDIR/vserver.functions"
26 FAI_NFSROOT=/usr/lib/fai/nfsroot
27 FAI_DIR=/usr/local/share/fai
33 -f) FAI_VSERVER=$2; shift; ;;
34 -n) FAI_NFSROOT=$2; shift; ;;
35 -d) FAI_DIR=$2; shift; ;;
37 --debug) DEBUG=1; SH_DEBUG=-x; set -x;;
39 *) echo "vserver-build.fai: internal error: unrecognized option '$1'" >&2
49 base.initFilesystem "$OPTION_FORCE"
51 setup_writeOption "$VSERVER_NAME"
52 setup_writeInitialFstab
54 test -z "$BUILD_INITPRE" || "$BUILD_INITPRE" "$SETUP_CONFDIR" "$UTIL_VSERVER_VARS"
56 # migrate is a 2.6 feature, we need 2.6 for the secure_mount ccap
57 if ! $_VSERVER_INFO - FEATURE migrate; then
59 The fai build method requires kernel features that are not present
63 # if they specified a vserver where FAI is installed, then prefix its
64 # root to the FAI_NFSROOT etc (unless they have already specified a
65 # $ROOTDIR-relative path)
66 REAL_ROOTDIR=`getPhysicalDir "$ROOTDIR"`
67 REAL_VDIR=`getPhysicalDir "$VDIR"`
68 echo $"ROOTDIR is $REAL_ROOTDIR"
69 echo $"VDIR is $REAL_VDIR"
70 if [ -n "$FAI_VSERVER" ]
72 echo "FAI_VSERVER is $FAI_VSERVER"
73 if [ `expr "$FAI_NFSROOT" : "$REAL_ROOTDIR"` -eq 0 ]
75 FAI_NFSROOT="$REAL_ROOTDIR/$FAI_VSERVER$FAI_NFSROOT"
77 if [ `expr "$FAI_DIR" : "$REAL_ROOTDIR"` -eq 0 ]
79 FAI_DIR="$REAL_ROOTDIR/$FAI_VSERVER$FAI_DIR"
82 echo $"FAI_NFSROOT is $FAI_NFSROOT"
83 echo $"FAI_DIR is $FAI_DIR"
86 if [ ! -e "$FAI_NFSROOT/usr/sbin/fai" ]
88 panic $"NFSROOT not found - did you run fai-setup?"
91 if ! grep -qw VIRTUAL "$FAI_NFSROOT/usr/sbin/fai"
94 ERROR: Looks like you don't have the patched FAI.
95 See http://faiwiki.informatik.uni-koeln.de/index.php/Using_FAI_as_a_vserver_build_method
96 for information on where to get it."
101 # suppresses color logo, as it does not leave the terminal in a nice
108 if isVserverRunning "$SETUP_CONFDIR" S_CONTEXT
110 $_VKILL -c "$S_CONTEXT" -s 15
112 $_VKILL -c "$S_CONTEXT" -s 9
114 isVserverRunning "$SETUP_CONFDIR" && warning $"\
115 Vserver '$VSERVER_NAME' still running unexpectedly; please investigate it
118 [ -n "$HAVE_INTERFACES" ] && disableInterfaces "$SETUP_CONFDIR"
122 trap killprocs INT EXIT
124 # last chance to abort!
127 echo -n "Press ENTER to begin, or Ctrl+C to cancel: "
131 # set up interfaces, so that the vserver can be built with restricted
133 generateOptions "$SETUP_CONFDIR"
134 enableInterfaces "$SETUP_CONFDIR"
137 rwpaths="/var/lock /var/log /dev /var/run /etc/sysconfig"
138 [ -d "$FAI_NFSROOT/etc/network/run" ] && rwpaths="$rwpaths /etc/network/run"
140 export VDIR ROOTDIR FAI_VSERVER FAI_DIR FAI_NFSROOT FAI_ROOT console
142 [ -z "$AUTO" ] && FINAL_SHELL="exec /bin/sh -i"
144 # set up /mnt with all the mounts required
145 $_SECURE_MOUNT -n -o ro,dev --bind "$FAI_NFSROOT" /mnt
146 $_SECURE_MOUNT -n -t tmpfs -o size=64m,mode=1777 vm /mnt/tmp
147 $_MKDIR -p /mnt/tmp/target
148 $_SECURE_MOUNT -n -o rw,dev --bind "$VDIR" /mnt/tmp/target
149 $_MKDIR -p /mnt/tmp/target/proc
150 $_SECURE_MOUNT -n -t proc proc /mnt/tmp/target/proc
153 /mnt/usr/lib/fai/mkrw -n "/mnt$x"
155 $_SECURE_MOUNT -n -o ro --bind "$FAI_DIR" /mnt/fai
156 $_SECURE_MOUNT -n -t proc proc /mnt/proc
159 $_CHBIND "${CHBIND_OPTS[@]}" \
160 $_VCONTEXT --create "${OPTS_VCONTEXT_CREATE[@]}" -- \
161 $_VUNAME --xid self --set -t nodename="${SETUP_HOSTNAME:-fai-build}" \
162 -t context="$SETUP_CONFDIR" -- \
163 $_VATTRIBUTE --set --xid self "${OPTS_VATTRIBUTE[@]}" --ccap secure_mount \
164 $_SAVE_CTXINFO "$SETUP_CONFDIR" \
165 $_VCONTEXT --migrate-self --endsetup --chroot $SILENT_OPT \
166 "${OPTS_VCONTEXT_MIGRATE[@]}" "${OPTS_VCONTEXT_ENTER[@]}" -- \
167 /bin/sh -c "/bin/sh $SH_DEBUG /etc/init.d/rcS -N vschild_build; $FINAL_SHELL"
169 test -z "$BUILD_INITPOST" || "$BUILD_INITPOST" "$SETUP_CONFDIR" "$UTIL_VSERVER_VARS"