/[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 5429 by lange, Sat Jul 18 16:29:12 2009 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-2009 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    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
33    usage() {
34    
35        cat <<-EOF
36            Copyright (C) 1999-2009 Thomas Lange
37            Report bugs to <fai@informatik.uni-koeln.de>.
38    
39            Usage: make-fai-nfsroot [OPTIONS]
40      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  PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin
77    
78  if [ `id -u` -ne 0 ]; then  merror="properly"
79      echo "Run this program as root."  sshpreserve=0
80      exit 9  divert=1
81    
82    if [ -f /etc/lsb-release ]; then
83        . /etc/lsb-release
84        case "$DISTRIB_ID" in
85            Ubuntu) divert=0 ;;
86        esac
87  fi  fi
88    
 merror="properly"  
89  # option e currently does nothing  # option e currently does nothing
90  while getopts ervc:f:kK opt ; do  while getopts hervC:f:kKpU opt ; do
91      case "$opt" in      case "$opt" in
92          c) cfdir=$OPTARG ;;          C) cfdir=$OPTARG ;;
93          v) verbose=1 ; v=-v ;;          v) verbose=1 ; v=-v ;;
94          r) recover=1 ;;          r) recover=1 ;;
95          f) cfg=$OPTARG ;;          f) die "Option -f is not supported any more. Use option -C instead" ;;
96          k) kinstall=1 ;;          k) kinstall=1 ;;
97          K) kremove=1; kinstall=1 ;;          K) kremove=1;;
98          e) expert=1 ;;          h) usage ;;
99            e) expert=1 ;; # a dummy option, that only fai-setup uses
100            p) sshpreserve=1 ;;
101            U) divert=0 ;;
102          ?) exit 5 ;; # error in option parsing          ?) exit 5 ;; # error in option parsing
103      esac      esac
104  done  done
105    
106    if [ $(id -u) != "0" ]; then
107        echo "Run this program as root."
108        exit 9
109    fi
110    
111  set -e  set -e
112    
113  [ -z "$cfdir" ] && cfdir=/etc/fai  # use FAI_ETC_DIR from environment variable
114    if [ -n "$FAI_ETC_DIR" -a -z "$cfdir" ]; then
115        echo "Using environment variable \$FAI_ETC_DIR."
116    fi
117    [ -z "$cfdir" ] && cfdir=${FAI_ETC_DIR:=/etc/fai}
118    cfdir=$(readlink -f $cfdir) # canonicalize path
119  if [ ! -d "$cfdir" ]; then  if [ ! -d "$cfdir" ]; then
120      echo "$cfdir is not a directory"      echo "$cfdir is not a directory"
121      exit 6      exit 6
122  fi  fi
123  [ "$verbose" ] && echo "Using configuration files from directory $cfdir"  [ "$verbose" ] && echo "Using configuration files from $cfdir"
124  if [ -n "$cfg" ]; then  . $cfdir/fai.conf
     . $cfdir/$cfg  
 else  
     . $cfdir/fai.conf  
 fi  
