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

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

Parent Directory Parent Directory | Revision Log Revision Log


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