/[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 2758 by lange, Wed Apr 6 19:04:41 2005 UTC trunk/bin/make-fai-nfsroot revision 4564 by lange, Thu Sep 13 09:39:53 2007 UTC
# 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-2005 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 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    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31    usage() {
32    
33        cat <<-EOF
34            Copyright (C) 1999-2007 Thomas Lange
35            Report bugs to <fai@informatik.uni-koeln.de>.
36    
37            Usage: make-fai-nfsroot [OPTIONS]
38      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  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
52    
53  if [ `id -u` -ne 0 ]; then  kfile="vmlinuz" # some architectures use different names
54      echo "Run this program as root."  merror="properly"
55      exit 9  sshpreserve=0
56    divert=1
57    
58    if [ -f /etc/lsb-release ]; then
59        . /etc/lsb-release
60        case "$DISTRIB_ID" in
61            Ubuntu) divert=0 ;;
62        esac
63  fi  fi
64    
 merror="properly"  
65  # option e currently does nothing  # option e currently does nothing
66  while getopts ervc:f:kK opt ; do  while getopts hervC:f:kKpU opt ; do
67      case "$opt" in      case "$opt" in
68          c) cfdir=$OPTARG ;;          C) cfdir=$OPTARG ;;
69          v) verbose=1 ; v=-v ;;          v) verbose=1 ; v=-v ;;
70          r) recover=1 ;;          r) recover=1 ;;
71          f) cfg=$OPTARG ;;          f) die "Option -f is not supported any more. Use option -C instead" ;;
72          k) kinstall=1 ;;          k) kinstall=1 ;;
73          K) kremove=1; kinstall=1 ;;          K) kremove=1;;
74          e) expert=1 ;;          h) usage ;;
75            e) expert=1 ;; # a dummy option, that only fai-setup uses
76            p) sshpreserve=1 ;;
77            U) divert=0 ;;
78          ?) exit 5 ;; # error in option parsing          ?) exit 5 ;; # error in option parsing
79      esac      esac
80  done  done
81    
82    if [ $(id -u) != "0" ]; then
83        echo "Run this program as root."
84        exit 9
85    fi
86    
87  set -e  set -e
88    
89  [ -z "$cfdir" ] && cfdir=/etc/fai  # use FAI_ETC_DIR from environment variable
90    if [ -n "$FAI_ETC_DIR" -a -z "$cfdir" ]; then
91        echo "Using environment variable \$FAI_ETC_DIR."
92    fi
93    [ -z "$cfdir" ] && cfdir=${FAI_ETC_DIR:=/etc/fai}
94    cfdir=$(readlink -f $cfdir) # canonicalize path
95  if [ ! -d "$cfdir" ]; then  if [ ! -d "$cfdir" ]; then
96      echo "$cfdir is not a directory"      echo "$cfdir is not a directory"
97      exit 6      exit 6
98  fi  fi
99  [ "$verbose" ] && echo "Using configuration files from directory $cfdir"  [ "$verbose" ] && echo "Using configuration files from $cfdir"
100  if [ -n "$cfg" ]; then  . $cfdir/fai.conf
     . $cfdir/$cfg  
 else  
     . $cfdir/fai.conf  
 fi  
101    
102  # read config file for this tool  # read config file for this tool
103  if [ -f "$cfdir/make-fai-nfsroot.conf" ]; then  if [ -f "$cfdir/make-fai-nfsroot.conf" ]; then
# Line 72  else Line 107  else
107      exit 8      exit 8
108  fi  fi
109    
110  if [ -z "$NFSROOT" ]; then  # IMO this may be removed, since all information should be included into sources.list
111      echo "\$NFSROOT is not set. Please check your settings in $cfdir/fai.conf."  [ -n "$FAI_LOCAL_REPOSITORY" ] && die "The use of \$FAI_LOCAL_REPOSITORY is now deprecated. Please include this information into sources.list."
112      exit 4  [ -n "$packages" ] && die "The use of \$packages in make-fai-nfsroot.conf is now deprecated. Please include this information into $cfdir/NFSROOT."
113  fi  [ -n "$NFSROOT_PACKAGES" ] && die "The use of \$NFSROOT_PACKAGES in make-fai-nfsroot.conf is now deprecated. Please include this information into $cfdir/NFSROOT."
114    [ -n "$FAI_SOURCES_LIST" ] && die "The use of \$FAI_SOURCES_LIST is deprecated. Please use sources.list now."
 if [ "$FAI_SOURCES_LIST" ]; then  
     echo "The usage of the variable \$FAI_SOURCES_LIST is deprecated. Please use sources.list now."  
     exit 3  
 fi  