125    
126  # read config file for this tool  # read config file for this tool
127  if [ -f "$cfdir/make-fai-nfsroot.conf" ]; then  if [ -f "$cfdir/make-fai-nfsroot.conf" ]; then
# Line 72  else Line 131  else
131      exit 8      exit 8
132  fi  fi
133    
134  if [ -z "$NFSROOT" ]; then  # IMO this may be removed, since all information should be included into sources.list
135      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."
136      exit 4  [ -n "$packages" ] && badupdateto32 "The use of \$packages in make-fai-nfsroot.conf is now deprecated. Please include this information into $cfdir/NFSROOT."
137  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."
138    [ -n "$FAI_SOURCES_LIST" ] && die "The use of \$FAI_SOURCES_LIST is deprecated. Please use sources.list now."
139  if [ "$FAI_SOURCES_LIST" ]; then  
140      echo "The usage of the variable \$FAI_SOURCES_LIST is deprecated. Please use sources.list now."  [ -z "$NFSROOT" ] && die "\$NFSROOT is not set. Please check your settings in $cfdir/fai.conf."
141      exit 3  [ -z "$TFTPROOT" ] && badupdateto32 "\$TFTPROOT is not set. Please check your settings in $cfdir/make-fai-nfsroot.conf."
142  fi  [ -n "$KERNELPACKAGE" ] && badupdateto32 "The use of \$KERNELPACKAGE is deprecated. Please use $cfdir/NFSROOT now."
143    [ ! -d "$cfdir/apt" ] && die "$cfdir/apt/ does not exists. Can't continue."
144    
145  if [ ! -s "$cfdir/sources.list" -a ! -f /etc/apt/sources.list ]; then  oldnfsroot=$NFSROOT
146      echo "Neither $cfdir/sources.list nor /etc/apt/sources.list exists."  NFSROOT="$NFSROOT/live/filesystem.dir"
     echo "I think something is wrong. Can't continue."  
     exit 7  
 fi  
   
 kfile="vmlinuz"  
 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"  
   
147  ROOTCMD="chroot $NFSROOT"  ROOTCMD="chroot $NFSROOT"
148    
149  RUNDIR=/var/run/fai/make-fai-nfsroot  RUNDIR=/var/run/fai/make-fai-nfsroot
150  [ ! -d $RUNDIR ] && mkdir -p $RUNDIR  mkdir -p $RUNDIR
 LIBFAI=/usr/lib/fai  
 SHAREFAI=/usr/share/fai  
