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

Legend:
Removed from v.1026  
changed lines
  Added in v.5026

  ViewVC Help
Powered by ViewVC 1.1.5