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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 869 by lange, Mon Oct 29 15:52:44 2001 UTC revision 2474 by lange, Sat Oct 23 21:21:35 2004 UTC
# Line 1  Line 1 
1  #! /bin/sh  #! /bin/bash
2    
3  # $Id$  # $Id$
4  #*********************************************************************  #*********************************************************************
# Line 6  Line 6 
6  # make-fai-nfsroot -- create nfsroot directory and add additional packages  # make-fai-nfsroot -- create nfsroot directory and add additional packages
7  #  #
8  # This script is part of FAI (Fully Automatic Installation)  # This script is part of FAI (Fully Automatic Installation)
9  # (c) 2000-2001 by Thomas Lange, lange@informatik.uni-koeln.de  # (c) 2000-2004 by Thomas Lange, lange@informatik.uni-koeln.de
10  # Universitaet zu Koeln  # Universitaet zu Koeln
11  #  #
12  #*********************************************************************  #*********************************************************************
# Line 27  Line 27 
27  # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28  #*********************************************************************  #*********************************************************************
29    
30  # Packages that are install to nfsroot by default  
31  # Additional packages are defined with $NFSROOT_PACKAGES in fai.conf  PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin
32  packages="dhcp-client file rdate cfengine bootpc wget rsh-client less dump ext2resize strace hdparm parted dnsutils grub ntpdate psmisc hwtools dosfstools"  
33    if [ `id -u` -ne 0 ]; then
34  PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin      echo "Run this program as root."
35        exit 9
 if [ "$UID" -ne 0 ]; then  
  echo "Run this program as root."  
  exit 9  
36  fi  fi
37    
38  while getopts v opt ; do  merror="properly"
39          case "$opt" in  # option e currently does nothing
40          v) verbose=1 ;;  while getopts ervc:f:kK opt ; do
41          esac      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  done
52    
53  set -e  set -e
 . /etc/fai.conf  
 packages="$packages $NFSROOT_PACKAGES"  
 ROOTCMD="chroot $NFSROOT"  