151  export DEBIAN_FRONTEND=noninteractive  export DEBIAN_FRONTEND=noninteractive
152  [ "$recover" ] || rm -rf $RUNDIR/*  [ "$recover" ] || rm -rf $RUNDIR/*
   
 trap "umount_dirs" EXIT  
 trap "bad_exit" ERR  
153  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
154  bad_exit() {  bad_exit() {
155    
# Line 130  bad_exit() { Line 158  bad_exit() {
158      echo "Please fix the error or try make-fai-nfsroot -v"      echo "Please fix the error or try make-fai-nfsroot -v"
159  }  }
160  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 die() {  
   
     echo "$@"  
     exit 99  
 }  
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
161  call_with_stamp() {  call_with_stamp() {
162    
163      local func=$1      local func=$1
164      local stamp=$RUNDIR/$func      local stamp=$RUNDIR/$func
165      # call subroutine      # call subroutine
166      [ "$recover" -a -f $stamp ] && return 0      [ "$recover" -a -f $stamp ] && return 0
167      "$@"      # make a stamp only on success.
168      > $stamp      "$@" && : > $stamp
169  }  }
170  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
171  call_verbose() {  call_verbose() {
172    
173      if [ "$verbose" ]; then      if [ "$verbose" ]; then
174          "$@"          "$@"
175            return $?
176      else      else
177          "$@" > /dev/null          "$@" > /dev/null
178            return $?
179      fi      fi
180  }  }
181  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
182  install_kernel_nfsroot() {  install_kernel_nfsroot() {
183    
184      rm -rf $NFSROOT/boot/*-$KERNELVERSION $NFSROOT/lib/modules/$KERNELVERSION      if [ $divert = 1 ]; then
185      # since woody we can install the kernel using dpkg -i          rm $NFSROOT/usr/sbin/update-initramfs
186      echo "do_boot_enable=no" > $NFSROOT/etc/kernel-img.conf          LC_ALL=C $ROOTCMD dpkg-divert --rename --remove /usr/sbin/update-initramfs
187      dpkg -x $KERNELPACKAGE $NFSROOT          $ROOTCMD update-initramfs -k all -t -u
188      # 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  
189  }  }
190  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
191  setup_ssh() {  setup_ssh() {
192    
193      # nothing to do if no ssh is available in nfsroot      # nothing to do if no ssh is available in nfsroot
194      [ -f $NFSROOT/var/lib/dpkg/info/ssh.list ] || return 0      [ -f $NFSROOT/usr/bin/ssh ] || return 0
195        if [ $sshpreserve = 1 ]; then
196            tar -C $NFSROOT -xf $tmptar
197            rm $tmptar
198            return 0
199        fi
200    
201      mkdir -p -m 700 $NFSROOT/root/.ssh      mkdir -p -m 700 $NFSROOT/root/.ssh
202      if [ -n "$LOGUSER" ] ; then      if [ -n "$LOGUSER" ] ; then
203          loguserhome=`eval "cd ~$LOGUSER 2>/dev/null && pwd;true"`          loguserhome=$(eval "cd ~$LOGUSER 2>/dev/null && pwd;true")
     # is copying of *.pub important?  
204          [ -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
205          [ -d $loguserhome/.ssh ] && {          [ -d $loguserhome/.ssh ] && {
206              [ -f $loguserhome/.ssh/id_dsa ] &&              [ -f $loguserhome/.ssh/id_dsa ] &&
207                 cp -p $loguserhome/.ssh/id_dsa* $NFSROOT/root/.ssh/                 cp -p $loguserhome/.ssh/id_dsa* $NFSROOT/root/.ssh/
208              [ -f $loguserhome/.ssh/id_rsa ] &&              [ -f $loguserhome/.ssh/id_rsa ] &&
209                 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/  
210          }          }
211      fi      fi
212    
# Line 198  setup_ssh() { Line 222  setup_ssh() {
222  copy_fai_files() {  copy_fai_files() {
223    
224      # copy to nfsroot      # copy to nfsroot
225      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  
226      cp -Rpv $cfdir/* $NFSROOT/etc/fai      cp -Rpv $cfdir/* $NFSROOT/etc/fai
227        # append additional variables to fai.conf for the install clients
228        [ -z "$FAI_CONFIG_SRC" ] && echo "FAI_CONFIG_SRC=nfs://`hostname`$FAI_CONFIGDIR" >> $NFSROOT/etc/fai/fai.conf
229    
230      # remove some files that should not be copied      # remove some files that should not be copied
231      rm -f $NFSROOT/etc/fai/make-fai-nfsroot.conf      rm -f $NFSROOT/etc/fai/make-fai-nfsroot.conf
232      [ -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/  
233      $ROOTCMD shadowconfig on      $ROOTCMD shadowconfig on
234  }  }
235  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
236  call_debootstrap() {  call_debootstrap() {
237    
238      echo "Creating nfsroot for $1 using debootstrap"      # check if NFSROOT directory is mounted with bad options
239      [ "$verbose" ] && echo "Calling debootstrap $1 $NFSROOT $2"      fs=$(df $NFSROOT | tail -1 | awk '{print $6}')
240      yes '' | LC_ALL=C call_verbose debootstrap $FAI_DEBOOTSTRAP_OPTS $1 $NFSROOT $2 || true      if mount | grep "on $fs " |  awk '{print $6}' | egrep -q "nosuid|nodev"; then
241            die "NFSROOT directory $NFSROOT is mounted using nosuid or nodev. Aborting"
242        fi
243        local dversion=$(dpkg -l debootstrap | awk '/debootstrap/ {print $3}')
244        echo "Creating base system using debootstrap version $dversion"
245        echo "Calling debootstrap $1 $NFSROOT $2"
246        LC_ALL=C call_verbose debootstrap $FAI_DEBOOTSTRAP_OPTS $1 $NFSROOT $2
247        if [ $? -ne 0 ]; then
248            echo "ERROR: debootstrap did not complete successfully."
249            echo "This is mostly caused by a broken mirror."
250            echo "Please check your mirror or use an official mirror."
251            [ "$verbose" ] || echo "Call make-fai-nfsroot -v for better debugging."
252            exit 10
253        fi
254    
255        if [ ! -f $NFSROOT/usr/bin/apt-get ]; then
256            echo "No apt-get executable available inside the NFSROOT."
257            echo "Maybe debootstrap did not finish successfully. Aborting."
258            [ "$verbose" ] || echo "Call make-fai-nfsroot -v for better debugging."
259            exit 11
260        fi
261    }
262    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
263    add_all_host_entries() {
264    
265        local ips=$(ip addr | grep -w inet | cut -d t -f 2 | cut -d ' ' -f 2 | cut -d / -f 1 | grep -v 127.0.0.1)
266        for eth in $ips; do
267            getent hosts $eth >> etc/hosts || true
268        done
269  }  }
270  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
271  create_base() {  create_base() {
# Line 235  create_base() { Line 275  create_base() {
275          $ROOTCMD apt-get clean          $ROOTCMD apt-get clean
276          rm -f $NFSROOT/etc/resolv.conf          rm -f $NFSROOT/etc/resolv.conf
277          echo "Creating base.tgz"          echo "Creating base.tgz"
278          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 --exclude 'var/lib/apt/lists/*_*' . | gzip > $NFSROOT/var/tmp/base.tgz
279            touch $NFSROOT/.THIS_IS_THE_FAI_NFSROOT
280      else      else
281          die "\$FAI_DEBOOTSTRAP not defined."          die "\$FAI_DEBOOTSTRAP not defined."
282      fi      fi
# Line 244  create_base() { Line 285  create_base() {
285  create_nfsroot() {  create_nfsroot() {
286    
287      mkdir -p $NFSROOT/$FAI      mkdir -p $NFSROOT/$FAI
288      cd $NFSROOT || die "Error: Can't cd to $NFSROOT"      cd $NFSROOT || die "Can't cd to $NFSROOT"
289    
290      call_with_stamp create_base      call_with_stamp create_base
291      # save the list of all packages in the base.tgz      # save the list of all packages in the base.tgz
292      $ROOTCMD dpkg --get-selections | egrep 'install$' | awk '{print $1}' > var/tmp/base-pkgs.lis      $ROOTCMD dpkg --get-selections | awk '/install$/ {print $1}' > var/tmp/base-pkgs.lis
     echo $arch_packages > $NFSROOT/var/tmp/packages.arch  
293    
294      if [ "$FAI_DEBMIRROR" ]; then      if [ "$FAI_DEBMIRROR" ]; then
295          [ "$verbose" ] && echo "Mounting $FAI_DEBMIRROR to $NFSROOT/$MNTPOINT."          [ "$verbose" ] && echo "Mounting $FAI_DEBMIRROR to $NFSROOT/$MNTPOINT."
# Line 262  create_nfsroot() { Line 302  create_nfsroot() {
302      # liloconfig, dump and raidtool2 needs these files      # liloconfig, dump and raidtool2 needs these files
303      echo "# UNCONFIGURED FSTAB FOR BASE SYSTEM" > etc/fstab      echo "# UNCONFIGURED FSTAB FOR BASE SYSTEM" > etc/fstab
304      > etc/raidtab      > etc/raidtab
     mkdir -p lib/modules/$KERNELVERSION           # dirty trick to hoax lvm  
     >  lib/modules/$KERNELVERSION/modules.dep  # dirty trick to hoax lvm  
305      echo 'NTPSERVERS=""' > etc/default/ntp-servers      echo 'NTPSERVERS=""' > etc/default/ntp-servers
306    
307      [ -d $NFSROOT/var/state ] || mkdir $NFSROOT/var/state      cp -a $cfdir/apt $NFSROOT/etc
308      [ "$verbose" ] && echo "Try to copy $cfdir/sources.list or /etc/apt/sources.list."  
309      cp -v $cfdir/sources.list $NFSROOT/etc/apt/sources.list || \      ainsl -as $NFSROOT/etc/hosts "127.0.0.1 localhost"
310          cp -v /etc/apt/sources.list $NFSROOT/etc/apt/sources.list || \      ainsl     $NFSROOT/etc/hosts "$NFSROOT_ETC_HOSTS"
311          { echo "No sources.list file found."      add_all_host_entries
312            echo "I think something is wrong. But I'll try to continue."  
313          }      # we need these option before installing the first package. So we
314        # can't put this into fai-nfsroot /etc/apt/apt.conf.d/90fai
315      echo "127.0.0.1 localhost" >> etc/hosts      cat <<EOF >$NFSROOT/etc/apt/apt.conf.d/10fai
316      echo "$NFSROOT_ETC_HOSTS" >> etc/hosts  APT::Get::AllowUnauthenticated "true";
317      [ -f /etc/apt/preferences ] && cp -v /etc/apt/preferences $NFSROOT/etc/apt  Aptitude::CmdLine::Ignore-Trust-Violations yes;
318      [ -f $cfdir/preferences ] && cp -v $cfdir/preferences $NFSROOT/etc/apt  EOF
319      echo "Upgrading $NFSROOT"      echo "Upgrading $NFSROOT"
320      LC_ALL=C call_verbose call_with_stamp upgrade_nfsroot      LC_ALL=C call_verbose call_with_stamp upgrade_nfsroot
321      echo "Adding additional packages to $NFSROOT:"  
322      echo "$packages"      # overwrite default live.conf
323      LC_ALL=C call_verbose call_with_stamp add_packages_nfsroot      if [ -f $cfdir/live.conf ]; then
324            cp -p $cfdir/live.conf etc/live.conf
325        else
326            cat > etc/live.conf <<EOF
327    # UNIONTYPE=aufs # if unionfs is broken
328    NOUSER="Yes"
329    NOHOSTS="Yes"
330    export UNIONTYPE NOHOSTS NOUSER
331    EOF
332        fi
333    
334        LC_ALL=C call_with_stamp add_packages_nfsroot
335      call_with_stamp copy_fai_files      call_with_stamp copy_fai_files
336    
337      # set timezone in nfsroot      # set timezone in nfsroot
# Line 290  create_nfsroot() { Line 339  create_nfsroot() {
339      echo $timezone > etc/timezone      echo $timezone > etc/timezone
340      rm -f etc/localtime && ln -sf /usr/share/zoneinfo/$timezone etc/localtime      rm -f etc/localtime && ln -sf /usr/share/zoneinfo/$timezone etc/localtime
341    
342      # 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  
343      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  
     # 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  
344    
345      # definition for loopback device      # definition for loopback device
346      echo "iface lo inet loopback" > etc/network/interfaces      echo "iface lo inet loopback" > etc/network/interfaces
347    
     echo "*.* /tmp/fai/syslog.log" > etc/syslog.conf  
348      cat >> root/.profile <<-EOF      cat >> root/.profile <<-EOF
349          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:
350          export PATH          export PATH
351          . $SHAREFAI/subroutines          . /usr/lib/fai/subroutines
352          . $SHAREFAI/subroutines-$OS_TYPE          . /usr/lib/fai/subroutines-linux
353          set -a          set -a
354          . /tmp/fai/variables.sh 2>/dev/null          . /tmp/fai/variables.log 2>/dev/null
355  EOF  EOF
356    
357      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  
358  }  }
359  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
360  upgrade_nfsroot() {  upgrade_nfsroot() {
361    
362      cp -p $v /etc/resolv.conf $NFSROOT/etc/resolv.conf-installserver      if [ -f /etc/resolv.conf ]; then
363      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
364            cp -p $v /etc/resolv.conf $NFSROOT/etc/resolv.conf # this is needed during make-fai-nfsroot
365        fi
366        mount -t proc /proc $NFSROOT/proc
367        mount -t sysfs /sys $NFSROOT/sys
368        mount -t devpts devpts $NFSROOT/dev/pts
369      $ROOTCMD apt-get update      $ROOTCMD apt-get update
370      $ROOTCMD apt-get -fyu install      $ROOTCMD aptitude -Rfy install fai-nfsroot
371      $ROOTCMD apt-get check      $ROOTCMD apt-get check
372      rm -rf $NFSROOT/etc/apm      rm -rf $NFSROOT/etc/apm
     mount -t proc /proc $NFSROOT/proc  
373    
374      # fake start-stop-dameon      if [ $divert = 1 ]; then
375      fdivert /etc/init.d/rcS /sbin/start-stop-daemon /sbin/discover-modprobe          fdivert /usr/sbin/update-initramfs
376      cp /sbin/fai-start-stop-daemon $NFSROOT/sbin/          ln -s /bin/true $NFSROOT/usr/sbin/update-initramfs
377      ln -s /sbin/fai-start-stop-daemon $NFSROOT/sbin/start-stop-daemon      fi
378        fdivert /sbin/start-stop-daemon /sbin/discover-modprobe
379        cp -p /sbin/fai-start-stop-daemon $NFSROOT/sbin
380        cp -p /sbin/fai-start-stop-daemon $NFSROOT/sbin/start-stop-daemon
381      $ROOTCMD apt-get -y dist-upgrade      $ROOTCMD apt-get -y dist-upgrade
382  }  }
383  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
384  add_packages_nfsroot() {  add_packages_nfsroot() {
385    
386      $ROOTCMD apt-get -y --fix-missing install $packages </dev/null      local iarch=$($ROOTCMD dpkg --print-installation-architecture|tr /a-z/ /A-Z/)
387      if [ -n "$NFSROOT_PACKAGES" ] ; then      export FAI_ROOT=$NFSROOT
388          LC_ALL=C $ROOTCMD apt-get -y --fix-missing install $NFSROOT_PACKAGES </dev/null      export classes="NFSROOT $iarch"
389      fi  cat > $NFSROOT/etc/kernel-img.conf << EOF
390      $ROOTCMD apt-get clean  do_bootloader = No
391    do_initrd = No
392    warn_initrd = No
393    EOF
394        install_packages -l -p$cfdir > $NFSROOT/var/tmp/packages.nfsroot
395        echo "Adding additional packages to $NFSROOT:"
396        cat $NFSROOT/var/tmp/packages.nfsroot
397        call_verbose install_packages -N $v -p$cfdir
398        echo "install_packages exit code: $?"
399  }  }
400  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
401  umount_dirs() {  umount_dirs() {
402    
403      [ -f $NFSROOT/usr/sbin/dpkg-divert ] &&      [ -f $NFSROOT/usr/sbin/dpkg-divert ] &&
404         LC_ALL=C $ROOTCMD dpkg-divert --package fai --rename --remove /sbin/discover-modprobe         LC_ALL=C $ROOTCMD dpkg-divert --rename --remove /sbin/discover-modprobe
405      cd /      cd /
     sleep 2  
406      [ -d $NFSROOT/proc/self ] && umount $NFSROOT/proc      [ -d $NFSROOT/proc/self ] && umount $NFSROOT/proc
407      [ -d $NFSROOT/proc/self ] && umount $NFSROOT/dev/pts      [ -d $NFSROOT/sys/class ] && umount $NFSROOT/sys
408        [ -d $NFSROOT/proc/self ] && die "/proc still mounted inside the nfsroot."
409        umount $NFSROOT/dev/pts 2> /dev/null || true
410    
411      if [ "$FAI_DEBMIRROR" ]; then      if [ "$FAI_DEBMIRROR" ]; then
412          test -d $NFSROOT/$MNTPOINT && umount $NFSROOT/$MNTPOINT || true          test -d $NFSROOT/$MNTPOINT && umount $NFSROOT/$MNTPOINT || true
413      fi      fi
# Line 380  umount_dirs() { Line 415  umount_dirs() {
415      mount | grep " on $NFSROOT " || true      mount | grep " on $NFSROOT " || true
416  }  }
417  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 get_kernel_version() {  
   
     local package=$1  
     KERNELVERSION=`dpkg --info $package | grep "Package: kernel-image" | sed -e 's/.*kernel-image-'//`  
 }  
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
 setup_bootp(){  
   
     if [ -x "`which mkelf-linux`" ]; then  
         mkelf-linux --ip=any --output=/boot/fai/installimage \  
           $NFSROOT/boot/$kfile-$KERNELVERSION  
     else  
         echo "Command mkelf-linux not found. Can not set up BOOTP booting. Please install the package mknbi and rerun fai-setup."  
         return  
     fi  
   
     # imggen is free software from 3com - use ver1.00: 1.01 produces "Image too Big" errors.  
     # it converts netboot images to images which are bootable by 3com network cards  
     if [ -x "`which imggen`" ]; then  
         imggen -a /boot/fai/installimage /boot/fai/installimage_3com  
     fi  
     echo "BOOTP environment prepared."  
 }  
   
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
418  setup_dhcp(){  setup_dhcp(){
419    
420      # pxe and dhcp environment      # pxe and dhcp environment
421      local pxebin=/usr/lib/syslinux/pxelinux.0      local pxebin=/usr/lib/syslinux/pxelinux.0
422      cp -p $NFSROOT/boot/$kfile-$KERNELVERSION /boot/fai/$kfile-install      rm -f $NFSROOT/boot/*.bak
423      [ -f $pxebin ] && cp $pxebin /boot/fai      mkdir -p $TFTPROOT/pxelinux.cfg
424      [ -d /boot/fai/pxelinux.cfg ] || mkdir -p /boot/fai/pxelinux.cfg || true      cp -pv $NFSROOT/boot/vmlinu?-* $NFSROOT/boot/initrd.img-* $TFTPROOT
425        [ -f $pxebin ] && cp $pxebin $TFTPROOT
426      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."
427  }  }
428  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Line 419  fdivert() { Line 430  fdivert() {
430    
431      local item      local item
432      for item in "$@"; do      for item in "$@"; do
433          LC_ALL=C $ROOTCMD dpkg-divert --quiet --package fai --add --rename $item          LC_ALL=C $ROOTCMD dpkg-divert --quiet --add --rename $item
434      done      done
435  }  }
436  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
437  kernel_install() {  kernel_install() {
438    
439  # Install the kernel package  # Install the kernel package
 if [ -f $KERNELPACKAGE ]; then  
     # determine kernel version  
     get_kernel_version $KERNELPACKAGE  
440    
441      # create tftp boot images      # create tftp boot images
442      call_with_stamp install_kernel_nfsroot      call_with_stamp install_kernel_nfsroot
443    
444      # setup for DHCP, BOOTP or both      # setup for DHCP, BOOTP or both
445      [ "x$FAI_BOOT" = "x" ] && FAI_BOOT="dhcp bootp"      [ "x$FAI_BOOT" = "x" ] && FAI_BOOT="dhcp"
446    
447      for bootopt in $FAI_BOOT; do      for bootopt in $FAI_BOOT; do
448          case $bootopt in          case $bootopt in
449                  dhcp|DHCP)                  dhcp|DHCP)
450                          call_with_stamp setup_dhcp ;;                          call_with_stamp setup_dhcp ;;
451                  bootp|BOOTP)                  bootp|BOOTP)
452                          call_with_stamp setup_bootp ;;                          echo "You have to setup BOOTP support manually." ;;
453                  *)                  *)
454                          echo "Unknown boot option" ;;                          echo "Unknown boot option" ;;
455          esac          esac
456      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  
457  }  }
458  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
459    run_hooks() {
460    
461        local file
462        if [ -z "$NFSROOT_HOOKS" ]; then
463            return
464        fi
465        if [ -d "$NFSROOT_HOOKS"  ]; then
466            echo "Running hooks..."
467            for file in $(ls $NFSROOT_HOOKS/* 2>/dev/null); do
468                . $file
469            done
470        fi
471    }
472    # - - - - - - - - - - - - - - - - - - - - - - - - - -
473  # main routine  # main routine
474    
475    trap 'echo "Aborting";umount_dirs' EXIT
476    trap "bad_exit" ERR
477    {
478    
479  # remove all kernels from nfsroot  # remove all kernels from nfsroot
480  [ -n "$kremove" ] && {  [ -n "$kremove" ] && {
481      echo "Removing all kernels from NFSROOT."      echo "Removing all kernels from NFSROOT."
482      rm -f $NFSROOT/boot/{System.map,vmlinuz,config}*      $ROOTCMD aptitude -y purge ~nlinux-image
483      rm -rf $NFSROOT/lib/modules/2.*      exit
484  }  }
485    
486  # just install a new kernel to the nfsroot  # just install a new kernel to the nfsroot
487  [ -n "$kinstall" ] && {  [ -n "$kinstall" ] && {
488      trap "true" EXIT      trap "true" EXIT
489      echo "Installing new kernel into the nfsroot."      echo "Upgrading nfsroot and installing new packages into the nfsroot."
490        if [ $divert = 1 ]; then
491            fdivert /usr/sbin/update-initramfs
492            ln -s /bin/true $NFSROOT/usr/sbin/fai
493        fi
494        $ROOTCMD apt-get update
495        $ROOTCMD apt-get -y dist-upgrade
496        LC_ALL=C add_packages_nfsroot
497      kernel_install      kernel_install
498      echo "New kernel from $KERNELPACKAGE installed into the nfsroot."      run_hooks
499      exit      umount_dirs
500        trap "true" EXIT
501        echo "make-fai-nfsroot finished $merror."
502        exit 0
503  }  }
504    
505  echo Creating FAI nfsroot can take a long time and will  echo "Creating FAI nfsroot in $NFSROOT."
506  echo need more than $nfssize disk space in $NFSROOT.  echo "By default it needs more than 390 MBytes disk space."
507    echo "This may take a long time."
508    
509    if [ $sshpreserve = 1 ]; then
510        # save old .ssh directory
511        tmptar=$(mktemp) || exit 12
512        # should we set the umask before? Does it influence the other parts?
513        tar -C $NFSROOT -cvf $tmptar root/.ssh
514    fi
515    
516  # Kill the directory if not in recover mode  # Kill the directory if not in recover mode
517  if [ -d $NFSROOT/$FAI -a ! "$recover" ]  if [ -d $NFSROOT/proc -a ! "$recover" ]
518  then  then
519      echo $NFSROOT already exists. Removing $NFSROOT      echo $NFSROOT already exists. Removing $NFSROOT
520      umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true      umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true
521      rm -rf $NFSROOT/.??* $NFSROOT/*      [ -L $NFSROOT/proc/self ] && umount $NFSROOT/proc || true
522        [ -L $NFSROOT/proc/self ] && die "/proc is still mounted inside the nfsroot."
523        umount $NFSROOT/$MNTPOINT  2>/dev/null || true # it's safer to try to umount
524        rm -rf $oldnfsroot/.??* $oldnfsroot/*
525      # also remove files $NFSROOT/.? but not . and ..      # also remove files $NFSROOT/.? but not . and ..
526      find $NFSROOT ! -type d -xdev -maxdepth 1 | xargs -r rm -f      find $oldnfsroot -xdev -maxdepth 1 ! -type d | xargs -r rm -f
527  fi  fi
528    
529  # Create a new nfsroot  # Create a new nfsroot
530    if [ ! -x "$(which debootstrap)" ]; then
531        die "Can't find debootstrap command. Aborting."
532    fi
533  call_with_stamp create_nfsroot  call_with_stamp create_nfsroot
534    
535  kernel_install  kernel_install
536    run_hooks
537    check_nfsroot
538  umount_dirs  umount_dirs
 trap "true" EXIT  
539  echo "make-fai-nfsroot finished $merror."  echo "make-fai-nfsroot finished $merror."
540  exit 0  exit 0
541    } 2>&1 | tee /var/log/fai/make-fai-nfsroot.log
542    umount_dirs
543    trap "true" EXIT
544    echo "Log file written to /var/log/fai/make-fai-nfsroot.log"

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

  ViewVC Help
Powered by ViewVC 1.1.5