115    
116  if [ ! -s "$cfdir/sources.list" -a ! -f /etc/apt/sources.list ]; then  [ -z "$NFSROOT" ] && die "\$NFSROOT is not set. Please check your settings in $cfdir/fai.conf."
117      echo "Neither $cfdir/sources.list nor /etc/apt/sources.list exists."  [ ! -d "$cfdir/apt" ] && die "$cfdir/apt/ does not exists. Can't continue."
     echo "I think something is wrong. Can't continue."  
     exit 7  
 fi  
118    
119  kfile="vmlinuz"  NFSROOT="$NFSROOT/live/filesystem.dir"
 case `dpkg --print-installation-architecture` in  
     i386|amd64)  
         arch_packages="grub lilo read-edid kudzu hwtools dmidecode" ;;  
   
     ia64)  
         arch_packages="elilo gnu-efi efibootmgr" ;;  
   
     sparc)  
         arch_packages="silo sparc-utils" ;;  
   
     powerpc)  
         arch_packages=""  
         kfile="vmlinux" ;;  
   
     alpha)  
         arch_packages="aboot" ;;  
   
     *)  arch_packages="" ;;  
 esac  
 packages="$packages  
 $arch_packages"  
   
120  ROOTCMD="chroot $NFSROOT"  ROOTCMD="chroot $NFSROOT"
121    
122  RUNDIR=/var/run/fai/make-fai-nfsroot  RUNDIR=/var/run/fai/make-fai-nfsroot
123  [ ! -d $RUNDIR ] && mkdir -p $RUNDIR  mkdir -p $RUNDIR
 LIBFAI=/usr/lib/fai  
 SHAREFAI=/usr/share/fai  
