/[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 869 by lange, Mon Oct 29 15:52:44 2001 UTC trunk/bin/make-fai-nfsroot revision 4750 by lange, Thu Nov 15 17:17:36 2007 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-2007 by Thomas Lange, lange@informatik.uni-koeln.de
10  # Universitaet zu Koeln  # Universitaet zu Koeln
11  #  #
12  #*********************************************************************  #*********************************************************************
# Line 24  Line 24 
24  # `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution  # `/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  # 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.,  # can also obtain it by writing to the Free Software Foundation, Inc.,
27  # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
28  #*********************************************************************  #*********************************************************************
29    
30  # Packages that are install to nfsroot by default  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31  # Additional packages are defined with $NFSROOT_PACKAGES in fai.conf  usage() {
32  packages="dhcp-client file rdate cfengine bootpc wget rsh-client less dump ext2resize strace hdparm parted dnsutils grub ntpdate psmisc hwtools dosfstools"  
33        cat <<-EOF
34  PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin          Copyright (C) 1999-2007 Thomas Lange
35            Report bugs to <fai@informatik.uni-koeln.de>.
36  if [ "$UID" -ne 0 ]; then  
37   echo "Run this program as root."          Usage: make-fai-nfsroot [OPTIONS]
38   exit 9    Create an NFSROOT for FAI.
39            Read the man pages pages make-fai-nfsroot(8).
40    EOF
41        exit 0
42    }
43    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
44    die() {
45    
46        echo "ERROR: $@"
47        exit 99
48    }
49    
50    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
51    check_nfsroot() {
52    
53        set +e
54        # simple test, to see if important thing are available inside the nfsroot
55        [ -d $NFSROOT/usr/share/live-initramfs ] || die "live-initramfs is not installed."
56        local files=$(ls $NFSROOT/boot/initrd* 2>/dev/null)
57        [ -z "$files" ] && die "No initrd installed."
58        return 0
59    }
60    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
61    badupdateto32() {
62    
63        cat <<-EOF
64            It seems that you have updated an older FAI version without checking files in /etc/fai/
65            Please check the NEWS file for changes in variable names and if you have a linux-image package
66            defined in /etc/fai/NFSROOT.
67    EOF
68        die $@
69    }
70    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
71    
72    PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin
73    
74    kfile="vmlinuz" # some architectures use different names
75    merror="properly"
76    sshpreserve=0
77    divert=1
78    
79    if [ -f /etc/lsb-release ]; then
80        . /etc/lsb-release
81        case "$DISTRIB_ID" in
82            Ubuntu) divert=0 ;;
83        esac
84  fi  fi
85    
86  while getopts v opt ; do  # option e currently does nothing
87          case "$opt" in  while getopts hervC:f:kKpU opt ; do
88          v) verbose=1 ;;      case "$opt" in
89          esac          C) cfdir=$OPTARG ;;
90            v) verbose=1 ; v=-v ;;
91            r) recover=1 ;;
92            f) die "Option -f is not supported any more. Use option -C instead" ;;
93            k) kinstall=1 ;;
94            K) kremove=1;;
95            h) usage ;;
96            e) expert=1 ;; # a dummy option, that only fai-setup uses
97            p) sshpreserve=1 ;;
98            U) divert=0 ;;
99            ?) exit 5 ;; # error in option parsing
100        esac
101  done  done
102    
103    if [ $(id -u) != "0" ]; then
104        echo "Run this program as root."
105        exit 9
106    fi
107    
108    { # start of block which output will be written to log file
109    
110  set -e  set -e
 . /etc/fai.conf  
 packages="$packages $NFSROOT_PACKAGES"  
 ROOTCMD="chroot $NFSROOT"  
111    
112  LIBFAI=/usr/lib/fai  # use FAI_ETC_DIR from environment variable
113  conffile=$NFSROOT/etc/rcS_fai.conf  if [ -n "$FAI_ETC_DIR" -a -z "$cfdir" ]; then
114  export DEBIAN_FRONTEND=Noninteractive      echo "Using environment variable \$FAI_ETC_DIR."
115    fi
116    [ -z "$cfdir" ] && cfdir=${FAI_ETC_DIR:=/etc/fai}
117    cfdir=$(readlink -f $cfdir) # canonicalize path
118    if [ ! -d "$cfdir" ]; then
119        echo "$cfdir is not a directory"
120        exit 6
121    fi
122    [ "$verbose" ] && echo "Using configuration files from $cfdir"
123    . $cfdir/fai.conf
124    
125  if [ "$verbose" ]; then  # read config file for this tool
126          devnull=/dev/tty  if [ -f "$cfdir/make-fai-nfsroot.conf" ]; then
127        . $cfdir/make-fai-nfsroot.conf
128  else  else
129          devnull=/dev/null      echo "Can't read $cfdir/make-fai-nfsroot.conf"
130        exit 8
131  fi  fi
132    
133  trap "umount_dirs" EXIT  # IMO this may be removed, since all information should be included into sources.list
134    [ -n "$FAI_LOCAL_REPOSITORY" ] && die "The use of \$FAI_LOCAL_REPOSITORY is now deprecated. Please include this information into sources.list."
135    [ -n "$packages" ] && badupdateto32 "The use of \$packages in make-fai-nfsroot.conf is now deprecated. Please include this information into $cfdir/NFSROOT."
136    [ -n "$NFSROOT_PACKAGES" ] && die "The use of \$NFSROOT_PACKAGES in make-fai-nfsroot.conf is now deprecated. Please include this information into $cfdir/NFSROOT."
137    [ -n "$FAI_SOURCES_LIST" ] && die "The use of \$FAI_SOURCES_LIST is deprecated. Please use sources.list now."
138    
139    [ -z "$NFSROOT" ] && die "\$NFSROOT is not set. Please check your settings in $cfdir/fai.conf."
140    [ -z "$TFTPROOT" ] && badupdateto32 "\$TFTPROOT is not set. Please check your settings in $cfdir/make-fai-nfsroot.conf."
141    [ -n "$KERNELPACKAGE" ] && badupdateto32 "The use of \$KERNELPACKAGE is deprecated. Please use $cfdir/NFSROOT now."
142    [ ! -d "$cfdir/apt" ] && die "$cfdir/apt/ does not exists. Can't continue."
143    
144    oldnfsroot=$NFSROOT
145    NFSROOT="$NFSROOT/live/filesystem.dir"
146    ROOTCMD="chroot $NFSROOT"
147    
148    RUNDIR=/var/run/fai/make-fai-nfsroot
149    mkdir -p $RUNDIR
150    export DEBIAN_FRONTEND=noninteractive
151    [ "$recover" ] || rm -rf $RUNDIR/*
152    
153    trap 'echo "Aborting";umount_dirs' EXIT
154    trap "bad_exit" ERR
155    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
156    bad_exit() {
157    
158        merror="with errors"
159        echo "An error occured during make-fai-nfsroot."
160        echo "Please fix the error or try make-fai-nfsroot -v"
161    }
162  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
163  die() {  call_with_stamp() {
164    
165      echo $*      local func=$1
166      exit 99      local stamp=$RUNDIR/$func
167        # call subroutine
168        [ "$recover" -a -f $stamp ] && return 0
169        # make a stamp only on success.
170        "$@" && : > $stamp
171    }
172    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
173    call_verbose() {
174    
175        if [ "$verbose" ]; then
176            "$@"
177            return $?
178        else
179            "$@" > /dev/null
180            return $?
181        fi
182  }  }
183  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
184  install_kernel_nfsroot() {  install_kernel_nfsroot() {
185    
186      rm -rf $NFSROOT/boot/*-$KERNELVERSION $NFSROOT/lib/modules/$KERNELVERSION      if [ $divert = 1 ]; then
187      dpkg -x $KERNELPACKAGE $NFSROOT          rm $NFSROOT/usr/sbin/update-initramfs
188      # if $NFROOT/proc/modules exists, then update-modules calls depmod -a without          LC_ALL=C $ROOTCMD dpkg-divert --rename --remove /usr/sbin/update-initramfs
189      # these special flags; so umount first          $ROOTCMD update-initramfs -k all -t -u
190      umount $NFSROOT/proc      fi
     chroot $NFSROOT update-modules  
     chroot $NFSROOT depmod -a -F /boot/System.map-$KERNELVERSION $KERNELVERSION  
191  }  }
192  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
193  setup_ssh() {  setup_ssh() {
194    
195      # nothing to do if no ssh is available in nfsroot      # nothing to do if no ssh is available in nfsroot
196      [ -f $NFSROOT/var/lib/dpkg/info/ssh.list ] || return 0      [ -f $NFSROOT/usr/bin/ssh ] || return 0
197        if [ $sshpreserve = 1 ]; then
198            tar -C $NFSROOT -xf $tmptar
199            rm $tmptar
200            return 0
201        fi
202    
203      mkdir -p -m 700 $NFSROOT/root/.ssh      mkdir -p -m 700 $NFSROOT/root/.ssh
204      [ -f /etc/ssh/ssh_known_hosts ] && cp /etc/ssh/ssh_known_hosts $NFSROOT/root/.ssh/known_hosts      if [ -n "$LOGUSER" ] ; then
205      loguserhome=`eval "cd ~$LOGUSER 2>/dev/null && pwd;true"`          loguserhome=$(eval "cd ~$LOGUSER 2>/dev/null && pwd;true")
206      [ -d $loguserhome/.ssh ] && cp -p $loguserhome/.ssh/identity* $NFSROOT/root/.ssh/          [ -f $loguserhome/.ssh/known_hosts ] && cp $loguserhome/.ssh/known_hosts $NFSROOT/root/.ssh/known_hosts
207            [ -d $loguserhome/.ssh ] && {
208                [ -f $loguserhome/.ssh/id_dsa ] &&
209                   cp -p $loguserhome/.ssh/id_dsa* $NFSROOT/root/.ssh/
210                [ -f $loguserhome/.ssh/id_rsa ] &&
211                   cp -p $loguserhome/.ssh/id_rsa* $NFSROOT/root/.ssh/
212            }
213        fi
214    
215      # enable root login      # enable root login
216      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
217      if [ -f "$SSH_IDENTITY" ]; then      if [ -f "$SSH_IDENTITY" ]; then
218          cp -p $SSH_IDENTITY $NFSROOT/root/.ssh/authorized_keys          cp $SSH_IDENTITY $NFSROOT/root/.ssh/authorized_keys
219          echo You can log into install clients without password using $SSH_IDENTITY          chmod 0644 $NFSROOT/root/.ssh/authorized_keys
220            echo You can log into install clients without password using $SSH_IDENTITY
221      fi      fi
222  }  }
223  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
224  copy_fai_files() {  copy_fai_files() {
225    
226      # copy to nfsroot      # copy to nfsroot
227      perl -pi -e "s/^root::/root:${FAI_ROOTPW}:/" etc/passwd      echo "root:$FAI_ROOTPW" | $ROOTCMD chpasswd --encrypted
228      mkdir -p $NFSROOT/fai/fai_config $NFSROOT/usr/share/fai      cp -Rpv $cfdir/* $NFSROOT/etc/fai
229      cd $NFSROOT      # append additional variables to fai.conf for the install clients
230      cp -p $LIBFAI/sbin/dhclient-script $LIBFAI/etc/dhclient.conf /etc/fai.conf etc      [ -z "$FAI_CONFIG_SRC" ] && echo "FAI_CONFIG_SRC=nfs://`hostname`$FAI_CONFIGDIR" >> $NFSROOT/etc/fai/fai.conf
231      cp -p $LIBFAI/sbin/* sbin  
232      cp -p $LIBFAI/etc/fai_modules_off etc/modutils      # remove some files that should not be copied
233        rm -f $NFSROOT/etc/fai/make-fai-nfsroot.conf
234      cp -p /usr/share/fai/subroutines usr/share/fai      [ -f $cfdir/.cvspass ] && cp -p $v $cfdir/.cvspass $NFSROOT/.cvspass
235      cp -p $LIBFAI/etc/apt.conf etc/apt      $ROOTCMD shadowconfig on
     cp -p /usr/lib/perl5/Debian/Fai.pm usr/lib/perl5/Debian/  
     echo $NFSROOT_ETC_HOSTS >> etc/hosts  
236  }  }
237  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
238  call_debootstrap() {  call_debootstrap() {
239    
240        local dversion=$(dpkg -l debootstrap | grep debootstrap | cut -f7 -d' ')
241        echo "Creating base system using debootstrap version $dversion"
242        echo "Calling debootstrap $1 $NFSROOT $2"
243        yes '' | LC_ALL=C call_verbose debootstrap $FAI_DEBOOTSTRAP_OPTS $1 $NFSROOT $2
244    }
245    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
246    add_all_host_entries() {
247    
248      echo "Creating nfsroot for $1 using debootstrap"      local ips=$(ifconfig | grep -w inet | cut -d : -f 2 | cut -d ' ' -f 1 | grep -v 127.0.0.1)
249      [ "$verbose" ] && echo "calling debootstrap $1 $NFSROOT $2"      for eth in $ips; do
250      LC_ALL=C debootstrap $1 $NFSROOT $2 > $devnull 2>&1          getent hosts $eth >> etc/hosts || true
251        done
252  }  }
253  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
254  create_base() {  create_base() {
255    
256      if [ "$FAI_DEBOOTSTRAP" ]; then      if [ "$FAI_DEBOOTSTRAP" ]; then
257          call_debootstrap $FAI_DEBOOTSTRAP          call_with_stamp call_debootstrap $FAI_DEBOOTSTRAP
258          echo "Creating base.tgz"          $ROOTCMD apt-get clean
259          tar -C $NFSROOT -cf - . | gzip > $NFSROOT/../base.tgz          rm -f $NFSROOT/etc/resolv.conf
260          mv $NFSROOT/../base.tgz $NFSROOT/var/tmp/base.tgz          echo "Creating base.tgz"
261            tar --one-file-system -C $NFSROOT -cf - --exclude var/tmp/base.tgz . | gzip > $NFSROOT/var/tmp/base.tgz
262            touch $NFSROOT/.THIS_IS_THE_FAI_NFSROOT
263      else      else
264          # 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  
265      fi      fi
266  }  }
267  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
268  create_nfsroot() {  create_nfsroot() {
269    
270      mkdir -p $NFSROOT/fai      mkdir -p $NFSROOT/$FAI
271      cd $NFSROOT || die "Error: Can't cd to $NFSROOT"      cd $NFSROOT || die "Can't cd to $NFSROOT"
272      create_base  
273      mknod dev/boot255 c 0 255      call_with_stamp create_base
274        # save the list of all packages in the base.tgz
275        $ROOTCMD dpkg --get-selections | egrep 'install$' | awk '{print $1}' > var/tmp/base-pkgs.lis
276    
277      if [ "$FAI_DEBMIRROR" ]; then      if [ "$FAI_DEBMIRROR" ]; then
278          mkdir -p $NFSROOT/$MNTPOINT          [ "$verbose" ] && echo "Mounting $FAI_DEBMIRROR to $NFSROOT/$MNTPOINT."
279          mount -o ro,rsize=8192 $FAI_DEBMIRROR $NFSROOT/$MNTPOINT || die "Can't mount $FAI_DEBMIRROR"          mkdir -p $NFSROOT/$MNTPOINT
280      fi          mount -o ro,noatime,rsize=8192 $FAI_DEBMIRROR $NFSROOT/$MNTPOINT || \
281                    die "Can't mount $FAI_DEBMIRROR to $NFSROOT/$MNTPOINT."
282            fi
283    
284      # hoaks some packages      # hoaks some packages
285      > etc/fstab # dump and raidtool2 needs these files      # liloconfig, dump and raidtool2 needs these files
286        echo "# UNCONFIGURED FSTAB FOR BASE SYSTEM" > etc/fstab
287      > etc/raidtab      > etc/raidtab
288      mkdir -p lib/modules/$KERNELVERSION           # dirty trick to hoax lvm      echo 'NTPSERVERS=""' > etc/default/ntp-servers
     >  lib/modules/$KERNELVERSION/modules.dep  # dirty trick to hoax lvm  
     mkdir -p etc/ssh  
     > etc/ssh/NOSERVER  
289    
290      if [ "$FAI_SOURCES_LIST" ]; then      # live.conf will set hostname to debian
291          echo "$FAI_SOURCES_LIST" > etc/apt/sources.list      if [ -f $cfdir/live.conf ]; then
292            cp -p $cfdir/live.conf etc/live.conf
293      else      else
294          cp /etc/apt/sources.list etc/apt/sources.list          cat >> etc/live.conf <<EOF
295    # UNIONTYPE=aufs # if unionfs is broken
296    NOUSER="Yes"
297    NOHOSTS="Yes"
298    export UNIONTYPE NOHOSTS NOUSER
299    EOF
300      fi      fi
301      upgrade_nfsroot  
302      copy_fai_files      cp -a $cfdir/apt $NFSROOT/etc
303    
304      # set timezone      ainsl -as $NFSROOT/etc/hosts "127.0.0.1 localhost"
305      rm -f etc/localtime      ainsl     $NFSROOT/etc/hosts "$NFSROOT_ETC_HOSTS"
306      cp -d /etc/localtime /etc/timezone etc      add_all_host_entries
307    
308      # make little changes to nfsroot, because nfsroot is      # we need these option before installing the first package. So we
309      # read only for the install clients      # can't put this into fai-nfsroot /etc/apt/apt.conf.d/90fai
310      rm -rf etc/mtab var/run      cat <<EOF >$NFSROOT/etc/apt/apt.conf.d/10fai
311      mv etc/init.d/rcS etc/init.d/rcS.orig  APT::Get::AllowUnauthenticated "true";
312      ln -s /proc/mounts etc/mtab  Aptitude::CmdLine::Ignore-Trust-Violations yes;
313      ln -s /tmp/var/run var/run  EOF
314      ln -sf /tmp/etc/resolv.conf etc/resolv.conf      echo "Upgrading $NFSROOT"
315      ln -s /sbin/rcS_fai etc/init.d/rcS      LC_ALL=C call_verbose call_with_stamp upgrade_nfsroot
316      # for nis      LC_ALL=C call_with_stamp add_packages_nfsroot
317      [ -d var/yp ] && ln -s /tmp/binding var/yp/binding      call_with_stamp copy_fai_files
318    
319        # set timezone in nfsroot
320        timezone=$(readlink /etc/localtime | sed 's%^/usr/share/zoneinfo/%%')
321        echo $timezone > etc/timezone
322        rm -f etc/localtime && ln -sf /usr/share/zoneinfo/$timezone etc/localtime
323    
324      # turn off logging of loading kernel modules      rm etc/mtab && ln -s /proc/mounts etc/mtab
325      [ -d var/log/ksymoops/ ] && rmdir var/log/ksymoops/      ln -s /usr/sbin/fai etc/init.d/rcS
326      ln -s /dev/null var/log/ksymoops      # for nis
327    #    [ -d var/yp ] && ln -s /tmp/binding var/yp/binding
328    
329      # definition for loopback device      # definition for loopback device
330      echo "iface lo inet loopback" > etc/network/interfaces      echo "iface lo inet loopback" > etc/network/interfaces
331    
332      echo "*.* /tmp/syslog.log" > etc/syslog.conf      cat >> root/.profile <<-EOF
333      echo ". /usr/share/fai/subroutines" >> root/.profile          PATH=/usr/local/sbin:/usr/local/bin:/usr/lib/fai:/bin:/sbin:/usr/bin:/usr/sbin:
334            export PATH
335      setup_ssh          . /usr/lib/fai/subroutines
336            . /usr/lib/fai/subroutines-linux
337      cat >$NFSROOT/etc/rc2.d/S01fai_abort <<-EOF          set -a
338          #!/bin/sh          . /tmp/fai/variables.log 2>/dev/null
         echo FAI: installation aborted.  
         echo reboot with: faireboot  
         echo or after a logout  
         sh  
         cd /  
         umount -ar  
         reboot -dfi  
339  EOF  EOF
340      chmod a+rx $NFSROOT/etc/rc2.d/S01fai_abort  
341        call_verbose call_with_stamp setup_ssh
342  }  }
343  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
344  upgrade_nfsroot() {  upgrade_nfsroot() {
345    
346      echo "Upgrading $NFSROOT"      if [ -f /etc/resolv.conf ]; then
347      {          cp -p $v /etc/resolv.conf $NFSROOT/etc/resolv.conf-installserver
348      cp /etc/resolv.conf $NFSROOT/etc          cp -p $v /etc/resolv.conf $NFSROOT/etc/resolv.conf # this is needed during make-fai-nfsroot
349        fi
350      $ROOTCMD apt-get update      $ROOTCMD apt-get update
351        $ROOTCMD apt-get -fy install fai-nfsroot
352      $ROOTCMD apt-get check      $ROOTCMD apt-get check
353      rm -rf $NFSROOT/etc/apm      rm -rf $NFSROOT/etc/apm
354      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  
355    
356      # fake start-stop-dameon      if [ $divert = 1 ]; then
357      $ROOTCMD dpkg-divert --quiet --package fai --add --rename /sbin/start-stop-daemon          fdivert /usr/sbin/update-initramfs
358      cp $LIBFAI/sbin/start-stop-daemon $NFSROOT/sbin          ln -s /bin/true $NFSROOT/usr/sbin/update-initramfs
359      $ROOTCMD apt-get -y upgrade      fi
360      } > $devnull      fdivert /sbin/start-stop-daemon /sbin/discover-modprobe
361        cp -p /sbin/fai-start-stop-daemon $NFSROOT/sbin
362        cp -p /sbin/fai-start-stop-daemon $NFSROOT/sbin/start-stop-daemon
363        $ROOTCMD apt-get -y dist-upgrade
364    }
365    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
366    add_packages_nfsroot() {
367    
368        local iarch=$($ROOTCMD dpkg --print-installation-architecture|tr /a-z/ /A-Z/)
369        export FAI_ROOT=$NFSROOT
370        export classes="NFSROOT $iarch"
371    cat > $NFSROOT/etc/kernel-img.conf << EOF
372    do_bootloader = No
373    do_initrd = No
374    warn_initrd = No
375    EOF
376        install_packages -l -p$cfdir > $NFSROOT/var/tmp/packages.nfsroot
377      echo "Adding additional packages to $NFSROOT:"      echo "Adding additional packages to $NFSROOT:"
378      echo "$packages"      cat $NFSROOT/var/tmp/packages.nfsroot
379      {      call_verbose install_packages $v -p$cfdir
380      $ROOTCMD apt-get -y --fix-missing install $packages </dev/null      echo "install_packages exit code: $?"
     $ROOTCMD apt-get clean  
     } > $devnull  
 }  
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
 get_basetgz() {  
   
     [ -f /tmp/base2_2.tgz ] && return  
     [ "$FAI_BASETGZ" ] || die "No /tmp/base2_2.tgz found and FAI_BASETGZ not defined."  
     case $FAI_BASETGZ in  
         ftp:*|http:*)  
             echo "Fetching $FAI_BASETGZ via wget. This may take some time."  
             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  
381  }  }
382  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
383  umount_dirs() {  umount_dirs() {
384    
385        [ -f $NFSROOT/usr/sbin/dpkg-divert ] &&
386           LC_ALL=C $ROOTCMD dpkg-divert --rename --remove /sbin/discover-modprobe
387      cd /      cd /
388      sleep 2      [ -d $NFSROOT/proc/self ] && umount $NFSROOT/proc
389      umount $NFSROOT/proc 1>/dev/null 2>&1 || true      [ -d $NFSROOT/proc/self ] && die "/proc still mounted inside the nfsroot."
     umount $NFSROOT/dev/pts 1>/dev/null 2>&1 ||true  
390      if [ "$FAI_DEBMIRROR" ]; then      if [ "$FAI_DEBMIRROR" ]; then
391          test -d $NFSROOT/$MNTPOINT && umount $NFSROOT/$MNTPOINT || true          test -d $NFSROOT/$MNTPOINT && umount $NFSROOT/$MNTPOINT || true
392      fi      fi
393      # show directories still mounted on nfsroot      # show directories still mounted on nfsroot
394      mount | grep " on $NFSROOT " || true      mount | grep " on $NFSROOT " || true
395  }  }
396  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
397    get_kernel_version() {
398    
399        local package=$1
400    
401        KERNELVERSION=`dpkg --info $package | grep ' Package: '`
402        KERNELVERSION=${KERNELVERSION/*-image-/}
403    }
404    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
405    setup_bootp(){
406    
407        mkdir -p $TFTPROOT
408        if [ -x "$(which mkelf-linux)" ]; then
409            # does not work any mork if we do not know the excatly kernel name
410    :
411    #       mkelf-linux --ip=any --output=$TFTPROOT/installimage \
412    #         $NFSROOT/boot/$kfile-$KERNELVERSION
413        else
414            echo "Command mkelf-linux not found. Can not set up BOOTP booting. Please install the package mknbi and rerun fai-setup."
415            return
416        fi
417    
418        # imggen is free software from 3com - use ver1.00: 1.01 produces "Image too Big" errors.
419        # it converts netboot images to images which are bootable by 3com network cards
420        if [ -x "$(which imggen)" ]; then
421            imggen -a $TFTPROOT/installimage $TFTPROOT/installimage_3com
422        fi
423        echo "BOOTP environment prepared."
424    }
425    
426    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
427    setup_dhcp(){
428    
429        # pxe and dhcp environment
430        local pxebin=/usr/lib/syslinux/pxelinux.0
431        rm -f $NFSROOT/boot/*.bak
432        mkdir -p $TFTPROOT/pxelinux.cfg
433        cp -pv $NFSROOT/boot/$kfile-* $TFTPROOT
434        cp -pv $NFSROOT/boot/initrd.img-* $TFTPROOT
435        [ -f $pxebin ] && cp $pxebin $TFTPROOT
436        echo "DHCP environment prepared. If you want to use it, you have to enable the dhcpd and the tftp-hpa daemon."
437    }
438    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
439    fdivert() {
440    
441        local item
442        for item in "$@"; do
443            LC_ALL=C $ROOTCMD dpkg-divert --quiet --add --rename $item
444        done
445    }
446    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
447    kernel_install() {
448    
449    # Install the kernel package
450    
451        # create tftp boot images
452        call_with_stamp install_kernel_nfsroot
453    
454        # setup for DHCP, BOOTP or both
455        [ "x$FAI_BOOT" = "x" ] && FAI_BOOT="dhcp bootp"
456    
457        for bootopt in $FAI_BOOT; do
458            case $bootopt in
459                    dhcp|DHCP)
460                            call_with_stamp setup_dhcp ;;
461                    bootp|BOOTP)
462                            call_with_stamp setup_bootp ;;
463                    *)
464                            echo "Unknown boot option" ;;
465            esac
466        done
467    }
468    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
469    run_hooks() {
470    
471        local file
472        if [ -z "$NFSROOT_HOOKS" ]; then
473            return
474        fi
475        if [ -d "$NFSROOT_HOOKS"  ]; then
476            echo "Running hooks..."
477            for file in $(ls $NFSROOT_HOOKS/* 2>/dev/null); do
478                . $file
479            done
480        fi
481    }
482    # - - - - - - - - - - - - - - - - - - - - - - - - - -
483  # main routine  # main routine
484    
485  if [ -d $NFSROOT/fai ]; then  # remove all kernels from nfsroot
486    [ -n "$kremove" ] && {
487        echo "Removing all kernels from NFSROOT."
488        $ROOTCMD aptitude -y purge ~nlinux-image
489        exit
490    }
491    
492    # just install a new kernel to the nfsroot
493    [ -n "$kinstall" ] && {
494        trap "true" EXIT
495        echo "Installing new kernel into the nfsroot."
496        if [ $divert = 1 ]; then
497            fdivert /usr/sbin/update-initramfs
498            ln -s /bin/true $NFSROOT/usr/sbin/fai
499        fi
500        LC_ALL=C add_packages_nfsroot
501        kernel_install
502        run_hooks
503        umount_dirs
504        trap "true" EXIT
505        echo "make-fai-nfsroot finished $merror."
506        exit 0
507    }
508    
509    echo "Creating FAI nfsroot in $NFSROOT."
510    echo "By default it needs more than 330 MBytes disk space."
511    echo "This may take a long time."
512    
513    if [ $sshpreserve = 1 ]; then
514        # save old .ssh directory
515        tmptar=$(mktemp) || exit 12
516        # should we set the umask before? Does it influence the other parts?
517        tar -C $NFSROOT -cvf $tmptar root/.ssh
518    fi
519    
520    # Kill the directory if not in recover mode
521    if [ -d $NFSROOT/proc -a ! "$recover" ]
522    then
523      echo $NFSROOT already exists. Removing $NFSROOT      echo $NFSROOT already exists. Removing $NFSROOT
524      umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true      umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true
525      rm -rf $NFSROOT/.??* $NFSROOT/*      [ -L $NFSROOT/proc/self ] && umount $NFSROOT/proc || true
526        [ -L $NFSROOT/proc/self ] && die "/proc is still mounted inside the nfsroot."
527        rm -rf $oldnfsroot/.??* $oldnfsroot/*
528      # also remove files $NFSROOT/.? but not . and ..      # also remove files $NFSROOT/.? but not . and ..
529      find $NFSROOT ! -type d -xdev -maxdepth 1 | xargs -r rm -f      find $oldnfsroot -xdev -maxdepth 1 ! -type d | xargs -r rm -f
530  fi  fi
531    
532  create_nfsroot  # Create a new nfsroot
533    if [ ! -x "$(which debootstrap)" ]; then
534  if [ -f $KERNELPACKAGE ]; then      die "Can't find debootstrap command. Aborting."
     # 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."  
535  fi  fi
536    call_with_stamp create_nfsroot
537    
538  echo make-fai-nfsroot finished.  kernel_install
539    run_hooks
540    check_nfsroot
541    umount_dirs
542    trap "true" EXIT
543    echo "make-fai-nfsroot finished $merror."
544  exit 0  exit 0
545    } 2>&1 | tee /var/log/fai/make-fai-nfsroot.log
546    echo "Log file written to /var/log/fai/make-fai-nfsroot.log"

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

  ViewVC Help
Powered by ViewVC 1.1.5