54    
55  LIBFAI=/usr/lib/fai  [ -z "$cfdir" ] && cfdir=/etc/fai
56  conffile=$NFSROOT/etc/rcS_fai.conf  if [ ! -d "$cfdir" ]; then
57  export DEBIAN_FRONTEND=Noninteractive      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  if [ "$verbose" ]; then  # read config file for this tool
68          devnull=/dev/tty  if [ -f "$cfdir/make-fai-nfsroot.conf" ]; then
69        . $cfdir/make-fai-nfsroot.conf
70  else  else
71          devnull=/dev/null      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.lsit now."
82        exit 3
83  fi  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        ia64)
97            arch_packages="elilo gnu-efi efibootmgr" ;;
98    
99        sparc|sparc64)
100            arch_packages="silo sparc-utils" ;;
101    
102        ppc)
103            arch_packages=""
104            kfile="vmlinux" ;;
105    
106        *)  arch_packages="" ;;
107    esac
108    packages="$packages
109    $arch_packages"
110    
111    ROOTCMD="chroot $NFSROOT"
112    
113    RUNDIR=/var/run/fai/make-fai-nfsroot
114    [ ! -d $RUNDIR ] && mkdir -p $RUNDIR
115    LIBFAI=/usr/lib/fai
116    SHAREFAI=/usr/share/fai
117    export DEBIAN_FRONTEND=noninteractive
118    [ "$recover" ] || rm -rf $RUNDIR/*
119    
120  trap "umount_dirs" EXIT  trap "umount_dirs" EXIT
121    trap "bad_exit" ERR
122    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
123    bad_exit() {
124    
125        merror="with errors"
126        echo "An error occured during make-fai-nfsroot."
127        echo "Please fix the error or try make-fai-nfsroot -v"
128    }
129  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
130  die() {  die() {
131    
132      echo $*      echo "$@"
133      exit 99      exit 99
134  }  }
135  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
136    call_with_stamp() {
137    
138        local func=$1
139        local stamp=$RUNDIR/$func
140        # call subroutine
141        [ "$recover" -a -f $stamp ] && return 0
142        "$@"
143        > $stamp
144    }
145    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
146    call_verbose() {
147    
148        if [ "$verbose" ]; then
149            "$@"
150        else
151            "$@" > /dev/null
152        fi
153    }
154    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
155  install_kernel_nfsroot() {  install_kernel_nfsroot() {
156    
157      rm -rf $NFSROOT/boot/*-$KERNELVERSION $NFSROOT/lib/modules/$KERNELVERSION      rm -rf $NFSROOT/boot/*-$KERNELVERSION $NFSROOT/lib/modules/$KERNELVERSION
158        # since woody we can install the kernel using dpkg -i
159        echo "do_boot_enable=no" > $NFSROOT/etc/kernel-img.conf
160      dpkg -x $KERNELPACKAGE $NFSROOT      dpkg -x $KERNELPACKAGE $NFSROOT
161      # if $NFROOT/proc/modules exists, then update-modules calls depmod -a without      # if $NFROOT/proc/modules exists, then update-modules calls depmod -a without
162      # these special flags; so umount first      # these special flags; so umount first
163      umount $NFSROOT/proc      [ -e $NFSROOT/proc/modules ] && umount $NFSROOT/proc
164      chroot $NFSROOT update-modules      chroot $NFSROOT update-modules
165      chroot $NFSROOT depmod -a -F /boot/System.map-$KERNELVERSION $KERNELVERSION      chroot $NFSROOT depmod -qaF /boot/System.map-$KERNELVERSION $KERNELVERSION || true
166  }  }
167  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
168  setup_ssh() {  setup_ssh() {
# Line 83  setup_ssh() { Line 170  setup_ssh() {
170      # nothing to do if no ssh is available in nfsroot      # nothing to do if no ssh is available in nfsroot
171      [ -f $NFSROOT/var/lib/dpkg/info/ssh.list ] || return 0      [ -f $NFSROOT/var/lib/dpkg/info/ssh.list ] || return 0
172      mkdir -p -m 700 $NFSROOT/root/.ssh      mkdir -p -m 700 $NFSROOT/root/.ssh
173      [ -f /etc/ssh/ssh_known_hosts ] && cp /etc/ssh/ssh_known_hosts $NFSROOT/root/.ssh/known_hosts      if [ -n "$LOGUSER" ] ; then
174      loguserhome=`eval "cd ~$LOGUSER 2>/dev/null && pwd;true"`          loguserhome=`eval "cd ~$LOGUSER 2>/dev/null && pwd;true"`
175      [ -d $loguserhome/.ssh ] && cp -p $loguserhome/.ssh/identity* $NFSROOT/root/.ssh/      # is copying of *.pub important?
176            [ -f $loguserhome/.ssh/known_hosts ] && cp $loguserhome/.ssh/known_hosts $NFSROOT/root/.ssh/known_hosts
177            [ -d $loguserhome/.ssh ] && {
178                [ -f $loguserhome/.ssh/id_dsa ] &&
179                   cp -p $loguserhome/.ssh/id_dsa* $NFSROOT/root/.ssh/
180                [ -f $loguserhome/.ssh/id_rsa ] &&
181                   cp -p $loguserhome/.ssh/id_rsa* $NFSROOT/root/.ssh/
182                cp -p $loguserhome/.ssh/*.pub $NFSROOT/root/.ssh/
183            }
184        fi
185    
186      # enable root login      # enable root login
187      perl -pi -e 's/PermitRootLogin no/PermitRootLogin yes/' $NFSROOT/etc/ssh/sshd_config      perl -pi -e 's/PermitRootLogin no/PermitRootLogin yes/' $NFSROOT/etc/ssh/sshd_config
188      if [ -f "$SSH_IDENTITY" ]; then      if [ -f "$SSH_IDENTITY" ]; then
189          cp -p $SSH_IDENTITY $NFSROOT/root/.ssh/authorized_keys          cp $SSH_IDENTITY $NFSROOT/root/.ssh/authorized_keys
190          echo You can log into install clients without password using $SSH_IDENTITY          chmod 0644 $NFSROOT/root/.ssh/authorized_keys
191            echo You can log into install clients without password using $SSH_IDENTITY
192      fi      fi
193  }  }
194  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
195  copy_fai_files() {  copy_fai_files() {
196    
197      # copy to nfsroot      # copy to nfsroot
198      perl -pi -e "s/^root::/root:${FAI_ROOTPW}:/" etc/passwd      perl -pi -e "s#^root::#root:${FAI_ROOTPW}:#" etc/passwd
199      mkdir -p $NFSROOT/fai/fai_config $NFSROOT/usr/share/fai      mkdir -p $NFSROOT/$SHAREFAI $NFSROOT/$LIBFAI $NFSROOT/etc/fai
200      cd $NFSROOT      cd $NFSROOT
201      cp -p $LIBFAI/sbin/dhclient-script $LIBFAI/etc/dhclient.conf /etc/fai.conf etc      fdivert /etc/dhcp3/dhclient-script /etc/dhcp3/dhclient.conf
202      cp -p $LIBFAI/sbin/* sbin      cp -p $SHAREFAI/etc/dhclient.conf etc/dhcp3
203      cp -p $LIBFAI/etc/fai_modules_off etc/modutils      cp -Rpv $cfdir/* $NFSROOT/etc/fai
204        rm -f $NFSROOT/etc/fai/make-fai-nfsroot.conf
205      cp -p /usr/share/fai/subroutines usr/share/fai      [ -f $cfdir/.cvspass ] && cp -p $v $cfdir/.cvspass $NFSROOT/.cvspass
206      cp -p $LIBFAI/etc/apt.conf etc/apt      cp -p $LIBFAI/sbin/* sbin/
207      cp -p /usr/lib/perl5/Debian/Fai.pm usr/lib/perl5/Debian/      mv sbin/dhclient-script etc/dhcp3
208      echo $NFSROOT_ETC_HOSTS >> etc/hosts      cp -p /usr/sbin/{ftar,fcopy,install_packages} usr/sbin/
209        cp -p /usr/bin/{fai-do-scripts,fai-class} usr/bin/
210        cp -p $LIBFAI/* usr/lib/fai 2>/dev/null || true  # cp will complain about directories
211        cp -p $SHAREFAI/etc/fai_modules_off etc/modutils/
212    
213        cp -p $SHAREFAI/subroutines* usr/share/fai
214        cp -p $v $SHAREFAI/etc/apt.conf $NFSROOT/etc/apt
215        cp -p /usr/share/perl5/Debian/Fai.pm usr/share/perl5/Debian/
216        $ROOTCMD pwconv # enable shadow
217  }  }
218  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
219  call_debootstrap() {  call_debootstrap() {
220    
221      echo "Creating nfsroot for $1 using debootstrap"      echo "Creating nfsroot for $1 using debootstrap"
222      [ "$verbose" ] && echo "calling debootstrap $1 $NFSROOT $2"      [ "$verbose" ] && echo "Calling debootstrap $1 $NFSROOT $2"
223      LC_ALL=C debootstrap $1 $NFSROOT $2 > $devnull 2>&1      yes '' | LC_ALL=C call_verbose debootstrap $FAI_DEBOOTSTRAP_OPTS $1 $NFSROOT $2 || true
224  }  }
225  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
226  create_base() {  create_base() {
227    
228      if [ "$FAI_DEBOOTSTRAP" ]; then      if [ "$FAI_DEBOOTSTRAP" ]; then
229          call_debootstrap $FAI_DEBOOTSTRAP          call_with_stamp call_debootstrap $FAI_DEBOOTSTRAP
230          echo "Creating base.tgz"          $ROOTCMD apt-get clean
231          tar -C $NFSROOT -cf - . | gzip > $NFSROOT/../base.tgz          echo "Creating base.tgz"
232          mv $NFSROOT/../base.tgz $NFSROOT/var/tmp/base.tgz          tar -l -C $NFSROOT -cf - --exclude var/tmp/base.tgz . | gzip > $NFSROOT/var/tmp/base.tgz
233      else      else
234          # old method for potato          die "\$FAI_DEBOOTSTRAP not defined."
         get_basetgz  
         echo "Unpacking base2_2.tgz"  
         zcat /tmp/base2_2.tgz | tar -C $NFSROOT -xpf -  
         cp -p /tmp/base2_2.tgz $NFSROOT/var/tmp/base.tgz  
235      fi      fi
236  }  }
237  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
238  create_nfsroot() {  create_nfsroot() {
239    
240      mkdir -p $NFSROOT/fai      mkdir -p $NFSROOT/$FAI
241      cd $NFSROOT || die "Error: Can't cd to $NFSROOT"      cd $NFSROOT || die "Error: Can't cd to $NFSROOT"
242      create_base  
243      mknod dev/boot255 c 0 255      call_with_stamp create_base
244    
245      if [ "$FAI_DEBMIRROR" ]; then      if [ "$FAI_DEBMIRROR" ]; then
246          mkdir -p $NFSROOT/$MNTPOINT          [ "$verbose" ] && echo "Mounting $FAI_DEBMIRROR to $NFSROOT/$MNTPOINT."
247          mount -o ro,rsize=8192 $FAI_DEBMIRROR $NFSROOT/$MNTPOINT || die "Can't mount $FAI_DEBMIRROR"          mkdir -p $NFSROOT/$MNTPOINT
248      fi          mount -o ro,noatime,rsize=8192 $FAI_DEBMIRROR $NFSROOT/$MNTPOINT || \
249                    die "Can't mount $FAI_DEBMIRROR to $NFSROOT/$MNTPOINT."
250            fi
251    
252      # hoaks some packages      # hoaks some packages
253      > etc/fstab # dump and raidtool2 needs these files      # liloconfig, dump and raidtool2 needs these files
254        echo "# UNCONFIGURED FSTAB FOR BASE SYSTEM" > etc/fstab
255      > etc/raidtab      > etc/raidtab
256      mkdir -p lib/modules/$KERNELVERSION           # dirty trick to hoax lvm      mkdir -p lib/modules/$KERNELVERSION           # dirty trick to hoax lvm
257      >  lib/modules/$KERNELVERSION/modules.dep  # dirty trick to hoax lvm      >  lib/modules/$KERNELVERSION/modules.dep  # dirty trick to hoax lvm
258      mkdir -p etc/ssh      echo 'NTPSERVERS=""' > etc/default/ntp-servers
     > etc/ssh/NOSERVER  
259    
260      if [ "$FAI_SOURCES_LIST" ]; then      [ -d $NFSROOT/var/state ] || mkdir $NFSROOT/var/state
261          echo "$FAI_SOURCES_LIST" > etc/apt/sources.list      [ "$verbose" ] && echo "Try to copy $cfdir/sources.list or /etc/apt/sources.list."
262      else      cp -v $cfdir/sources.list $NFSROOT/etc/apt/sources.list || \
263          cp /etc/apt/sources.list etc/apt/sources.list          cp -v /etc/apt/sources.list $NFSROOT/etc/apt/sources.list || \
264      fi          { echo "No sources.list file found."
265      upgrade_nfsroot            echo "I think something is wrong. But I'll try to continue."
266      copy_fai_files          }
267    
268        echo "127.0.0.1 localhost" >> etc/hosts
269        echo "$NFSROOT_ETC_HOSTS" >> etc/hosts
270        [ -f /etc/apt/preferences ] && cp -v /etc/apt/preferences $NFSROOT/etc/apt
271        [ -f $cfdir/preferences ] && cp -v $cfdir/preferences $NFSROOT/etc/apt
272        echo "Upgrading $NFSROOT"
273        LC_ALL=C call_verbose call_with_stamp upgrade_nfsroot
274        echo "Adding additional packages to $NFSROOT:"
275        echo "$packages"
276        LC_ALL=C call_verbose call_with_stamp add_packages_nfsroot
277        call_with_stamp copy_fai_files
278    
279      # set timezone      # set timezone in nfsroot
280      rm -f etc/localtime      timezone=$(readlink /etc/localtime | sed 's%^/usr/share/zoneinfo/%%')
281      cp -d /etc/localtime /etc/timezone etc      echo $timezone > etc/timezone
282        rm -f etc/localtime && ln -sf /usr/share/zoneinfo/$timezone etc/localtime
283    
284      # make little changes to nfsroot, because nfsroot is      # make little changes to nfsroot, because nfsroot is
285      # read only for the install clients      # read only for the install clients
286      rm -rf etc/mtab var/run      rm -rf etc/mtab var/run etc/sysconfig
     mv etc/init.d/rcS etc/init.d/rcS.orig  
287      ln -s /proc/mounts etc/mtab      ln -s /proc/mounts etc/mtab
288      ln -s /tmp/var/run var/run      ln -s /tmp/var/run var/run
289        ln -sf /tmp/var/state/discover var/state/discover
290        ln -s /tmp/etc/syslogsocket dev/log
291      ln -sf /tmp/etc/resolv.conf etc/resolv.conf      ln -sf /tmp/etc/resolv.conf etc/resolv.conf
292      ln -s /sbin/rcS_fai etc/init.d/rcS      ln -sf /tmp etc/sysconfig
293        ln -s ../../sbin/rcS_fai etc/init.d/rcS
294        ln -sf /dev/null etc/network/ifstate
295      # for nis      # for nis
296      [ -d var/yp ] && ln -s /tmp/binding var/yp/binding      [ -d var/yp ] && ln -s /tmp/binding var/yp/binding
297    
# Line 184  create_nfsroot() { Line 302  create_nfsroot() {
302      # definition for loopback device      # definition for loopback device
303      echo "iface lo inet loopback" > etc/network/interfaces      echo "iface lo inet loopback" > etc/network/interfaces
304    
305      echo "*.* /tmp/syslog.log" > etc/syslog.conf      echo "*.* /tmp/fai/syslog.log" > etc/syslog.conf
306      echo ". /usr/share/fai/subroutines" >> root/.profile      cat >> root/.profile <<-EOF
307            PATH=/usr/local/sbin:/usr/local/bin:/usr/lib/fai:/bin:/sbin:/usr/bin:/usr/sbin:
308            export PATH
309            . $SHAREFAI/subroutines
310            . $SHAREFAI/subroutines-$OS_TYPE
311            set -a
312            . /tmp/fai/variables.sh 2>/dev/null
313    EOF
314    
315      setup_ssh      call_verbose call_with_stamp setup_ssh
316    
317      cat >$NFSROOT/etc/rc2.d/S01fai_abort <<-EOF      cat >$NFSROOT/etc/rc2.d/S01fai_abort <<-EOF
318          #!/bin/sh          #!/bin/sh
319          echo FAI: installation aborted.          echo FAI: installation aborted.
320          echo reboot with: faireboot          echo reboot with: faireboot
321          echo or after a logout          echo or after a logout
322          sh          sh
323          cd /          cd /
324          umount -ar          umount -ar
325          reboot -dfi          reboot -dfi
326  EOF  EOF
327      chmod a+rx $NFSROOT/etc/rc2.d/S01fai_abort      chmod a+rx $NFSROOT/etc/rc2.d/S01fai_abort
328    
329        echo -e "\n$FAI_LOCAL_REPOSITORY" >> etc/apt/sources.list
330  }  }
331  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
332  upgrade_nfsroot() {  upgrade_nfsroot() {
333    
334      echo "Upgrading $NFSROOT"      cp -p $v /etc/resolv.conf $NFSROOT/etc/resolv.conf-installserver
     {  
     cp /etc/resolv.conf $NFSROOT/etc  
335      $ROOTCMD apt-get update      $ROOTCMD apt-get update
336        $ROOTCMD apt-get -fyu install
337      $ROOTCMD apt-get check      $ROOTCMD apt-get check
338      rm -rf $NFSROOT/etc/apm      rm -rf $NFSROOT/etc/apm
339      mount -t proc /proc $NFSROOT/proc      mount -t proc /proc $NFSROOT/proc
     $ROOTCMD apt-get --purge -y remove debconf+ pcmcia-cs ppp pppconfig </dev/null  
340    
341      # fake start-stop-dameon      # fake start-stop-dameon
342      $ROOTCMD dpkg-divert --quiet --package fai --add --rename /sbin/start-stop-daemon      fdivert /etc/init.d/rcS /sbin/start-stop-daemon /sbin/discover-modprobe
343      cp $LIBFAI/sbin/start-stop-daemon $NFSROOT/sbin      cp /sbin/fai-start-stop-daemon $NFSROOT/sbin/
344      $ROOTCMD apt-get -y upgrade      ln -s /sbin/fai-start-stop-daemon $NFSROOT/sbin/start-stop-daemon
345      } > $devnull      $ROOTCMD apt-get -y dist-upgrade
     echo "Adding additional packages to $NFSROOT:"  
     echo "$packages"  
     {  
     $ROOTCMD apt-get -y --fix-missing install $packages </dev/null  
     $ROOTCMD apt-get clean  
     } > $devnull  
346  }  }
347  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
348  get_basetgz() {  add_packages_nfsroot() {
349    
350      [ -f /tmp/base2_2.tgz ] && return      $ROOTCMD apt-get -y --fix-missing install $packages </dev/null
351      [ "$FAI_BASETGZ" ] || die "No /tmp/base2_2.tgz found and FAI_BASETGZ not defined."      if [ -n "$NFSROOT_PACKAGES" ] ; then
352      case $FAI_BASETGZ in          LC_ALL=C $ROOTCMD apt-get -y --fix-missing install $NFSROOT_PACKAGES </dev/null
353          ftp:*|http:*)      fi
354              echo "Fetching $FAI_BASETGZ via wget. This may take some time."      $ROOTCMD apt-get clean
             TMPBDIR=`mktemp /tmp/FAI-wget-XXXXXX` || exit 1  
             rm $TMPBDIR; mkdir $TMPBDIR || exit  
             wget -P$TMPBDIR $FAI_BASETGZ  
             mv $TMPBDIR/base2_2.tgz /tmp  
             rm -rf $TMPBDIR  
             ;;  
         /*/base2_2.tgz)  
             rm -f /tmp/base2_2.tgz  
             test -r $FAI_BASETGZ || die "Can't read $FAI_BASETGZ. Check FAI_BASETGZ in fai.conf."  
             ln -s $FAI_BASETGZ /tmp  
             ;;  
         *)  
             die "FAI_BASETGZ in fai.conf is $FAI_BASETGZ and looks very strange."  
             ;;  
     esac  
