/[fai]/trunk/bin/make-fai-nfsroot
ViewVC logotype

Contents of /trunk/bin/make-fai-nfsroot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3686 - (show annotations) (download)
Thu Jul 27 10:39:05 2006 UTC (6 years, 9 months ago) by lange
File size: 15812 byte(s)
remove $nfssize variable
1 #! /bin/bash
2
3 # $Id$
4 #*********************************************************************
5 #
6 # make-fai-nfsroot -- create nfsroot directory and add additional packages
7 #
8 # This script is part of FAI (Fully Automatic Installation)
9 # (c) 2000-2006 by Thomas Lange, lange@informatik.uni-koeln.de
10 # Universitaet zu Koeln
11 #
12 #*********************************************************************
13 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2 of the License, or
16 # (at your option) any later version.
17 #
18 # This program is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
22 #
23 # A copy of the GNU General Public License is available as
24 # `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution
25 # or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html. You
26 # can also obtain it by writing to the Free Software Foundation, Inc.,
27 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #*********************************************************************
29
30 PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin
31
32 if [ `id -u` -ne 0 ]; then
33 echo "Run this program as root."
34 exit 9
35 fi
36
37 merror="properly"
38 # option e currently does nothing
39 while getopts ervc:f:kK opt ; do
40 case "$opt" in
41 c) cfdir=$OPTARG ;;
42 v) verbose=1 ; v=-v ;;
43 r) recover=1 ;;
44 f) die "Option -f is not supported any more. Use option -c instead" ;;
45 k) kinstall=1 ;;
46 K) kremove=1; kinstall=1 ;;
47 e) expert=1 ;;
48 ?) exit 5 ;; # error in option parsing
49 esac
50 done
51
52 set -e
53
54 [ -z "$cfdir" ] && cfdir=/etc/fai
55 if [ ! -d "$cfdir" ]; then
56 echo "$cfdir is not a directory"
57 exit 6
58 fi
59 [ "$verbose" ] && echo "Using configuration files from directory $cfdir"
60 . $cfdir/fai.conf
61
62 # read config file for this tool
63 if [ -f "$cfdir/make-fai-nfsroot.conf" ]; then
64 . $cfdir/make-fai-nfsroot.conf
65 else
66 echo "Can't read $cfdir/make-fai-nfsroot.conf"
67 exit 8
68 fi
69
70 if [ -z "$NFSROOT" ]; then
71 echo "\$NFSROOT is not set. Please check your settings in $cfdir/fai.conf."
72 exit 4
73 fi
74
75 if [ "$FAI_SOURCES_LIST" ]; then
76 echo "The usage of the variable \$FAI_SOURCES_LIST is deprecated. Please use sources.list now."
77 exit 3
78 fi
79
80 if [ ! -d "$cfdir/apt" ]; then
81 echo "$cfdir/apt/ does not exists. Can't continue."
82 exit 7
83 fi
84
85 kfile="vmlinuz"
86 case `dpkg --print-installation-architecture` in
87 i386)
88 arch_packages="grub lilo dmidecode hwtools read-edid" ;;
89
90 amd64)
91 arch_packages="grub lilo dmidecode" ;;
92
93 ia64)
94 arch_packages="elilo gnu-efi efibootmgr dmidecode" ;;
95
96 sparc)
97 arch_packages="silo sparc-utils" ;;
98
99 powerpc)
100 arch_packages="" ;;
101
102 alpha)
103 arch_packages="aboot" ;;
104
105 *) arch_packages="" ;;
106 esac
107 packages="$packages
108 $arch_packages"
109
110 ROOTCMD="chroot $NFSROOT"
111
112 RUNDIR=/var/run/fai/make-fai-nfsroot
113 [ ! -d $RUNDIR ] && mkdir -p $RUNDIR
114 export DEBIAN_FRONTEND=noninteractive
115 [ "$recover" ] || rm -rf $RUNDIR/*
116
117 trap "umount_dirs" EXIT
118 trap "bad_exit" ERR
119 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
120 bad_exit() {
121
122 merror="with errors"
123 echo "An error occured during make-fai-nfsroot."
124 echo "Please fix the error or try make-fai-nfsroot -v"
125 }
126 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
127 die() {
128
129 echo "$@"
130 exit 99
131 }
132 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
133 call_with_stamp() {
134
135 local func=$1
136 local stamp=$RUNDIR/$func
137 # call subroutine
138 [ "$recover" -a -f $stamp ] && return 0
139 "$@"
140 > $stamp
141 }
142 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
143 call_verbose() {
144
145 if [ "$verbose" ]; then
146 "$@"
147 else
148 "$@" > /dev/null
149 fi
150 }
151 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
152 install_kernel_nfsroot() {
153
154 rm -rf $NFSROOT/boot/*-$KERNELVERSION $NFSROOT/lib/modules/$KERNELVERSION
155 # since woody we can install the kernel using dpkg -i
156 echo "do_boot_enable=no" > $NFSROOT/etc/kernel-img.conf
157 dpkg -x $KERNELPACKAGE $NFSROOT
158 echo "Kernel $KERNELVERSION installed into the nfsroot."
159 chroot $NFSROOT depmod -qaF /boot/System.map-$KERNELVERSION $KERNELVERSION || true
160 }
161 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
162 setup_ssh() {
163
164 # nothing to do if no ssh is available in nfsroot
165 [ -f $NFSROOT/usr/bin/ssh ] || return 0
166 mkdir -p -m 700 $NFSROOT/root/.ssh
167 if [ -n "$LOGUSER" ] ; then
168 loguserhome=`eval "cd ~$LOGUSER 2>/dev/null && pwd;true"`
169 # is copying of *.pub important?
170 [ -f $loguserhome/.ssh/known_hosts ] && cp $loguserhome/.ssh/known_hosts $NFSROOT/root/.ssh/known_hosts
171 [ -d $loguserhome/.ssh ] && {
172 [ -f $loguserhome/.ssh/id_dsa ] &&
173 cp -p $loguserhome/.ssh/id_dsa* $NFSROOT/root/.ssh/
174 [ -f $loguserhome/.ssh/id_rsa ] &&
175 cp -p $loguserhome/.ssh/id_rsa* $NFSROOT/root/.ssh/
176 cp -p $loguserhome/.ssh/*.pub $NFSROOT/root/.ssh/
177 }
178 fi
179
180 # enable root login
181 perl -pi -e 's/PermitRootLogin no/PermitRootLogin yes/' $NFSROOT/etc/ssh/sshd_config
182 if [ -f "$SSH_IDENTITY" ]; then
183 cp $SSH_IDENTITY $NFSROOT/root/.ssh/authorized_keys
184 chmod 0644 $NFSROOT/root/.ssh/authorized_keys
185 echo You can log into install clients without password using $SSH_IDENTITY
186 fi
187 }
188 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
189 copy_fai_files() {
190
191 # copy to nfsroot
192 echo "root:$FAI_ROOTPW" | $ROOTCMD chpasswd --encrypted
193 cd $NFSROOT
194 cp -Rpv $cfdir/* $NFSROOT/etc/fai
195 # remove some files that should not be copied
196 rm -f $NFSROOT/etc/fai/make-fai-nfsroot.conf
197 [ -f $cfdir/.cvspass ] && cp -p $v $cfdir/.cvspass $NFSROOT/.cvspass
198 $ROOTCMD shadowconfig on
199 }
200 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
201 call_debootstrap() {
202
203 local dversion=$(dpkg -l debootstrap | grep debootstrap | cut -f7 -d' ')
204 echo "Creating base system for $1 using debootstrap version $dversion"
205 [ "$verbose" ] && echo "Calling debootstrap $1 $NFSROOT $2"
206 yes '' | LC_ALL=C call_verbose debootstrap $FAI_DEBOOTSTRAP_OPTS $1 $NFSROOT $2
207 }
208 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
209 create_base() {
210
211 if [ "$FAI_DEBOOTSTRAP" ]; then
212 call_with_stamp call_debootstrap $FAI_DEBOOTSTRAP
213 $ROOTCMD apt-get clean
214 rm -f $NFSROOT/etc/resolv.conf
215 echo "Creating base.tgz"
216 tar --one-file-system -C $NFSROOT -cf - --exclude var/tmp/base.tgz . | gzip > $NFSROOT/var/tmp/base.tgz
217 touch $NFSROOT/.THIS_IS_THE_FAI_NFSROOT
218 else
219 die "\$FAI_DEBOOTSTRAP not defined."
220 fi
221 }
222 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
223 create_nfsroot() {
224
225 mkdir -p $NFSROOT/$FAI
226 cd $NFSROOT || die "Error: Can't cd to $NFSROOT"
227
228 call_with_stamp create_base
229 # save the list of all packages in the base.tgz
230 $ROOTCMD dpkg --get-selections | egrep 'install$' | awk '{print $1}' > var/tmp/base-pkgs.lis
231 echo $arch_packages > $NFSROOT/var/tmp/packages.arch
232
233 if [ "$FAI_DEBMIRROR" ]; then
234 [ "$verbose" ] && echo "Mounting $FAI_DEBMIRROR to $NFSROOT/$MNTPOINT."
235 mkdir -p $NFSROOT/$MNTPOINT
236 mount -o ro,noatime,rsize=8192 $FAI_DEBMIRROR $NFSROOT/$MNTPOINT || \
237 die "Can't mount $FAI_DEBMIRROR to $NFSROOT/$MNTPOINT."
238 fi
239
240 # hoaks some packages
241 # liloconfig, dump and raidtool2 needs these files
242 echo "# UNCONFIGURED FSTAB FOR BASE SYSTEM" > etc/fstab
243 > etc/raidtab
244 mkdir -p lib/modules/$KERNELVERSION # dirty trick to hoax lvm
245 > lib/modules/$KERNELVERSION/modules.dep # dirty trick to hoax lvm
246 echo 'NTPSERVERS=""' > etc/default/ntp-servers
247
248 [ -d $NFSROOT/var/state ] || mkdir $NFSROOT/var/state
249 cp -a $cfdir/apt $NFSROOT/etc
250
251 egrep -q "127.0.0.1" etc/hosts 2>/dev/null || echo "127.0.0.1 localhost" >> etc/hosts
252 egrep -q "$NFSROOT_ETC_HOSTS" etc/hosts 2>/dev/null || echo "$NFSROOT_ETC_HOSTS" >> etc/hosts
253 # we need these option before installing the first package. So we
254 # can't put this into fai-nfsroot /etc/apt/apt.conf.d/90fai
255 cat <<EOF >$NFSROOT/etc/apt/apt.conf.d/10fai
256 APT::Get::AllowUnauthenticated "true";
257 Aptitude::CmdLine::Ignore-Trust-Violations yes;
258 EOF
259 echo "Upgrading $NFSROOT"
260 LC_ALL=C call_verbose call_with_stamp upgrade_nfsroot
261 echo "Adding additional packages to $NFSROOT:"
262 echo "$packages"
263 LC_ALL=C call_verbose call_with_stamp add_packages_nfsroot
264 call_with_stamp copy_fai_files
265
266 # set timezone in nfsroot
267 timezone=$(readlink /etc/localtime | sed 's%^/usr/share/zoneinfo/%%')
268 echo $timezone > etc/timezone
269 rm -f etc/localtime && ln -sf /usr/share/zoneinfo/$timezone etc/localtime
270
271 # make little changes to nfsroot, because nfsroot is
272 # read only for the install clients
273 rm etc/mtab
274 ln -s /proc/mounts etc/mtab
275 [ -d "var/lib/discover" ] || mkdir var/lib/discover
276 mkdir etc/sysconfig tmp/etc
277 cp -p /etc/resolv.conf tmp/etc # so we have DNS after chroot $NFSROOT on the install server
278 ln -sf /tmp/etc/resolv.conf etc/resolv.conf
279 ln -s /usr/sbin/fai etc/init.d/rcS
280 # for nis
281 [ -d var/yp ] && ln -s /tmp/binding var/yp/binding
282
283 # definition for loopback device
284 echo "iface lo inet loopback" > etc/network/interfaces
285
286 echo "*.* /tmp/fai/syslog.log" > etc/syslog.conf
287 cat >> root/.profile <<-EOF
288 PATH=/usr/local/sbin:/usr/local/bin:/usr/lib/fai:/bin:/sbin:/usr/bin:/usr/sbin:
289 export PATH
290 . /usr/lib/fai/subroutines
291 . /usr/lib/fai/subroutines-linux
292 set -a
293 . /tmp/fai/variables.sh 2>/dev/null
294 EOF
295
296 call_verbose call_with_stamp setup_ssh
297
298 cat >$NFSROOT/etc/rc2.d/S01fai_abort <<-EOF
299 #!/bin/sh
300 echo FAI: installation aborted.
301 echo reboot with: faireboot
302 echo or after a logout
303 sh
304 cd /
305 umount -ar
306 reboot -dfi
307 EOF
308 chmod a+rx $NFSROOT/etc/rc2.d/S01fai_abort
309
310 # IMO this may be removed, since all information should be included into sources.list
311 [ -n "$FAI_LOCAL_REPOSITORY" ] && echo "WARNING: The use of \$FAI_LOCAL_REPOSITORY is now deprecated. Please include this information into sources.list." || true
312 }
313 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
314 upgrade_nfsroot() {
315
316 if [ -f /etc/resolv.conf ]; then
317 cp -p $v /etc/resolv.conf $NFSROOT/etc/resolv.conf-installserver
318 cp -p $v /etc/resolv.conf $NFSROOT/etc/resolv.conf # this is needed during make-fai-nfsroot
319 fi
320 $ROOTCMD apt-get update
321 $ROOTCMD apt-get -fyu install
322 $ROOTCMD apt-get check
323 rm -rf $NFSROOT/etc/apm
324 mount -t proc /proc $NFSROOT/proc
325
326 fdivert /sbin/start-stop-daemon /sbin/discover-modprobe
327 cp -p /sbin/fai-start-stop-daemon $NFSROOT/sbin/start-stop-daemon
328 $ROOTCMD apt-get -y dist-upgrade
329 }
330 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
331 add_packages_nfsroot() {
332
333 $ROOTCMD apt-get -y --fix-missing install $packages </dev/null
334 if [ -n "$NFSROOT_PACKAGES" ] ; then
335 LC_ALL=C $ROOTCMD apt-get -y --fix-missing install $NFSROOT_PACKAGES </dev/null
336 fi
337 $ROOTCMD apt-get clean
338 }
339 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
340 umount_dirs() {
341
342 [ -f $NFSROOT/usr/sbin/dpkg-divert ] &&
343 LC_ALL=C $ROOTCMD dpkg-divert --rename --remove /sbin/discover-modprobe
344 cd /
345 sleep 2
346 [ -d $NFSROOT/proc/self ] && umount $NFSROOT/proc
347 [ -d $NFSROOT/proc/self ] && umount $NFSROOT/dev/pts
348 if [ "$FAI_DEBMIRROR" ]; then
349 test -d $NFSROOT/$MNTPOINT && umount $NFSROOT/$MNTPOINT || true
350 fi
351 # show directories still mounted on nfsroot
352 mount | grep " on $NFSROOT " || true
353 }
354 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
355 get_kernel_version() {
356
357 local package=$1
358
359 KERNELVERSION=`dpkg --info $package | grep ' Package: '`
360 KERNELVERSION=${KERNELVERSION/*-image-/}
361 }
362 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
363 setup_bootp(){
364
365 if [ -x "`which mkelf-linux`" ]; then
366 mkelf-linux --ip=any --output=/srv/tftp/fai/installimage \
367 $NFSROOT/boot/$kfile-$KERNELVERSION
368 else
369 echo "Command mkelf-linux not found. Can not set up BOOTP booting. Please install the package mknbi and rerun fai-setup."
370 return
371 fi
372
373 # imggen is free software from 3com - use ver1.00: 1.01 produces "Image too Big" errors.
374 # it converts netboot images to images which are bootable by 3com network cards
375 if [ -x "`which imggen`" ]; then
376 imggen -a /srv/tftp/fai/installimage /srv/tftp/fai/installimage_3com
377 fi
378 echo "BOOTP environment prepared."
379 }
380
381 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
382 setup_dhcp(){
383
384 # pxe and dhcp environment
385 local pxebin=/usr/lib/syslinux/pxelinux.0
386 cp -p $NFSROOT/boot/$kfile-$KERNELVERSION /srv/tftp/fai/$kfile-install
387 [ -f $pxebin ] && cp $pxebin /srv/tftp/fai
388 [ -d /srv/tftp/fai/pxelinux.cfg ] || mkdir -p /srv/tftp/fai/pxelinux.cfg
389 echo "DHCP environment prepared. If you want to use it, you have to enable the dhcpd and the tftp-hpa daemon."
390 }
391 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
392 fdivert() {
393
394 local item
395 for item in "$@"; do
396 LC_ALL=C $ROOTCMD dpkg-divert --quiet --add --rename $item
397 done
398 }
399 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
400 kernel_install() {
401
402 # Install the kernel package
403 if [ -f $KERNELPACKAGE ]; then
404 # determine kernel version
405 get_kernel_version $KERNELPACKAGE
406
407 # create tftp boot images
408 call_with_stamp install_kernel_nfsroot
409
410 # setup for DHCP, BOOTP or both
411 [ "x$FAI_BOOT" = "x" ] && FAI_BOOT="dhcp bootp"
412
413 for bootopt in $FAI_BOOT; do
414 case $bootopt in
415 dhcp|DHCP)
416 call_with_stamp setup_dhcp ;;
417 bootp|BOOTP)
418 call_with_stamp setup_bootp ;;
419 *)
420 echo "Unknown boot option" ;;
421 esac
422 done
423 else
424 merror="with errors"
425 echo "Error. Kernel package $KERNELPACKAGE not found."
426 echo "No install kernel installed in /srv/tftp/fai."
427 echo "No kernel modules available in nfsroot."
428 fi
429 }
430 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
431 # main routine
432
433 [ -z "$KERNELPACKAGE" ] && die "\$KERNELPACKAGE is not set. Aborting."
434
435 # remove all kernels from nfsroot
436 [ -n "$kremove" ] && {
437 echo "Removing all kernels from NFSROOT."
438 rm -f $NFSROOT/boot/{System.map,vmlinuz,config,patches}*
439 rm -rf $NFSROOT/lib/modules/2.*
440 }
441
442 # just install a new kernel to the nfsroot
443 [ -n "$kinstall" ] && {
444 trap "true" EXIT
445 echo "Installing new kernel into the nfsroot."
446 kernel_install
447 echo "New kernel from" $KERNELPACKAGE "installed into the nfsroot."
448 exit
449 }
450
451 echo "Creating FAI nfsroot in $NFSROOT."
452 echo "By default it needs more than 250 MBytes disk space."
453 echo "This may take a long time."
454
455 # Kill the directory if not in recover mode
456 if [ -d $NFSROOT/$FAI -a ! "$recover" ]
457 then
458 echo $NFSROOT already exists. Removing $NFSROOT
459 umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true
460 rm -rf $NFSROOT/.??* $NFSROOT/*
461 # also remove files $NFSROOT/.? but not . and ..
462 find $NFSROOT -xdev -maxdepth 1 ! -type d | xargs -r rm -f
463 fi
464
465 # Create a new nfsroot
466 if [ ! -x "`which debootstrap`" ]; then
467 die "Can't find debootstrap command. Aborting."
468 fi
469 call_with_stamp create_nfsroot
470
471 kernel_install
472
473 umount_dirs
474 trap "true" EXIT
475 echo "make-fai-nfsroot finished $merror."
476 exit 0

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.5