/[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

trunk/scripts/make-fai-nfsroot revision 1303 by lange, Fri Nov 22 14:19:50 2002 UTC trunk/bin/make-fai-nfsroot revision 3843 by lange, Mon Sep 4 17:05:56 2006 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-2002 by Thomas Lange, lange@informatik.uni-koeln.de  # (c) 2000-2006 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 Additional packages are  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31  # defined with $NFSROOT_PACKAGES in fai.conf  die() {
32  packages="portmap dhcp-client file rdate cfengine bootpc wget rsh-client less dump  
33  ext2resize strace hdparm parted dnsutils grub ntpdate psmisc      echo "$@"
34  dosfstools sysutils dialog libdetect0 discover mdetect read-edid kudzu hwtools"      exit 99
35    }
36    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
37    
38  PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin  PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin
39    
40  if [ `id -u` -ne 0 ]; then  if [ $(id -u) != "0" ]; then
41      echo "Run this program as root."      echo "Run this program as root."
42      exit 9      exit 9
43  fi  fi
44    
45  while getopts rv opt ; do  kfile="vmlinuz" # some architectures use different names
46    kernelname="$kfile-install"
47    merror="properly"
48    # option e currently does nothing
49    while getopts ervc:f:kKV: opt ; do
50      case "$opt" in      case "$opt" in
51          v) verbose=1 ;;          c) cfdir=$OPTARG ;;
52            v) verbose=1 ; v=-v ;;
53            V) kernelname=$OPTARG ;;
54          r) recover=1 ;;          r) recover=1 ;;
55            f) die "Option -f is not supported any more. Use option -c instead" ;;
56            k) kinstall=1 ;;
57            K) kremove=1; kinstall=1 ;;
58            e) expert=1 ;;
59            ?) exit 5 ;; # error in option parsing
60      esac      esac
61  done  done
62    
63  set -e  set -e
64  . /etc/fai/fai.conf  
65    [ -z "$cfdir" ] && cfdir=/etc/fai
66    if [ ! -d "$cfdir" ]; then
67        echo "$cfdir is not a directory"
68        exit 6
69    fi
70    [ "$verbose" ] && echo "Using configuration files from directory $cfdir"
71    . $cfdir/fai.conf
72    
73    # read config file for this tool
74    if [ -f "$cfdir/make-fai-nfsroot.conf" ]; then
75        . $cfdir/make-fai-nfsroot.conf
76    else
77        echo "Can't read $cfdir/make-fai-nfsroot.conf"
78        exit 8
79    fi
80    
81    [ -n "$packages" ] && die "WARNING: The use of \$packages in make-fai-nfsroot.conf is now deprecated. Please include this information into $cfdir/NFSROOT."
82    [ -n "$NFSROOT_PACKAGES" ] && die "WARNING: The use of \$NFSROOT_PACKAGES in make-fai-nfsroot.conf is now deprecated. Please include this information into $cfdir/NFSROOT."
83    
84    if [ -z "$NFSROOT" ]; then
85        echo "\$NFSROOT is not set. Please check your settings in $cfdir/fai.conf."
86        exit 4
87    fi
88    
89    if [ "$FAI_SOURCES_LIST" ]; then
90        echo "The usage of the variable \$FAI_SOURCES_LIST is deprecated. Please use sources.list now."
91        exit 3
92    fi
93    
94    if [ ! -d "$cfdir/apt" ]; then
95        echo "$cfdir/apt/ does not exists. Can't continue."
96        exit 7
97    fi
98    
99  ROOTCMD="chroot $NFSROOT"  ROOTCMD="chroot $NFSROOT"
100    
101  RUNDIR=/var/run/fai/make-nfs-root  RUNDIR=/var/run/fai/make-fai-nfsroot
102  [ ! -d $RUNDIR ] && mkdir -p $RUNDIR  [ ! -d $RUNDIR ] && mkdir -p $RUNDIR
 [ ! "$recover" ] && rm -rf $RUNDIR/*  
   
 LIBFAI=/usr/lib/fai  
 SHAREFAI=/usr/share/fai  
 conffile=$NFSROOT/etc/rcS_fai.conf  
103  export DEBIAN_FRONTEND=noninteractive  export DEBIAN_FRONTEND=noninteractive
104    [ "$recover" ] || rm -rf $RUNDIR/*
105    
106  trap "umount_dirs" EXIT  trap "umount_dirs" EXIT
107    trap "bad_exit" ERR
108  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
109  die() {  bad_exit() {
110    
111      echo "$@"      merror="with errors"
112      exit 99      echo "An error occured during make-fai-nfsroot."
113        echo "Please fix the error or try make-fai-nfsroot -v"
114  }  }
115  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
116  call_with_stamp() {  call_with_stamp() {
# Line 94  install_kernel_nfsroot() { Line 138  install_kernel_nfsroot() {
138      # since woody we can install the kernel using dpkg -i      # since woody we can install the kernel using dpkg -i
139      echo "do_boot_enable=no" > $NFSROOT/etc/kernel-img.conf      echo "do_boot_enable=no" > $NFSROOT/etc/kernel-img.conf
140      dpkg -x $KERNELPACKAGE $NFSROOT      dpkg -x $KERNELPACKAGE $NFSROOT
141      # change default root device of kernel image to /dev/nfs      echo "Kernel $KERNELVERSION installed into the nfsroot."
142      rdev $NFSROOT/boot/vmlinuz-$KERNELVERSION $NFSROOT/dev/boot255      chroot $NFSROOT depmod -qaF /boot/System.map-$KERNELVERSION $KERNELVERSION || true
     # if $NFROOT/proc/modules exists, then update-modules calls depmod -a without  
     # these special flags; so umount first  
     [ -e $NFSROOT/proc/modules ] && umount $NFSROOT/proc  
     chroot $NFSROOT update-modules  
     chroot $NFSROOT depmod -a -F /boot/System.map-$KERNELVERSION $KERNELVERSION  
143  }  }
144  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
145  setup_ssh() {  setup_ssh() {
146    
147      # nothing to do if no ssh is available in nfsroot      # nothing to do if no ssh is available in nfsroot
148      [ -f $NFSROOT/var/lib/dpkg/info/ssh.list ] || return 0      [ -f $NFSROOT/usr/bin/ssh ] || return 0
149      mkdir -p -m 700 $NFSROOT/root/.ssh      mkdir -p -m 700 $NFSROOT/root/.ssh
     [ -f /etc/ssh/ssh_known_hosts ] && cp /etc/ssh/ssh_known_hosts $NFSROOT/root/.ssh/known_hosts  
150      if [ -n "$LOGUSER" ] ; then      if [ -n "$LOGUSER" ] ; then
151          loguserhome=`eval "cd ~$LOGUSER 2>/dev/null && pwd;true"`          loguserhome=`eval "cd ~$LOGUSER 2>/dev/null && pwd;true"`
152      # is copying of *.pub important?      # is copying of *.pub important?
153            [ -f $loguserhome/.ssh/known_hosts ] && cp $loguserhome/.ssh/known_hosts $NFSROOT/root/.ssh/known_hosts
154          [ -d $loguserhome/.ssh ] && {          [ -d $loguserhome/.ssh ] && {
             [ -f $loguserhome/.ssh/identity ] &&  
                cp -p $loguserhome/.ssh/identity* $NFSROOT/root/.ssh/  
155              [ -f $loguserhome/.ssh/id_dsa ] &&              [ -f $loguserhome/.ssh/id_dsa ] &&
156                 cp -p $loguserhome/.ssh/id_dsa* $NFSROOT/root/.ssh/                 cp -p $loguserhome/.ssh/id_dsa* $NFSROOT/root/.ssh/
157              [ -f $loguserhome/.ssh/id_rsa ] &&              [ -f $loguserhome/.ssh/id_rsa ] &&
# Line 126  setup_ssh() { Line 163  setup_ssh() {
163      # enable root login      # enable root login
164      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
165      if [ -f "$SSH_IDENTITY" ]; then      if [ -f "$SSH_IDENTITY" ]; then
166          cp -p $SSH_IDENTITY $NFSROOT/root/.ssh/authorized_keys          cp $SSH_IDENTITY $NFSROOT/root/.ssh/authorized_keys
167            chmod 0644 $NFSROOT/root/.ssh/authorized_keys
168          echo You can log into install clients without password using $SSH_IDENTITY          echo You can log into install clients without password using $SSH_IDENTITY
169      fi      fi
170  }  }
# Line 134  setup_ssh() { Line 172  setup_ssh() {
172  copy_fai_files() {  copy_fai_files() {
173    
174      # copy to nfsroot      # copy to nfsroot
175      perl -pi -e "s#^root::#root:${FAI_ROOTPW}:#" etc/passwd      echo "root:$FAI_ROOTPW" | $ROOTCMD chpasswd --encrypted
     mkdir -p $NFSROOT/$FAI/fai_config $NFSROOT/$SHAREFAI $NFSROOT/$LIBFAI $NFSROOT/etc/fai  
176      cd $NFSROOT      cd $NFSROOT
177      cp -p $SHAREFAI/etc/dhclient.conf etc/      cp -Rpv $cfdir/* $NFSROOT/etc/fai
178      ln -fs ../sbin/dhclient-script etc/dhclient-script      # append additional variables to fai.conf for the install clients
179      cp -Rp /etc/fai etc/      [ -z "$FAI_CONFIG_SRC" ] && echo "FAI_CONFIG_SRC=nfs://`hostname`$FAI_CONFIGDIR" >> $NFSROOT/etc/fai/fai.conf
180      [ -f /etc/fai/.cvspass ] && cp -p /etc/fai/.cvspass .cvspass  
181      cp -p $LIBFAI/sbin/* sbin/      # remove some files that should not be copied
182      cp -p $LIBFAI/* usr/lib/fai || true  # cp will complain about directories      rm -f $NFSROOT/etc/fai/make-fai-nfsroot.conf
183      cp -p $SHAREFAI/etc/fai_modules_off etc/modutils/      [ -f $cfdir/.cvspass ] && cp -p $v $cfdir/.cvspass $NFSROOT/.cvspass
184        $ROOTCMD shadowconfig on
     cp -p $SHAREFAI/subroutines* usr/share/fai  
     cp -p $SHAREFAI/etc/apt.conf etc/apt  
     cp -p /usr/share/perl5/Debian/Fai.pm usr/share/perl5/Debian/  
     echo $NFSROOT_ETC_HOSTS >> etc/hosts  
185  }  }
186  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
187  call_debootstrap() {  call_debootstrap() {
188    
189      echo "Creating nfsroot for $1 using debootstrap"      local dversion=$(dpkg -l debootstrap | grep debootstrap | cut -f7 -d' ')
190      [ "$verbose" ] && echo "calling debootstrap $1 $NFSROOT $2"      echo "Creating base system using debootstrap version $dversion"
191      yes '' | debootstrap $FAI_DEBOOTSTRAP_OPTS $1 $NFSROOT $2 || true      echo "Calling debootstrap $1 $NFSROOT $2"
192        yes '' | LC_ALL=C call_verbose debootstrap $FAI_DEBOOTSTRAP_OPTS $1 $NFSROOT $2
193    }
194    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
195    add_all_host_entries() {
196    
197        local ips=$(ifconfig | grep -w inet | cut -d : -f 2 | cut -d ' ' -f 1 | grep -v 127.0.0.1)
198        for eth in $ips; do
199            getent hosts $eth >> etc/hosts
200        done
201  }  }
202  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
203  create_base() {  create_base() {
204    
205      if [ "$FAI_DEBOOTSTRAP" ]; then      if [ "$FAI_DEBOOTSTRAP" ]; then
206          call_verbose call_with_stamp call_debootstrap $FAI_DEBOOTSTRAP          call_with_stamp call_debootstrap $FAI_DEBOOTSTRAP
207          $ROOTCMD apt-get clean          $ROOTCMD apt-get clean
208            rm -f $NFSROOT/etc/resolv.conf
209          echo "Creating base.tgz"          echo "Creating base.tgz"
210          tar -l -C $NFSROOT -cf - . | gzip > $NFSROOT/../base.tgz          tar --one-file-system -C $NFSROOT -cf - --exclude var/tmp/base.tgz . | gzip > $NFSROOT/var/tmp/base.tgz
211          mv $NFSROOT/../base.tgz $NFSROOT/var/tmp/base.tgz          touch $NFSROOT/.THIS_IS_THE_FAI_NFSROOT
212      else      else
213          die "\$FAI_DEBOOTSTRAP not defined."          die "\$FAI_DEBOOTSTRAP not defined."
214      fi      fi
# Line 177  create_nfsroot() { Line 220  create_nfsroot() {
220      cd $NFSROOT || die "Error: Can't cd to $NFSROOT"      cd $NFSROOT || die "Error: Can't cd to $NFSROOT"
221    
222      call_with_stamp create_base      call_with_stamp create_base
223        # save the list of all packages in the base.tgz
224      [ ! -c dev/boot255 ] && mknod dev/boot255 c 0 255      $ROOTCMD dpkg --get-selections | egrep 'install$' | awk '{print $1}' > var/tmp/base-pkgs.lis
225    
226      if [ "$FAI_DEBMIRROR" ]; then      if [ "$FAI_DEBMIRROR" ]; then
227            [ "$verbose" ] && echo "Mounting $FAI_DEBMIRROR to $NFSROOT/$MNTPOINT."
228          mkdir -p $NFSROOT/$MNTPOINT          mkdir -p $NFSROOT/$MNTPOINT
229          mount -o ro,noatime,rsize=8192 $FAI_DEBMIRROR $NFSROOT/$MNTPOINT || \          mount -o ro,noatime,rsize=8192 $FAI_DEBMIRROR $NFSROOT/$MNTPOINT || \
230                  die "Can't mount $FAI_DEBMIRROR"                  die "Can't mount $FAI_DEBMIRROR to $NFSROOT/$MNTPOINT."
231          fi          fi
232    
233      # hoaks some packages      # hoaks some packages
# Line 192  create_nfsroot() { Line 236  create_nfsroot() {
236      > etc/raidtab      > etc/raidtab
237      mkdir -p lib/modules/$KERNELVERSION           # dirty trick to hoax lvm      mkdir -p lib/modules/$KERNELVERSION           # dirty trick to hoax lvm
238      >  lib/modules/$KERNELVERSION/modules.dep  # dirty trick to hoax lvm      >  lib/modules/$KERNELVERSION/modules.dep  # dirty trick to hoax lvm
     mkdir -p etc/ssh  
239      echo 'NTPSERVERS=""' > etc/default/ntp-servers      echo 'NTPSERVERS=""' > etc/default/ntp-servers
240    
241      # woody uses debconf      [ -d $NFSROOT/var/state ] || mkdir $NFSROOT/var/state
242        cp -a $cfdir/apt $NFSROOT/etc
243    
244      if [ "$FAI_SOURCES_LIST" ]; then      egrep -q "127.0.0.1" etc/hosts 2>/dev/null || echo "127.0.0.1 localhost" >> etc/hosts
245          echo "$FAI_SOURCES_LIST" > etc/apt/sources.list      egrep -q "$NFSROOT_ETC_HOSTS" etc/hosts 2>/dev/null || echo "$NFSROOT_ETC_HOSTS" >> etc/hosts
246      else      add_all_host_entries
247          cp /etc/apt/sources.list etc/apt/sources.list  
248      fi      # we need these option before installing the first package. So we
249      [ -f /etc/apt/preferences ] && cp /etc/apt/preferences etc/apt      # can't put this into fai-nfsroot /etc/apt/apt.conf.d/90fai
250        cat <<EOF >$NFSROOT/etc/apt/apt.conf.d/10fai
251    APT::Get::AllowUnauthenticated "true";
252    Aptitude::CmdLine::Ignore-Trust-Violations yes;
253    EOF
254      echo "Upgrading $NFSROOT"      echo "Upgrading $NFSROOT"
255      call_verbose call_with_stamp upgrade_nfsroot      LC_ALL=C call_verbose call_with_stamp upgrade_nfsroot
256      echo "Adding additional packages to $NFSROOT:"      LC_ALL=C call_with_stamp add_packages_nfsroot
     echo "$packages"  
     call_verbose call_with_stamp add_packages_nfsroot  
257      call_with_stamp copy_fai_files      call_with_stamp copy_fai_files
258    
259      # set timezone      # set timezone in nfsroot
260      rm -f etc/localtime      timezone=$(readlink /etc/localtime | sed 's%^/usr/share/zoneinfo/%%')
261      cp -d /etc/localtime /etc/timezone etc      echo $timezone > etc/timezone
262        rm -f etc/localtime && ln -sf /usr/share/zoneinfo/$timezone etc/localtime
263    
264      # make little changes to nfsroot, because nfsroot is      # make little changes to nfsroot, because nfsroot is
265      # read only for the install clients      # read only for the install clients
266      rm -rf etc/mtab var/run etc/sysconfig      rm etc/mtab
     mv etc/init.d/rcS etc/init.d/rcS.orig  
267      ln -s /proc/mounts etc/mtab      ln -s /proc/mounts etc/mtab
268      ln -s /tmp/var/run var/run      [ -d "var/lib/discover" ] || mkdir var/lib/discover
269        mkdir etc/sysconfig tmp/etc
270        cp -p /etc/resolv.conf tmp/etc # so we have DNS after chroot $NFSROOT on the install server
271      ln -sf /tmp/etc/resolv.conf etc/resolv.conf      ln -sf /tmp/etc/resolv.conf etc/resolv.conf
272      ln -sf /tmp etc/sysconfig      ln -s /usr/sbin/fai etc/init.d/rcS
     ln -s ../../sbin/rcS_fai etc/init.d/rcS  
     ln -s /dev/null etc/network/ifstate  
273      # for nis      # for nis
274      [ -d var/yp ] && ln -s /tmp/binding var/yp/binding      [ -d var/yp ] && ln -s /tmp/binding var/yp/binding
275    
     # turn off logging of loading kernel modules  
     [ -d var/log/ksymoops/ ] && rmdir var/log/ksymoops/  
     ln -s /dev/null var/log/ksymoops  
   
276      # definition for loopback device      # definition for loopback device
277      echo "iface lo inet loopback" > etc/network/interfaces      echo "iface lo inet loopback" > etc/network/interfaces
278    
279      echo "*.* /tmp/syslog.log" > etc/syslog.conf      echo "*.* /tmp/fai/syslog.log" > etc/syslog.conf
280      cat >> root/.profile <<-EOF      cat >> root/.profile <<-EOF
281          . $SHAREFAI/subroutines          PATH=/usr/local/sbin:/usr/local/bin:/usr/lib/fai:/bin:/sbin:/usr/bin:/usr/sbin:
282          . $SHAREFAI/subroutines-$OS_TYPE          export PATH
283            . /usr/lib/fai/subroutines
284            . /usr/lib/fai/subroutines-linux
285          set -a          set -a
286          . /etc/fai/fai.conf          . /tmp/fai/variables.sh 2>/dev/null
         . /tmp/rcsfai.var  
287  EOF  EOF
288    
289      call_verbose call_with_stamp setup_ssh      call_verbose call_with_stamp setup_ssh
# Line 256  EOF Line 299  EOF
299          reboot -dfi          reboot -dfi
300  EOF  EOF
301      chmod a+rx $NFSROOT/etc/rc2.d/S01fai_abort      chmod a+rx $NFSROOT/etc/rc2.d/S01fai_abort
302    
303        # IMO this may be removed, since all information should be included into sources.list
304        [ -n "$FAI_LOCAL_REPOSITORY" ] && echo "WARNING: The use of \$FAI_LOCAL_REPOSITORY is now deprecated. Please include this information into sources.list." || true
305  }  }
306  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
307  upgrade_nfsroot() {  upgrade_nfsroot() {
308    
309      cp /etc/resolv.conf $NFSROOT/etc      if [ -f /etc/resolv.conf ]; then
310            cp -p $v /etc/resolv.conf $NFSROOT/etc/resolv.conf-installserver
311            cp -p $v /etc/resolv.conf $NFSROOT/etc/resolv.conf # this is needed during make-fai-nfsroot
312        fi
313      $ROOTCMD apt-get update      $ROOTCMD apt-get update
314        $ROOTCMD apt-get -fyu install
315      $ROOTCMD apt-get check      $ROOTCMD apt-get check
316      rm -rf $NFSROOT/etc/apm      rm -rf $NFSROOT/etc/apm
317      mount -t proc /proc $NFSROOT/proc      mount -t proc /proc $NFSROOT/proc
     $ROOTCMD apt-get --purge -y install debconf </dev/null  
318    
319      # fake start-stop-dameon      fdivert /sbin/start-stop-daemon /sbin/discover-modprobe
320      $ROOTCMD dpkg-divert --quiet --package fai --add --rename /sbin/start-stop-daemon      cp -p /sbin/fai-start-stop-daemon $NFSROOT/sbin/start-stop-daemon
321      cp $LIBFAI/sbin/start-stop-daemon $NFSROOT/sbin      $ROOTCMD apt-get -y dist-upgrade
     $ROOTCMD apt-get -y upgrade  
322  }  }
323  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
324  add_packages_nfsroot() {  add_packages_nfsroot() {
325    
326      $ROOTCMD apt-get -y --fix-missing install $packages </dev/null      local iarch=$(dpkg --print-installation-architecture|tr /a-z/ /A-Z/)
327      if [ -n "$NFSROOT_PACKAGES" ] ; then      export FAI_ROOT=$NFSROOT
328          $ROOTCMD apt-get -y --fix-missing install $NFSROOT_PACKAGES </dev/null      export classes="NFSROOT $iarch"
329      fi      install_packages -l -p/etc/fai > $NFSROOT/var/tmp/packages.nfsroot
330      $ROOTCMD apt-get clean      echo "Adding additional packages to $NFSROOT:"
331        cat $NFSROOT/var/tmp/packages.nfsroot
332        call_verbose install_packages $v -p/etc/fai
333  }  }
334  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
335  umount_dirs() {  umount_dirs() {
336    
337        [ -f $NFSROOT/usr/sbin/dpkg-divert ] &&
338           LC_ALL=C $ROOTCMD dpkg-divert --rename --remove /sbin/discover-modprobe
339      cd /      cd /
340      sleep 2      sleep 2
341      umount $NFSROOT/proc 1>/dev/null 2>&1 || true      [ -d $NFSROOT/proc/self ] && umount $NFSROOT/proc
342      umount $NFSROOT/dev/pts 1>/dev/null 2>&1 ||true      [ -d $NFSROOT/proc/self ] && umount $NFSROOT/dev/pts
343      if [ "$FAI_DEBMIRROR" ]; then      if [ "$FAI_DEBMIRROR" ]; then
344          test -d $NFSROOT/$MNTPOINT && umount $NFSROOT/$MNTPOINT || true          test -d $NFSROOT/$MNTPOINT && umount $NFSROOT/$MNTPOINT || true
345      fi      fi
# Line 298  umount_dirs() { Line 350  umount_dirs() {
350  get_kernel_version() {  get_kernel_version() {
351    
352      local package=$1      local package=$1
353      KERNELVERSION=`dpkg --info $1 | grep "Package: kernel-image" | sed -e 's/.*kernel-image-'//`  
354        KERNELVERSION=`dpkg --info $package | grep ' Package: '`
355        KERNELVERSION=${KERNELVERSION/*-image-/}
356  }  }
357  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
358  setup_bootp(){  setup_bootp(){
359    
360      if [ -x "`which mknbi-linux`" ]; then      if [ -x "`which mkelf-linux`" ]; then
361          mknbi-linux --verbose -d /dev/nfs -i rom -a nfsroot=rom \          mkelf-linux --ip=any --output=/srv/tftp/fai/installimage \
362            $NFSROOT/boot/vmlinuz-$KERNELVERSION /boot/fai/installimage            $NFSROOT/boot/$kfile-$KERNELVERSION
363      else      else
364          die "Command mknbi-linux not found. Please install the package netboot"          echo "Command mkelf-linux not found. Can not set up BOOTP booting. Please install the package mknbi and rerun fai-setup."
365            return
366      fi      fi
367    
368      # imggen is free software from 3com - use ver1.00: 1.01 produces "Image too Big" errors.      # imggen is free software from 3com - use ver1.00: 1.01 produces "Image too Big" errors.
369      # it converts netboot images to images which are bootable by 3com network cards      # it converts netboot images to images which are bootable by 3com network cards
370      if [ -x "`which imggen`" ]; then      if [ -x "`which imggen`" ]; then
371          imggen -a /boot/fai/installimage /boot/fai/installimage_3com          imggen -a /srv/tftp/fai/installimage /srv/tftp/fai/installimage_3com
372      fi      fi
373      echo "BOOTP environment prepared."      echo "BOOTP environment prepared."
374  }  }
# Line 323  setup_dhcp(){ Line 378  setup_dhcp(){
378    
379      # pxe and dhcp environment      # pxe and dhcp environment
380      local pxebin=/usr/lib/syslinux/pxelinux.0      local pxebin=/usr/lib/syslinux/pxelinux.0
381      cp -p $NFSROOT/boot/vmlinuz-$KERNELVERSION /boot/fai/installkernel      cp -p $NFSROOT/boot/$kfile-$KERNELVERSION /srv/tftp/fai/$kernelname
382      [ -f $pxebin ] && cp $pxebin /boot/fai      echo "Kernel $KERNELVERSION copied to /srv/tftp/fai/$kernelname"
383      [ -d /boot/fai/pxelinux.cfg ] || mkdir /boot/fai/pxelinux.cfg || true      [ -f $pxebin ] && cp $pxebin /srv/tftp/fai
384      cp -p /usr/share/fai/etc/pxelinux.cfg /boot/fai/pxelinux.cfg/default      [ -d /srv/tftp/fai/pxelinux.cfg ] || mkdir -p /srv/tftp/fai/pxelinux.cfg
385      echo "DHCP environment prepared. Now enable dhcpd and the special tftp daemon"      echo "DHCP environment prepared. If you want to use it, you have to enable the dhcpd and the tftp-hpa daemon."
386    }
387    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
388    fdivert() {
389    
390        local item
391        for item in "$@"; do
392            LC_ALL=C $ROOTCMD dpkg-divert --quiet --add --rename $item
393        done
394    }
395    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
396    kernel_install() {
397    
398    # Install the kernel package
399    if [ -f $KERNELPACKAGE ]; then
400        # determine kernel version
401        get_kernel_version $KERNELPACKAGE
402    
403        # create tftp boot images
404        call_with_stamp install_kernel_nfsroot
405    
406        # setup for DHCP, BOOTP or both
407        [ "x$FAI_BOOT" = "x" ] && FAI_BOOT="dhcp bootp"
408    
409        for bootopt in $FAI_BOOT; do
410            case $bootopt in
411                    dhcp|DHCP)
412                            call_with_stamp setup_dhcp ;;
413                    bootp|BOOTP)
414                            call_with_stamp setup_bootp ;;
415                    *)
416                            echo "Unknown boot option" ;;
417            esac
418        done
419    else
420        merror="with errors"
421        echo "Error. Kernel package $KERNELPACKAGE not found."
422        echo "No install kernel installed in /srv/tftp/fai."
423        echo "No kernel modules available in nfsroot."
424    fi
425  }  }
426  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
427  # main routine  # main routine
428    
429    [ -z "$KERNELPACKAGE" ] && die "\$KERNELPACKAGE is not set. Aborting."
430    
431    # remove all kernels from nfsroot
432    [ -n "$kremove" ] && {
433        echo "Removing all kernels from NFSROOT."
434        rm -f $NFSROOT/boot/{System.map,vmlinuz,config,patches}*
435        rm -rf $NFSROOT/lib/modules/2.*
436    }
437    
438    # just install a new kernel to the nfsroot
439    [ -n "$kinstall" ] && {
440        trap "true" EXIT
441        echo "Installing new kernel into the nfsroot."
442        kernel_install
443        echo "New kernel from" $KERNELPACKAGE "installed into the nfsroot."
444        exit
445    }
446    
447    echo "Creating FAI nfsroot in $NFSROOT."
448    echo "By default it needs more than 250 MBytes disk space."
449    echo "This may take a long time."
450    
451  # Kill the directory if not in recover mode  # Kill the directory if not in recover mode
452  if [ -d $NFSROOT/$FAI -a ! "$recover" ]  if [ -d $NFSROOT/$FAI -a ! "$recover" ]
453  then  then
# Line 339  then Line 455  then
455      umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true      umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true
456      rm -rf $NFSROOT/.??* $NFSROOT/*      rm -rf $NFSROOT/.??* $NFSROOT/*
457      # also remove files $NFSROOT/.? but not . and ..      # also remove files $NFSROOT/.? but not . and ..
458      find $NFSROOT ! -type d -xdev -maxdepth 1 | xargs -r rm -f      find $NFSROOT -xdev -maxdepth 1 ! -type d | xargs -r rm -f
459  fi  fi
460    
461  # Create a new nfsroot  # Create a new nfsroot
462    if [ ! -x "`which debootstrap`" ]; then
463        die "Can't find debootstrap command. Aborting."
464    fi
465  call_with_stamp create_nfsroot  call_with_stamp create_nfsroot
466    
467  # Install the kernel package  kernel_install
 if [ -f $KERNELPACKAGE ]; then  
     # determine kernel version  
     get_kernel_version $KERNELPACKAGE  
   
     # create tftp boot images  
     call_with_stamp install_kernel_nfsroot  
   
     grep -q _dhcp_ $NFSROOT/boot/System.map-$KERNELVERSION && TYPE=DHCP  
     # only BOOTP need a netboot image, DHCP can do with raw kernels  
     if [ "$TYPE" = DHCP ]; then  
         call_with_stamp setup_dhcp  
     else  
         call_with_stamp setup_bootp  
     fi  
 else  
     echo "Kernel package $KERNELPACKAGE not found."  
     echo "No install kernel installed in /boot/fai."  
     echo "No kernel modules available in nfsroot."  
 fi  
468    
469  echo make-fai-nfsroot finished.  umount_dirs
470    trap "true" EXIT
471    echo "make-fai-nfsroot finished $merror."
472  exit 0  exit 0

Legend:
Removed from v.1303  
changed lines
  Added in v.3843

  ViewVC Help
Powered by ViewVC 1.1.5