355  }  }
356  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
357  umount_dirs() {  umount_dirs() {
358    
359        [ -f $NFSROOT/usr/sbin/dpkg-divert ] &&
360           LC_ALL=C $ROOTCMD dpkg-divert --package fai --rename --remove /sbin/discover-modprobe
361      cd /      cd /
362      sleep 2      sleep 2
363      umount $NFSROOT/proc 1>/dev/null 2>&1 || true      [ -d $NFSROOT/proc/self ] && umount $NFSROOT/proc
364      umount $NFSROOT/dev/pts 1>/dev/null 2>&1 ||true      [ -d $NFSROOT/proc/self ] && umount $NFSROOT/dev/pts
365      if [ "$FAI_DEBMIRROR" ]; then      if [ "$FAI_DEBMIRROR" ]; then
366          test -d $NFSROOT/$MNTPOINT && umount $NFSROOT/$MNTPOINT || true          test -d $NFSROOT/$MNTPOINT && umount $NFSROOT/$MNTPOINT || true
367      fi      fi
368      # show directories still mounted on nfsroot      # show directories still mounted on nfsroot
369      mount | grep " on $NFSROOT " || true      mount | grep " on $NFSROOT " || true
370  }  }
371  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
372    get_kernel_version() {
373    
374        local package=$1
375        KERNELVERSION=`dpkg --info $package | grep "Package: kernel-image" | sed -e 's/.*kernel-image-'//`
376    }
377    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
378    setup_bootp(){
379    
380        if [ -x "`which mkelf-linux`" ]; then
381            mkelf-linux --ip=any --output=/boot/fai/installimage \
382              $NFSROOT/boot/$kfile-$KERNELVERSION
383        else
384            echo "Command mkelf-linux not found. Can not set up BOOTP booting. Please install the package mknbi and rerun fai-setup."
385            return
386        fi
387    
388        # imggen is free software from 3com - use ver1.00: 1.01 produces "Image too Big" errors.
389        # it converts netboot images to images which are bootable by 3com network cards
390        if [ -x "`which imggen`" ]; then
391            imggen -a /boot/fai/installimage /boot/fai/installimage_3com
392        fi
393        echo "BOOTP environment prepared."
394    }
395    
396    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
397    setup_dhcp(){
398    
399        # pxe and dhcp environment
400        local pxebin=/usr/lib/syslinux/pxelinux.0
401        cp -p $NFSROOT/boot/$kfile-$KERNELVERSION /boot/fai/$kfile-install
402        [ -f $pxebin ] && cp $pxebin /boot/fai
403        [ -d /boot/fai/pxelinux.cfg ] || mkdir -p /boot/fai/pxelinux.cfg || true
404        echo "DHCP environment prepared. If you want to use it, you have to enable the dhcpd and the tftp-hpa daemon."
405    }
406    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
407    fdivert() {
408    
409        for item in "$@"; do
410            LC_ALL=C $ROOTCMD dpkg-divert --quiet --package fai --add --rename $item
411        done
412    }
413    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
414    kernel_install() {
415    
416    # Install the kernel package
417    if [ -f $KERNELPACKAGE ]; then
418        # determine kernel version
419        get_kernel_version $KERNELPACKAGE
420    
421        # create tftp boot images
422        call_with_stamp install_kernel_nfsroot
423    
424        # setup for DHCP, BOOTP or both
425        [ "x$FAI_BOOT" = "x" ] && FAI_BOOT="dhcp bootp"
426    
427        for bootopt in $FAI_BOOT; do
428            case $bootopt in
429                    dhcp|DHCP)
430                            call_with_stamp setup_dhcp ;;
431                    bootp|BOOTP)
432                            call_with_stamp setup_bootp ;;
433                    *)
434                            echo "Unknown boot option" ;;
435            esac
436        done
437    else
438        merror="with errors"
439        echo "Error. Kernel package $KERNELPACKAGE not found."
440        echo "No install kernel installed in /boot/fai."
441        echo "No kernel modules available in nfsroot."
442    fi
443    }
444    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
445  # main routine  # main routine
446    
447  if [ -d $NFSROOT/fai ]; then  # remove all kernels from nfsroot
448    [ -n "$kremove" ] && {
449        echo "Removing all kernels from NFSROOT."
450        rm -f $NFSROOT/boot/{System.map,vmlinuz,config}*
451        rm -rf $NFSROOT/lib/modules/2.*
452    }
453    # just install a new kernel to the nfsroot
454    [ -n "$kinstall" ] && {
455        trap "true" EXIT
456        echo "Installing new kernel into the nfsroot."
457        kernel_install
458        echo "New kernel from $KERNELPACKAGE installed into the nfsroot."
459        exit
460    }
461    
462    echo Creating FAI nfsroot can take a long time and will
463    echo need more than $nfssize disk space in $NFSROOT.
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      echo $NFSROOT already exists. Removing $NFSROOT
469      umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true      umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true
470      rm -rf $NFSROOT/.??* $NFSROOT/*      rm -rf $NFSROOT/.??* $NFSROOT/*
# Line 273  if [ -d $NFSROOT/fai ]; then Line 472  if [ -d $NFSROOT/fai ]; then
472      find $NFSROOT ! -type d -xdev -maxdepth 1 | xargs -r rm -f      find $NFSROOT ! -type d -xdev -maxdepth 1 | xargs -r rm -f
473  fi  fi
474    
475  create_nfsroot  # Create a new nfsroot
476    call_with_stamp create_nfsroot
477    
478  if [ -f $KERNELPACKAGE ]; then  kernel_install
     # create tftp boot images  
     install_kernel_nfsroot  
     mknbi-linux --verbose $NFSROOT/boot/vmlinuz-$KERNELVERSION /boot/fai/installimage  
     # imggen is free software from 3com  
     # it converts netboot image to images, that are bootable by 3com network cards  
     imggen=`which imggen || true`  
     if [ -x "$imggen" ]; then  
         imggen -a /boot/fai/installimage /boot/fai/installimage_3com  
     fi  
 else  
     echo "Kernel package $KERNELPACKAGE not found."  
     echo "No install kernel installed in /boot/fai."  
     echo "No kernel modules available in nfsroot."  
 fi  
479    
480  echo make-fai-nfsroot finished.  umount_dirs
481    trap "true" EXIT
482    echo "make-fai-nfsroot finished $merror."
483  exit 0  exit 0

Legend:
Removed from v.869  
changed lines
  Added in v.2474

  ViewVC Help
Powered by ViewVC 1.1.5