124  export DEBIAN_FRONTEND=noninteractive  export DEBIAN_FRONTEND=noninteractive
125  [ "$recover" ] || rm -rf $RUNDIR/*  [ "$recover" ] || rm -rf $RUNDIR/*
126    
127  trap "umount_dirs" EXIT  trap 'echo "Aborting";umount_dirs' EXIT
128  trap "bad_exit" ERR  trap "bad_exit" ERR
129  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
130  bad_exit() {  bad_exit() {
# Line 130  bad_exit() { Line 134  bad_exit() {
134      echo "Please fix the error or try make-fai-nfsroot -v"      echo "Please fix the error or try make-fai-nfsroot -v"
135  }  }
136  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 die() {  
   
     echo "$@"  
     exit 99  
 }  
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
137  call_with_stamp() {  call_with_stamp() {
138    
139      local func=$1      local func=$1
# Line 157  call_verbose() { Line 155  call_verbose() {
155  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
156  install_kernel_nfsroot() {  install_kernel_nfsroot() {
157    
158      rm -rf $NFSROOT/boot/*-$KERNELVERSION $NFSROOT/lib/modules/$KERNELVERSION      if [ $divert = 1 ]; then
159      # since woody we can install the kernel using dpkg -i          rm $NFSROOT/usr/sbin/update-initramfs
160      echo "do_boot_enable=no" > $NFSROOT/etc/kernel-img.conf          LC_ALL=C $ROOTCMD dpkg-divert --rename --remove /usr/sbin/update-initramfs
161      dpkg -x $KERNELPACKAGE $NFSROOT          $ROOTCMD update-initramfs -k all -t -u
162      # if $NFROOT/proc/modules exists, then update-modules calls depmod -a without      fi
     # these special flags; so umount first  
     [ -e $NFSROOT/proc/modules ] && umount $NFSROOT/proc  
     chroot $NFSROOT update-modules  
     chroot $NFSROOT depmod -qaF /boot/System.map-$KERNELVERSION $KERNELVERSION || true  
163  }  }
164  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
165  setup_ssh() {  setup_ssh() {
166    
167      # nothing to do if no ssh is available in nfsroot      # nothing to do if no ssh is available in nfsroot
168      [ -f $NFSROOT/var/lib/dpkg/info/ssh.list ] || return 0      [ -f $NFSROOT/usr/bin/ssh ] || return 0
169        if [ $sshpreserve = 1 ]; then
170            tar -C $NFSROOT -xf $tmptar
171            rm $tmptar
172            return 0
173        fi
174    
175      mkdir -p -m 700 $NFSROOT/root/.ssh      mkdir -p -m 700 $NFSROOT/root/.ssh
176      if [ -n "$LOGUSER" ] ; then      if [ -n "$LOGUSER" ] ; then
177          loguserhome=`eval "cd ~$LOGUSER 2>/dev/null && pwd;true"`          loguserhome=`eval "cd ~$LOGUSER 2>/dev/null && pwd;true"`
     # is copying of *.pub important?  
178          [ -f $loguserhome/.ssh/known_hosts ] && cp $loguserhome/.ssh/known_hosts $NFSROOT/root/.ssh/known_hosts          [ -f $loguserhome/.ssh/known_hosts ] && cp $loguserhome/.ssh/known_hosts $NFSROOT/root/.ssh/known_hosts
179          [ -d $loguserhome/.ssh ] && {          [ -d $loguserhome/.ssh ] && {
180              [ -f $loguserhome/.ssh/id_dsa ] &&              [ -f $loguserhome/.ssh/id_dsa ] &&
181                 cp -p $loguserhome/.ssh/id_dsa* $NFSROOT/root/.ssh/                 cp -p $loguserhome/.ssh/id_dsa* $NFSROOT/root/.ssh/
182              [ -f $loguserhome/.ssh/id_rsa ] &&              [ -f $loguserhome/.ssh/id_rsa ] &&
183                 cp -p $loguserhome/.ssh/id_rsa* $NFSROOT/root/.ssh/                 cp -p $loguserhome/.ssh/id_rsa* $NFSROOT/root/.ssh/
             cp -p $loguserhome/.ssh/*.pub $NFSROOT/root/.ssh/  
184          }          }
185      fi      fi
186    
# Line 198  setup_ssh() { Line 196  setup_ssh() {
196  copy_fai_files() {  copy_fai_files() {
197    
198      # copy to nfsroot      # copy to nfsroot
199      perl -pi -e "s#^root::#root:${FAI_ROOTPW}:#" etc/passwd      echo "root:$FAI_ROOTPW" | $ROOTCMD chpasswd --encrypted
     mkdir -p $NFSROOT/$SHAREFAI $NFSROOT/$LIBFAI $NFSROOT/etc/fai  
     cd $NFSROOT  
     fdivert /etc/dhcp3/dhclient-script /etc/dhcp3/dhclient.conf  
     cp -p $SHAREFAI/etc/dhclient.conf etc/dhcp3  
200      cp -Rpv $cfdir/* $NFSROOT/etc/fai      cp -Rpv $cfdir/* $NFSROOT/etc/fai
201        # append additional variables to fai.conf for the install clients
202        [ -z "$FAI_CONFIG_SRC" ] && echo "FAI_CONFIG_SRC=nfs://`hostname`$FAI_CONFIGDIR" >> $NFSROOT/etc/fai/fai.conf
203    
204      # remove some files that should not be copied      # remove some files that should not be copied
205      rm -f $NFSROOT/etc/fai/make-fai-nfsroot.conf      rm -f $NFSROOT/etc/fai/make-fai-nfsroot.conf
206      [ -f $cfdir/.cvspass ] && cp -p $v $cfdir/.cvspass $NFSROOT/.cvspass      [ -f $cfdir/.cvspass ] && cp -p $v $cfdir/.cvspass $NFSROOT/.cvspass
     cp -p $LIBFAI/sbin/* sbin/  
     cp -p /usr/sbin/fai usr/sbin/  
     mv sbin/dhclient-script etc/dhcp3  
     cp -p /usr/sbin/{ftar,fcopy,install_packages} usr/sbin/  
     cp -p /usr/bin/{fai-do-scripts,fai-class,fai-debconf} usr/bin/  
     cp -p $LIBFAI/* usr/lib/fai 2>/dev/null || true  # cp will complain about directories  
     cp -p $SHAREFAI/etc/fai_modules_off etc/modutils/  
   
     cp -p $SHAREFAI/subroutines* usr/share/fai  
     cp -p $v $SHAREFAI/etc/apt.conf $NFSROOT/etc/apt  
     cp -p /usr/share/perl5/Debian/Fai.pm usr/share/perl5/Debian/  
207      $ROOTCMD shadowconfig on      $ROOTCMD shadowconfig on
208  }  }
209  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
210  call_debootstrap() {  call_debootstrap() {
211    
212      echo "Creating nfsroot for $1 using debootstrap"      local dversion=$(dpkg -l debootstrap | grep debootstrap | cut -f7 -d' ')
213      [ "$verbose" ] && echo "Calling debootstrap $1 $NFSROOT $2"      echo "Creating base system using debootstrap version $dversion"
214      yes '' | LC_ALL=C call_verbose debootstrap $FAI_DEBOOTSTRAP_OPTS $1 $NFSROOT $2 || true      echo "Calling debootstrap $1 $NFSROOT $2"
215        yes '' | LC_ALL=C call_verbose debootstrap $FAI_DEBOOTSTRAP_OPTS $1 $NFSROOT $2
216    }
217    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
218    add_all_host_entries() {
219    
220        local ips=$(ifconfig | grep -w inet | cut -d : -f 2 | cut -d ' ' -f 1 | grep -v 127.0.0.1)
221        for eth in $ips; do
222            getent hosts $eth >> etc/hosts || true
223        done
224  }  }
225  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
226  create_base() {  create_base() {
# Line 235  create_base() { Line 230  create_base() {
230          $ROOTCMD apt-get clean          $ROOTCMD apt-get clean
231          rm -f $NFSROOT/etc/resolv.conf          rm -f $NFSROOT/etc/resolv.conf
232          echo "Creating base.tgz"          echo "Creating base.tgz"
233          tar -l -C $NFSROOT -cf - --exclude var/tmp/base.tgz . | gzip > $NFSROOT/var/tmp/base.tgz          tar --one-file-system -C $NFSROOT -cf - --exclude var/tmp/base.tgz . | gzip > $NFSROOT/var/tmp/base.tgz
234            touch $NFSROOT/.THIS_IS_THE_FAI_NFSROOT
235      else      else
236          die "\$FAI_DEBOOTSTRAP not defined."          die "\$FAI_DEBOOTSTRAP not defined."
237      fi      fi
# Line 244  create_base() { Line 240  create_base() {
240  create_nfsroot() {  create_nfsroot() {
241    
242      mkdir -p $NFSROOT/$FAI      mkdir -p $NFSROOT/$FAI
243      cd $NFSROOT || die "Error: Can't cd to $NFSROOT"      cd $NFSROOT || die "Can't cd to $NFSROOT"
244    
245      call_with_stamp create_base      call_with_stamp create_base
246      # save the list of all packages in the base.tgz      # save the list of all packages in the base.tgz
247      $ROOTCMD dpkg --get-selections | egrep 'install$' | awk '{print $1}' > var/tmp/base-pkgs.lis      $ROOTCMD dpkg --get-selections | egrep 'install$' | awk '{print $1}' > var/tmp/base-pkgs.lis
     echo $arch_packages > $NFSROOT/var/tmp/packages.arch  
248    
249      if [ "$FAI_DEBMIRROR" ]; then      if [ "$FAI_DEBMIRROR" ]; then
250          [ "$verbose" ] && echo "Mounting $FAI_DEBMIRROR to $NFSROOT/$MNTPOINT."          [ "$verbose" ] && echo "Mounting $FAI_DEBMIRROR to $NFSROOT/$MNTPOINT."
# Line 262  create_nfsroot() { Line 257  create_nfsroot() {
257      # liloconfig, dump and raidtool2 needs these files      # liloconfig, dump and raidtool2 needs these files
258      echo "# UNCONFIGURED FSTAB FOR BASE SYSTEM" > etc/fstab      echo "# UNCONFIGURED FSTAB FOR BASE SYSTEM" > etc/fstab
259      > etc/raidtab      > etc/raidtab
     mkdir -p lib/modules/$KERNELVERSION           # dirty trick to hoax lvm  
     >  lib/modules/$KERNELVERSION/modules.dep  # dirty trick to hoax lvm  
260      echo 'NTPSERVERS=""' > etc/default/ntp-servers      echo 'NTPSERVERS=""' > etc/default/ntp-servers
261    
262      [ -d $NFSROOT/var/state ] || mkdir $NFSROOT/var/state      # live.conf will set hostname to debian
263      [ "$verbose" ] && echo "Try to copy $cfdir/sources.list or /etc/apt/sources.list."      cp /dev/null etc/live.conf
264      cp -v $cfdir/sources.list $NFSROOT/etc/apt/sources.list || \  
265          cp -v /etc/apt/sources.list $NFSROOT/etc/apt/sources.list || \      cp -a $cfdir/apt $NFSROOT/etc
266          { echo "No sources.list file found."  
267            echo "I think something is wrong. But I'll try to continue."      ainsl -as $NFSROOT/etc/hosts "127.0.0.1 localhost"
268          }      ainsl     $NFSROOT/etc/hosts "$NFSROOT_ETC_HOSTS"
269        add_all_host_entries
270      echo "127.0.0.1 localhost" >> etc/hosts  
271      echo "$NFSROOT_ETC_HOSTS" >> etc/hosts      # we need these option before installing the first package. So we
272      [ -f /etc/apt/preferences ] && cp -v /etc/apt/preferences $NFSROOT/etc/apt      # can't put this into fai-nfsroot /etc/apt/apt.conf.d/90fai
273      [ -f $cfdir/preferences ] && cp -v $cfdir/preferences $NFSROOT/etc/apt      cat <<EOF >$NFSROOT/etc/apt/apt.conf.d/10fai
274    APT::Get::AllowUnauthenticated "true";
275    Aptitude::CmdLine::Ignore-Trust-Violations yes;
276    EOF
277      echo "Upgrading $NFSROOT"      echo "Upgrading $NFSROOT"
278      LC_ALL=C call_verbose call_with_stamp upgrade_nfsroot      LC_ALL=C call_verbose call_with_stamp upgrade_nfsroot
279      echo "Adding additional packages to $NFSROOT:"      LC_ALL=C call_with_stamp add_packages_nfsroot
     echo "$packages"  
     LC_ALL=C call_verbose call_with_stamp add_packages_nfsroot  
280      call_with_stamp copy_fai_files      call_with_stamp copy_fai_files
281    
282      # set timezone in nfsroot      # set timezone in nfsroot
# Line 290  create_nfsroot() { Line 284  create_nfsroot() {
284      echo $timezone > etc/timezone      echo $timezone > etc/timezone
285      rm -f etc/localtime && ln -sf /usr/share/zoneinfo/$timezone etc/localtime      rm -f etc/localtime && ln -sf /usr/share/zoneinfo/$timezone etc/localtime
286    
287      # make little changes to nfsroot, because nfsroot is      rm etc/mtab && ln -s /proc/mounts etc/mtab
     # read only for the install clients  
     rm -rf etc/mtab var/run etc/sysconfig  
     ln -s /proc/mounts etc/mtab  
     ln -s /tmp/var/run var/run  
     ln -sf /tmp/var/state/discover var/state/discover  
     ln -sf /tmp/var/lib/discover var/lib/discover  
     ln -s /tmp/etc/syslogsocket dev/log  
     ln -sf /tmp/etc/resolv.conf etc/resolv.conf  
     ln -sf /tmp etc/sysconfig  
288      ln -s /usr/sbin/fai etc/init.d/rcS      ln -s /usr/sbin/fai etc/init.d/rcS
     ln -sf /dev/null etc/network/ifstate  
289      # for nis      # for nis
290      [ -d var/yp ] && ln -s /tmp/binding var/yp/binding  #    [ -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  
291    
292      # definition for loopback device      # definition for loopback device
293      echo "iface lo inet loopback" > etc/network/interfaces      echo "iface lo inet loopback" > etc/network/interfaces
294    
     echo "*.* /tmp/fai/syslog.log" > etc/syslog.conf  
295      cat >> root/.profile <<-EOF      cat >> root/.profile <<-EOF
296          PATH=/usr/local/sbin:/usr/local/bin:/usr/lib/fai:/bin:/sbin:/usr/bin:/usr/sbin:          PATH=/usr/local/sbin:/usr/local/bin:/usr/lib/fai:/bin:/sbin:/usr/bin:/usr/sbin:
297          export PATH          export PATH
298          . $SHAREFAI/subroutines          . /usr/lib/fai/subroutines
299          . $SHAREFAI/subroutines-$OS_TYPE          . /usr/lib/fai/subroutines-linux
300          set -a          set -a
301          . /tmp/fai/variables.sh 2>/dev/null          . /tmp/fai/variables.log 2>/dev/null
302  EOF  EOF
303    
304      call_verbose call_with_stamp setup_ssh      call_verbose call_with_stamp setup_ssh
   
     cat >$NFSROOT/etc/rc2.d/S01fai_abort <<-EOF  
         #!/bin/sh  
         echo FAI: installation aborted.  
         echo reboot with: faireboot  
         echo or after a logout  
         sh  
         cd /  
         umount -ar  
         reboot -dfi  
 EOF  
     chmod a+rx $NFSROOT/etc/rc2.d/S01fai_abort  
   
     echo -e "\n$FAI_LOCAL_REPOSITORY" >> etc/apt/sources.list  
305  }  }
306  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
307  upgrade_nfsroot() {  upgrade_nfsroot() {
308    
309      cp -p $v /etc/resolv.conf $NFSROOT/etc/resolv.conf-installserver      if [ -f /etc/resolv.conf ]; then
310      cp -p $v /etc/resolv.conf $NFSROOT/etc/resolv.conf # this is needed during make-fai-nfsroot          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      $ROOTCMD apt-get -fy install fai-nfsroot
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
318    
319      # fake start-stop-dameon      if [ $divert = 1 ]; then
320      fdivert /etc/init.d/rcS /sbin/start-stop-daemon /sbin/discover-modprobe          fdivert /usr/sbin/update-initramfs
321      cp /sbin/fai-start-stop-daemon $NFSROOT/sbin/          ln -s /bin/true $NFSROOT/usr/sbin/update-initramfs
322      ln -s /sbin/fai-start-stop-daemon $NFSROOT/sbin/start-stop-daemon      fi
323        fdivert /sbin/start-stop-daemon /sbin/discover-modprobe
324        cp -p /sbin/fai-start-stop-daemon $NFSROOT/sbin
325        cp -p /sbin/fai-start-stop-daemon $NFSROOT/sbin/start-stop-daemon
326      $ROOTCMD apt-get -y dist-upgrade      $ROOTCMD apt-get -y dist-upgrade
327  }  }
328  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
329  add_packages_nfsroot() {  add_packages_nfsroot() {
330    
331      $ROOTCMD apt-get -y --fix-missing install $packages </dev/null      local iarch=$($ROOTCMD dpkg --print-installation-architecture|tr /a-z/ /A-Z/)
332      if [ -n "$NFSROOT_PACKAGES" ] ; then      export FAI_ROOT=$NFSROOT
333          LC_ALL=C $ROOTCMD apt-get -y --fix-missing install $NFSROOT_PACKAGES </dev/null      export classes="NFSROOT $iarch"
334      fi  cat > $NFSROOT/etc/kernel-img.conf << EOF
335      $ROOTCMD apt-get clean  do_bootloader = No
336    do_initrd = No
337    warn_initrd = No
338    EOF
339        install_packages -l -p$cfdir > $NFSROOT/var/tmp/packages.nfsroot
340        echo "Adding additional packages to $NFSROOT:"
341        cat $NFSROOT/var/tmp/packages.nfsroot
342        call_verbose install_packages $v -p$cfdir
343  }  }
344  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
345  umount_dirs() {  umount_dirs() {
346    
347      [ -f $NFSROOT/usr/sbin/dpkg-divert ] &&      [ -f $NFSROOT/usr/sbin/dpkg-divert ] &&
348         LC_ALL=C $ROOTCMD dpkg-divert --package fai --rename --remove /sbin/discover-modprobe         LC_ALL=C $ROOTCMD dpkg-divert --rename --remove /sbin/discover-modprobe
349      cd /      cd /
     sleep 2  
350      [ -d $NFSROOT/proc/self ] && umount $NFSROOT/proc      [ -d $NFSROOT/proc/self ] && umount $NFSROOT/proc
351      [ -d $NFSROOT/proc/self ] && umount $NFSROOT/dev/pts      [ -d $NFSROOT/proc/self ] && umount $NFSROOT/dev/pts
352      if [ "$FAI_DEBMIRROR" ]; then      if [ "$FAI_DEBMIRROR" ]; then
# Line 383  umount_dirs() { Line 359  umount_dirs() {
359  get_kernel_version() {  get_kernel_version() {
360    
361      local package=$1      local package=$1
362      KERNELVERSION=`dpkg --info $package | grep "Package: kernel-image" | sed -e 's/.*kernel-image-'//`  
363        KERNELVERSION=`dpkg --info $package | grep ' Package: '`
364        KERNELVERSION=${KERNELVERSION/*-image-/}
365  }  }
366  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
367  setup_bootp(){  setup_bootp(){
368    
369        mkdir -p $TFTPROOT
370      if [ -x "`which mkelf-linux`" ]; then      if [ -x "`which mkelf-linux`" ]; then
371          mkelf-linux --ip=any --output=/boot/fai/installimage \          # does not work any mork if we do not know the excatly kernel name
372            $NFSROOT/boot/$kfile-$KERNELVERSION  :
373    #       mkelf-linux --ip=any --output=$TFTPROOT/installimage \
374    #         $NFSROOT/boot/$kfile-$KERNELVERSION
375      else      else
376          echo "Command mkelf-linux not found. Can not set up BOOTP booting. Please install the package mknbi and rerun fai-setup."          echo "Command mkelf-linux not found. Can not set up BOOTP booting. Please install the package mknbi and rerun fai-setup."
377          return          return
# Line 399  setup_bootp(){ Line 380  setup_bootp(){
380      # 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.
381      # 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
382      if [ -x "`which imggen`" ]; then      if [ -x "`which imggen`" ]; then
383          imggen -a /boot/fai/installimage /boot/fai/installimage_3com          imggen -a $TFTPROOT/installimage $TFTPROOT/installimage_3com
384      fi      fi
385      echo "BOOTP environment prepared."      echo "BOOTP environment prepared."
386  }  }
# Line 409  setup_dhcp(){ Line 390  setup_dhcp(){
390    
391      # pxe and dhcp environment      # pxe and dhcp environment
392      local pxebin=/usr/lib/syslinux/pxelinux.0      local pxebin=/usr/lib/syslinux/pxelinux.0
393      cp -p $NFSROOT/boot/$kfile-$KERNELVERSION /boot/fai/$kfile-install      rm -f $NFSROOT/boot/*.bak
394      [ -f $pxebin ] && cp $pxebin /boot/fai      mkdir -p $TFTPROOT/pxelinux.cfg
395      [ -d /boot/fai/pxelinux.cfg ] || mkdir -p /boot/fai/pxelinux.cfg || true      cp -pv $NFSROOT/boot/$kfile-* $TFTPROOT
396        cp -pv $NFSROOT/boot/initrd.img-* $TFTPROOT
397        [ -f $pxebin ] && cp $pxebin $TFTPROOT
398      echo "DHCP environment prepared. If you want to use it, you have to enable the dhcpd and the tftp-hpa daemon."      echo "DHCP environment prepared. If you want to use it, you have to enable the dhcpd and the tftp-hpa daemon."
399  }  }
400  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Line 419  fdivert() { Line 402  fdivert() {
402    
403      local item      local item
404      for item in "$@"; do      for item in "$@"; do
405          LC_ALL=C $ROOTCMD dpkg-divert --quiet --package fai --add --rename $item          LC_ALL=C $ROOTCMD dpkg-divert --quiet --add --rename $item
406      done      done
407  }  }
408  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
409  kernel_install() {  kernel_install() {
410    
411  # Install the kernel package  # Install the kernel package
 if [ -f $KERNELPACKAGE ]; then  
     # determine kernel version  
     get_kernel_version $KERNELPACKAGE  
412    
413      # create tftp boot images      # create tftp boot images
414      call_with_stamp install_kernel_nfsroot      call_with_stamp install_kernel_nfsroot
# Line 446  if [ -f $KERNELPACKAGE ]; then Line 426  if [ -f $KERNELPACKAGE ]; then
426                          echo "Unknown boot option" ;;                          echo "Unknown boot option" ;;
427          esac          esac
428      done      done
 else  
     merror="with errors"  
     echo "Error. Kernel package $KERNELPACKAGE not found."  
     echo "No install kernel installed in /boot/fai."  
     echo "No kernel modules available in nfsroot."  
 fi  
429  }  }
430  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - -
431  # main routine  # main routine
432    
433  # remove all kernels from nfsroot  # remove all kernels from nfsroot
434  [ -n "$kremove" ] && {  [ -n "$kremove" ] && {
435      echo "Removing all kernels from NFSROOT."      echo "Removing all kernels from NFSROOT."
436      rm -f $NFSROOT/boot/{System.map,vmlinuz,config}*      $ROOTCMD aptitude -y purge ~nlinux-image
437      rm -rf $NFSROOT/lib/modules/2.*      exit
438  }  }
439    
440  # just install a new kernel to the nfsroot  # just install a new kernel to the nfsroot
441  [ -n "$kinstall" ] && {  [ -n "$kinstall" ] && {
442      trap "true" EXIT      trap "true" EXIT
443      echo "Installing new kernel into the nfsroot."      echo "Installing new kernel into the nfsroot."
444        if [ $divert = 1 ]; then
445            fdivert /usr/sbin/update-initramfs
446            ln -s /bin/true $NFSROOT/usr/sbin/fai
447        fi
448        LC_ALL=C add_packages_nfsroot
449      kernel_install      kernel_install
     echo "New kernel from $KERNELPACKAGE installed into the nfsroot."  
450      exit      exit
451  }  }
452    
453  echo Creating FAI nfsroot can take a long time and will  echo "Creating FAI nfsroot in $NFSROOT."
454  echo need more than $nfssize disk space in $NFSROOT.  echo "By default it needs more than 330 MBytes disk space."
455    echo "This may take a long time."
456    
457    if [ $sshpreserve = 1 ]; then
458        # save old .ssh directory
459        tmptar=$(mktemp) || exit 12
460        # should we set the umask before? Does it influence the other parts?
461        tar -C $NFSROOT -cvf $tmptar root/.ssh
462    fi
463    
464  # Kill the directory if not in recover mode  # Kill the directory if not in recover mode
465  if [ -d $NFSROOT/$FAI -a ! "$recover" ]  if [ -d $NFSROOT/$FAI -a ! "$recover" ]
# Line 481  then Line 468  then
468      umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true      umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true
469      rm -rf $NFSROOT/.??* $NFSROOT/*      rm -rf $NFSROOT/.??* $NFSROOT/*
470      # also remove files $NFSROOT/.? but not . and ..      # also remove files $NFSROOT/.? but not . and ..
471      find $NFSROOT ! -type d -xdev -maxdepth 1 | xargs -r rm -f      find $NFSROOT -xdev -maxdepth 1 ! -type d | xargs -r rm -f
472  fi  fi
473    
474  # Create a new nfsroot  # Create a new nfsroot
475    if [ ! -x "`which debootstrap`" ]; then
476        die "Can't find debootstrap command. Aborting."
477    fi
478  call_with_stamp create_nfsroot  call_with_stamp create_nfsroot
479    
480  kernel_install  kernel_install

Legend:
Removed from v.2758  
changed lines
  Added in v.4564

  ViewVC Help
Powered by ViewVC 1.1.5