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

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

  ViewVC Help
Powered by ViewVC 1.1.5