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

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

Parent Directory Parent Directory | Revision Log Revision Log


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