/[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 2478 by lange, Sat Oct 23 22:25:21 2004 UTC trunk/bin/make-fai-nfsroot revision 4743 by lange, Wed Nov 14 21:12:08 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-2004 by Thomas Lange, lange@informatik.uni-koeln.de  # (c) 2000-2007 by Thomas Lange, lange@informatik.uni-koeln.de
10  # Universitaet zu Koeln  # Universitaet zu Koeln
11  #  #
12  #*********************************************************************  #*********************************************************************
# Line 24  Line 24 
24  # `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution  # `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution
25  # or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html.  You  # or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html.  You
26  # can also obtain it by writing to the Free Software Foundation, Inc.,  # can also obtain it by writing to the Free Software Foundation, Inc.,
27  # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
28  #*********************************************************************  #*********************************************************************
29    
30    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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    check_nfsroot() {
52    
53        set +e
54        # simple test, to see if important thing are available inside the nfsroot
55        [ -d $NFSROOT/usr/share/live-initramfs ] || die "live-initramfs is not installed."
56        local files=$(ls $NFSROOT/boot/initrd* 2>/dev/null)
57        [ -z "$files" ] && die "No initrd installed."
58        return 0
59    }
60    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
61    badupdateto32() {
62    
63        cat <<-EOF
64            It seems that you have updated an older FAI version without checking files in /etc/fai/
65            Please check the NEWS file for changes in variable names and if you have a linux-image package
66            defined in /etc/fai/NFSROOT.
67    EOF
68        die $@
69    }
70    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
71    
72  PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin  PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin
73    
74  if [ `id -u` -ne 0 ]; then  kfile="vmlinuz" # some architectures use different names
75      echo "Run this program as root."  merror="properly"
76      exit 9  sshpreserve=0
77    divert=1
78    
79    if [ -f /etc/lsb-release ]; then
80        . /etc/lsb-release
81        case "$DISTRIB_ID" in
82            Ubuntu) divert=0 ;;
83        esac
84  fi  fi
85    
 merror="properly"  
86  # option e currently does nothing  # option e currently does nothing
87  while getopts ervc:f:kK opt ; do  while getopts hervC:f:kKpU opt ; do
88      case "$opt" in      case "$opt" in
89          c) cfdir=$OPTARG ;;          C) cfdir=$OPTARG ;;
90          v) verbose=1 ; v=-v ;;          v) verbose=1 ; v=-v ;;
91          r) recover=1 ;;          r) recover=1 ;;
92          f) cfg=$OPTARG ;;          f) die "Option -f is not supported any more. Use option -C instead" ;;
93          k) kinstall=1 ;;          k) kinstall=1 ;;
94          K) kremove=1; kinstall=1 ;;          K) kremove=1;;
95          e) expert=1 ;;          h) usage ;;
96            e) expert=1 ;; # a dummy option, that only fai-setup uses
97            p) sshpreserve=1 ;;
98            U) divert=0 ;;
99          ?) exit 5 ;; # error in option parsing          ?) exit 5 ;; # error in option parsing
100      esac      esac
101  done  done
102    
103    if [ $(id -u) != "0" ]; then
104        echo "Run this program as root."
105        exit 9
106    fi
107    
108    { # start of block which output will be written to log file
109    
110  set -e  set -e
111    
112  [ -z "$cfdir" ] && cfdir=/etc/fai  # use FAI_ETC_DIR from environment variable
113    if [ -n "$FAI_ETC_DIR" -a -z "$cfdir" ]; then
114        echo "Using environment variable \$FAI_ETC_DIR."
115    fi
116    [ -z "$cfdir" ] && cfdir=${FAI_ETC_DIR:=/etc/fai}
117    cfdir=$(readlink -f $cfdir) # canonicalize path
118  if [ ! -d "$cfdir" ]; then  if [ ! -d "$cfdir" ]; then
119      echo "$cfdir is not a directory"      echo "$cfdir is not a directory"
120      exit 6      exit 6
121  fi  fi
122  [ "$verbose" ] && echo "Using configuration files from directory $cfdir"  [ "$verbose" ] && echo "Using configuration files from $cfdir"
123  if [ -n "$cfg" ]; then  . $cfdir/fai.conf
     . $cfdir/$cfg  
 else  
     . $cfdir/fai.conf  
 fi  
124    
125  # read config file for this tool  # read config file for this tool
126  if [ -f "$cfdir/make-fai-nfsroot.conf" ]; then  if [ -f "$cfdir/make-fai-nfsroot.conf" ]; then
# Line 72  else Line 130  else
130      exit 8      exit 8
131  fi  fi
132    
133  if [ -z "$NFSROOT" ]; then  # IMO this may be removed, since all information should be included into sources.list
134      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."
135      exit 4  [ -n "$packages" ] && badupdateto32 "The use of \$packages in make-fai-nfsroot.conf is now deprecated. Please include this information into $cfdir/NFSROOT."
136  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."
137    [ -n "$FAI_SOURCES_LIST" ] && die "The use of \$FAI_SOURCES_LIST is deprecated. Please use sources.list now."
138    
139    [ -z "$NFSROOT" ] && die "\$NFSROOT is not set. Please check your settings in $cfdir/fai.conf."
140    [ -z "$TFTPROOT" ] && badupdateto32 "\$TFTPROOT is not set. Please check your settings in $cfdir/make-fai-nfsroot.conf."
141    [ -n "$KERNELPACKAGE" ] && badupdateto32 "The use of \$KERNELPACKAGE is deprecated. Please use $cfdir/NFSROOT now."
142    [ ! -d "$cfdir/apt" ] && die "$cfdir/apt/ does not exists. Can't continue."
143    
144  if [ "$FAI_SOURCES_LIST" ]; then  oldnfsroot=$NFSROOT
145      echo "The usage of the variable \$FAI_SOURCES_LIST is deprecated. Please use sources.list now."  NFSROOT="$NFSROOT/live/filesystem.dir"
     exit 3  
 fi  
   
 if [ ! -s "$cfdir/sources.list" -a ! -f /etc/apt/sources.list ]; then  
     echo "Neither $cfdir/sources.list nor /etc/apt/sources.list exists."  
     echo "I think something is wrong. Can't continue."  
     exit 7  
 fi  
   
 kfile="vmlinuz"  
 case `uname -m` in  
     i386|i486|i586|i686|amd64)  
         arch_packages="grub lilo read-edid kudzu hwtools dmidecode" ;;  
   
     ia64)  
         arch_packages="elilo gnu-efi efibootmgr" ;;  
   
     sparc|sparc64)  
         arch_packages="silo sparc-utils" ;;  
   
     ppc)  
         arch_packages=""  
         kfile="vmlinux" ;;  
   
     alpha)  
         arch_packages="aboot" ;;  
   
     *)  arch_packages="" ;;  
 esac  
 packages="$packages  
 $arch_packages"  
   
146  ROOTCMD="chroot $NFSROOT"  ROOTCMD="chroot $NFSROOT"
147    
148  RUNDIR=/var/run/fai/make-fai-nfsroot  RUNDIR=/var/run/fai/make-fai-nfsroot
149  [ ! -d $RUNDIR ] && mkdir -p $RUNDIR  mkdir -p $RUNDIR
 LIBFAI=/usr/lib/fai  
 SHAREFAI=/usr/share/fai  
150  export DEBIAN_FRONTEND=noninteractive  export DEBIAN_FRONTEND=noninteractive
151  [ "$recover" ] || rm -rf $RUNDIR/*  [ "$recover" ] || rm -rf $RUNDIR/*
152    
153  trap "umount_dirs" EXIT  trap 'echo "Aborting";umount_dirs' EXIT
154  trap "bad_exit" ERR  trap "bad_exit" ERR
155  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
156  bad_exit() {  bad_exit() {
# Line 130  bad_exit() { Line 160  bad_exit() {
160      echo "Please fix the error or try make-fai-nfsroot -v"      echo "Please fix the error or try make-fai-nfsroot -v"
161  }  }
162  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 die() {  
   
     echo "$@"  
     exit 99  
 }  
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
163  call_with_stamp() {  call_with_stamp() {
164    
165      local func=$1      local func=$1
166      local stamp=$RUNDIR/$func      local stamp=$RUNDIR/$func
167      # call subroutine      # call subroutine
168      [ "$recover" -a -f $stamp ] && return 0      [ "$recover" -a -f $stamp ] && return 0
169      "$@"      # make a stamp only on success.
170      > $stamp      "$@" && : > $stamp
171  }  }
172  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
173  call_verbose() {  call_verbose() {
174    
175      if [ "$verbose" ]; then      if [ "$verbose" ]; then
176          "$@"          "$@"
177            return $?
178      else      else
179          "$@" > /dev/null          "$@" > /dev/null
180            return $?
181      fi      fi
182  }  }
183  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
184  install_kernel_nfsroot() {  install_kernel_nfsroot() {
185    
186      rm -rf $NFSROOT/boot/*-$KERNELVERSION $NFSROOT/lib/modules/$KERNELVERSION      if [ $divert = 1 ]; then
187      # since woody we can install the kernel using dpkg -i          rm $NFSROOT/usr/sbin/update-initramfs
188      echo "do_boot_enable=no" > $NFSROOT/etc/kernel-img.conf          LC_ALL=C $ROOTCMD dpkg-divert --rename --remove /usr/sbin/update-initramfs
189      dpkg -x $KERNELPACKAGE $NFSROOT          $ROOTCMD update-initramfs -k all -t -u
190      # 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  
191  }  }
192  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
193  setup_ssh() {  setup_ssh() {
194    
195      # nothing to do if no ssh is available in nfsroot      # nothing to do if no ssh is available in nfsroot
196      [ -f $NFSROOT/var/lib/dpkg/info/ssh.list ] || return 0      [ -f $NFSROOT/usr/bin/ssh ] || return 0
197        if [ $sshpreserve = 1 ]; then
198            tar -C $NFSROOT -xf $tmptar
199            rm $tmptar
200            return 0
201        fi
202    
203      mkdir -p -m 700 $NFSROOT/root/.ssh      mkdir -p -m 700 $NFSROOT/root/.ssh
204      if [ -n "$LOGUSER" ] ; then      if [ -n "$LOGUSER" ] ; then
205          loguserhome=`eval "cd ~$LOGUSER 2>/dev/null && pwd;true"`          loguserhome=$(eval "cd ~$LOGUSER 2>/dev/null && pwd;true")
     # is copying of *.pub important?  
206          [ -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
207          [ -d $loguserhome/.ssh ] && {          [ -d $loguserhome/.ssh ] && {
208              [ -f $loguserhome/.ssh/id_dsa ] &&              [ -f $loguserhome/.ssh/id_dsa ] &&
209                 cp -p $loguserhome/.ssh/id_dsa* $NFSROOT/root/.ssh/                 cp -p $loguserhome/.ssh/id_dsa* $NFSROOT/root/.ssh/
210              [ -f $loguserhome/.ssh/id_rsa ] &&              [ -f $loguserhome/.ssh/id_rsa ] &&
211                 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/  
212          }          }
213      fi      fi
214    
# Line 198  setup_ssh() { Line 224  setup_ssh() {
224  copy_fai_files() {  copy_fai_files() {
225    
226      # copy to nfsroot      # copy to nfsroot
227      perl -pi -e "s#^root::#root:${FAI_ROOTPW}:#" etc/passwd      echo "root:$FAI_ROOTPW" | $ROOTCMD chpasswd --encrypted
     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  
228      cp -Rpv $cfdir/* $NFSROOT/etc/fai      cp -Rpv $cfdir/* $NFSROOT/etc/fai
229        # append additional variables to fai.conf for the install clients
230        [ -z "$FAI_CONFIG_SRC" ] && echo "FAI_CONFIG_SRC=nfs://`hostname`$FAI_CONFIGDIR" >> $NFSROOT/etc/fai/fai.conf
231    
232        # remove some files that should not be copied
233      rm -f $NFSROOT/etc/fai/make-fai-nfsroot.conf      rm -f $NFSROOT/etc/fai/make-fai-nfsroot.conf
234      [ -f $cfdir/.cvspass ] && cp -p $v $cfdir/.cvspass $NFSROOT/.cvspass      [ -f $cfdir/.cvspass ] && cp -p $v $cfdir/.cvspass $NFSROOT/.cvspass
235      cp -p $LIBFAI/sbin/* sbin/      $ROOTCMD shadowconfig on
     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} 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/  
     $ROOTCMD pwconv # enable shadow  
236  }  }
237  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
238  call_debootstrap() {  call_debootstrap() {
239    
240      echo "Creating nfsroot for $1 using debootstrap"      local dversion=$(dpkg -l debootstrap | grep debootstrap | cut -f7 -d' ')
241      [ "$verbose" ] && echo "Calling debootstrap $1 $NFSROOT $2"      echo "Creating base system using debootstrap version $dversion"
242      yes '' | LC_ALL=C call_verbose debootstrap $FAI_DEBOOTSTRAP_OPTS $1 $NFSROOT $2 || true      echo "Calling debootstrap $1 $NFSROOT $2"
243        yes '' | LC_ALL=C call_verbose debootstrap $FAI_DEBOOTSTRAP_OPTS $1 $NFSROOT $2
244    }
245    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
246    add_all_host_entries() {
247    
248        local ips=$(ifconfig | grep -w inet | cut -d : -f 2 | cut -d ' ' -f 1 | grep -v 127.0.0.1)
249        for eth in $ips; do
250            getent hosts $eth >> etc/hosts || true
251        done
252  }  }
253  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
254  create_base() {  create_base() {
# Line 231  create_base() { Line 256  create_base() {
256      if [ "$FAI_DEBOOTSTRAP" ]; then      if [ "$FAI_DEBOOTSTRAP" ]; then
257          call_with_stamp call_debootstrap $FAI_DEBOOTSTRAP          call_with_stamp call_debootstrap $FAI_DEBOOTSTRAP
258          $ROOTCMD apt-get clean          $ROOTCMD apt-get clean
259            rm -f $NFSROOT/etc/resolv.conf
260          echo "Creating base.tgz"          echo "Creating base.tgz"
261          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
262            touch $NFSROOT/.THIS_IS_THE_FAI_NFSROOT
263      else      else
264          die "\$FAI_DEBOOTSTRAP not defined."          die "\$FAI_DEBOOTSTRAP not defined."
265      fi      fi
# Line 241  create_base() { Line 268  create_base() {
268  create_nfsroot() {  create_nfsroot() {
269    
270      mkdir -p $NFSROOT/$FAI      mkdir -p $NFSROOT/$FAI
271      cd $NFSROOT || die "Error: Can't cd to $NFSROOT"      cd $NFSROOT || die "Can't cd to $NFSROOT"
272    
273      call_with_stamp create_base      call_with_stamp create_base
274        # save the list of all packages in the base.tgz
275        $ROOTCMD dpkg --get-selections | egrep 'install$' | awk '{print $1}' > var/tmp/base-pkgs.lis
276    
277      if [ "$FAI_DEBMIRROR" ]; then      if [ "$FAI_DEBMIRROR" ]; then
278          [ "$verbose" ] && echo "Mounting $FAI_DEBMIRROR to $NFSROOT/$MNTPOINT."          [ "$verbose" ] && echo "Mounting $FAI_DEBMIRROR to $NFSROOT/$MNTPOINT."
# Line 256  create_nfsroot() { Line 285  create_nfsroot() {
285      # liloconfig, dump and raidtool2 needs these files      # liloconfig, dump and raidtool2 needs these files
286      echo "# UNCONFIGURED FSTAB FOR BASE SYSTEM" > etc/fstab      echo "# UNCONFIGURED FSTAB FOR BASE SYSTEM" > etc/fstab
287      > etc/raidtab      > etc/raidtab
     mkdir -p lib/modules/$KERNELVERSION           # dirty trick to hoax lvm  
     >  lib/modules/$KERNELVERSION/modules.dep  # dirty trick to hoax lvm  
288      echo 'NTPSERVERS=""' > etc/default/ntp-servers      echo 'NTPSERVERS=""' > etc/default/ntp-servers
289    
290      [ -d $NFSROOT/var/state ] || mkdir $NFSROOT/var/state      # live.conf will set hostname to debian
291      [ "$verbose" ] && echo "Try to copy $cfdir/sources.list or /etc/apt/sources.list."      cp /dev/null etc/live.conf
292      cp -v $cfdir/sources.list $NFSROOT/etc/apt/sources.list || \  
293          cp -v /etc/apt/sources.list $NFSROOT/etc/apt/sources.list || \      cp -a $cfdir/apt $NFSROOT/etc
294          { echo "No sources.list file found."  
295            echo "I think something is wrong. But I'll try to continue."      ainsl -as $NFSROOT/etc/hosts "127.0.0.1 localhost"
296          }      ainsl     $NFSROOT/etc/hosts "$NFSROOT_ETC_HOSTS"
297        add_all_host_entries
298      echo "127.0.0.1 localhost" >> etc/hosts  
299      echo "$NFSROOT_ETC_HOSTS" >> etc/hosts      # we need these option before installing the first package. So we
300      [ -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
301      [ -f $cfdir/preferences ] && cp -v $cfdir/preferences $NFSROOT/etc/apt      cat <<EOF >$NFSROOT/etc/apt/apt.conf.d/10fai
302    APT::Get::AllowUnauthenticated "true";
303    Aptitude::CmdLine::Ignore-Trust-Violations yes;
304    EOF
305      echo "Upgrading $NFSROOT"      echo "Upgrading $NFSROOT"
306      LC_ALL=C call_verbose call_with_stamp upgrade_nfsroot      LC_ALL=C call_verbose call_with_stamp upgrade_nfsroot
307      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  
308      call_with_stamp copy_fai_files      call_with_stamp copy_fai_files
309    
310      # set timezone in nfsroot      # set timezone in nfsroot
# Line 284  create_nfsroot() { Line 312  create_nfsroot() {
312      echo $timezone > etc/timezone      echo $timezone > etc/timezone
313      rm -f etc/localtime && ln -sf /usr/share/zoneinfo/$timezone etc/localtime      rm -f etc/localtime && ln -sf /usr/share/zoneinfo/$timezone etc/localtime
314    
315      # make little changes to nfsroot, because nfsroot is      rm etc/mtab && ln -s /proc/mounts etc/mtab
316      # read only for the install clients      ln -s /usr/sbin/fai etc/init.d/rcS
     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 -s /tmp/etc/syslogsocket dev/log  
     ln -sf /tmp/etc/resolv.conf etc/resolv.conf  
     ln -sf /tmp etc/sysconfig  
     ln -s ../../sbin/rcS_fai etc/init.d/rcS  
     ln -sf /dev/null etc/network/ifstate  
317      # for nis      # for nis
318      [ -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  
319    
320      # definition for loopback device      # definition for loopback device
321      echo "iface lo inet loopback" > etc/network/interfaces      echo "iface lo inet loopback" > etc/network/interfaces
322    
     echo "*.* /tmp/fai/syslog.log" > etc/syslog.conf  
323      cat >> root/.profile <<-EOF      cat >> root/.profile <<-EOF
324          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:
325          export PATH          export PATH
326          . $SHAREFAI/subroutines          . /usr/lib/fai/subroutines
327          . $SHAREFAI/subroutines-$OS_TYPE          . /usr/lib/fai/subroutines-linux
328          set -a          set -a
329          . /tmp/fai/variables.sh 2>/dev/null          . /tmp/fai/variables.log 2>/dev/null
330  EOF  EOF
331    
332      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  
333  }  }
334  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
335  upgrade_nfsroot() {  upgrade_nfsroot() {
336    
337      cp -p $v /etc/resolv.conf $NFSROOT/etc/resolv.conf-installserver      if [ -f /etc/resolv.conf ]; then
338            cp -p $v /etc/resolv.conf $NFSROOT/etc/resolv.conf-installserver
339            cp -p $v /etc/resolv.conf $NFSROOT/etc/resolv.conf # this is needed during make-fai-nfsroot
340        fi
341      $ROOTCMD apt-get update      $ROOTCMD apt-get update
342      $ROOTCMD apt-get -fyu install      $ROOTCMD apt-get -fy install fai-nfsroot
343      $ROOTCMD apt-get check      $ROOTCMD apt-get check
344      rm -rf $NFSROOT/etc/apm      rm -rf $NFSROOT/etc/apm
345      mount -t proc /proc $NFSROOT/proc      mount -t proc /proc $NFSROOT/proc
346    
347      # fake start-stop-dameon      if [ $divert = 1 ]; then
348      fdivert /etc/init.d/rcS /sbin/start-stop-daemon /sbin/discover-modprobe          fdivert /usr/sbin/update-initramfs
349      cp /sbin/fai-start-stop-daemon $NFSROOT/sbin/          ln -s /bin/true $NFSROOT/usr/sbin/update-initramfs
350      ln -s /sbin/fai-start-stop-daemon $NFSROOT/sbin/start-stop-daemon      fi
351        fdivert /sbin/start-stop-daemon /sbin/discover-modprobe
352        cp -p /sbin/fai-start-stop-daemon $NFSROOT/sbin
353        cp -p /sbin/fai-start-stop-daemon $NFSROOT/sbin/start-stop-daemon
354      $ROOTCMD apt-get -y dist-upgrade      $ROOTCMD apt-get -y dist-upgrade
355  }  }
356  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
357  add_packages_nfsroot() {  add_packages_nfsroot() {
358    
359      $ROOTCMD apt-get -y --fix-missing install $packages </dev/null      local iarch=$($ROOTCMD dpkg --print-installation-architecture|tr /a-z/ /A-Z/)
360      if [ -n "$NFSROOT_PACKAGES" ] ; then      export FAI_ROOT=$NFSROOT
361          LC_ALL=C $ROOTCMD apt-get -y --fix-missing install $NFSROOT_PACKAGES </dev/null      export classes="NFSROOT $iarch"
362      fi  cat > $NFSROOT/etc/kernel-img.conf << EOF
363      $ROOTCMD apt-get clean  do_bootloader = No
364    do_initrd = No
365    warn_initrd = No
366    EOF
367        install_packages -l -p$cfdir > $NFSROOT/var/tmp/packages.nfsroot
368        echo "Adding additional packages to $NFSROOT:"
369        cat $NFSROOT/var/tmp/packages.nfsroot
370        call_verbose install_packages $v -p$cfdir
371        echo "install_packages exit code: $?"
372  }  }
373  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
374  umount_dirs() {  umount_dirs() {
375    
376      [ -f $NFSROOT/usr/sbin/dpkg-divert ] &&      [ -f $NFSROOT/usr/sbin/dpkg-divert ] &&
377         LC_ALL=C $ROOTCMD dpkg-divert --package fai --rename --remove /sbin/discover-modprobe         LC_ALL=C $ROOTCMD dpkg-divert --rename --remove /sbin/discover-modprobe
378      cd /      cd /
     sleep 2  
379      [ -d $NFSROOT/proc/self ] && umount $NFSROOT/proc      [ -d $NFSROOT/proc/self ] && umount $NFSROOT/proc
380      [ -d $NFSROOT/proc/self ] && umount $NFSROOT/dev/pts      [ -d $NFSROOT/proc/self ] && umount $NFSROOT/dev/pts
381      if [ "$FAI_DEBMIRROR" ]; then      if [ "$FAI_DEBMIRROR" ]; then
# Line 375  umount_dirs() { Line 388  umount_dirs() {
388  get_kernel_version() {  get_kernel_version() {
389    
390      local package=$1      local package=$1
391      KERNELVERSION=`dpkg --info $package | grep "Package: kernel-image" | sed -e 's/.*kernel-image-'//`  
392        KERNELVERSION=`dpkg --info $package | grep ' Package: '`
393        KERNELVERSION=${KERNELVERSION/*-image-/}
394  }  }
395  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
396  setup_bootp(){  setup_bootp(){
397    
398      if [ -x "`which mkelf-linux`" ]; then      mkdir -p $TFTPROOT
399          mkelf-linux --ip=any --output=/boot/fai/installimage \      if [ -x "$(which mkelf-linux)" ]; then
400            $NFSROOT/boot/$kfile-$KERNELVERSION          # does not work any mork if we do not know the excatly kernel name
401    :
402    #       mkelf-linux --ip=any --output=$TFTPROOT/installimage \
403    #         $NFSROOT/boot/$kfile-$KERNELVERSION
404      else      else
405          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."
406          return          return
# Line 390  setup_bootp(){ Line 408  setup_bootp(){
408    
409      # 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.
410      # 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
411      if [ -x "`which imggen`" ]; then      if [ -x "$(which imggen)" ]; then
412          imggen -a /boot/fai/installimage /boot/fai/installimage_3com          imggen -a $TFTPROOT/installimage $TFTPROOT/installimage_3com
413      fi      fi
414      echo "BOOTP environment prepared."      echo "BOOTP environment prepared."
415  }  }
# Line 401  setup_dhcp(){ Line 419  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/$kfile-* $TFTPROOT
425        cp -pv $NFSROOT/boot/initrd.img-* $TFTPROOT
426        [ -f $pxebin ] && cp $pxebin $TFTPROOT
427      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."
428  }  }
429  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
430  fdivert() {  fdivert() {
431    
432        local item
433      for item in "$@"; do      for item in "$@"; do
434          LC_ALL=C $ROOTCMD dpkg-divert --quiet --package fai --add --rename $item          LC_ALL=C $ROOTCMD dpkg-divert --quiet --add --rename $item
435      done      done
436  }  }
437  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
438  kernel_install() {  kernel_install() {
439    
440  # Install the kernel package  # Install the kernel package
 if [ -f $KERNELPACKAGE ]; then  
     # determine kernel version  
     get_kernel_version $KERNELPACKAGE  
441    
442      # create tftp boot images      # create tftp boot images
443      call_with_stamp install_kernel_nfsroot      call_with_stamp install_kernel_nfsroot
# Line 437  if [ -f $KERNELPACKAGE ]; then Line 455  if [ -f $KERNELPACKAGE ]; then
455                          echo "Unknown boot option" ;;                          echo "Unknown boot option" ;;
456          esac          esac
457      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  
458  }  }
459  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
460    run_hooks() {
461    
462        local file
463        if [ -z "$NFSROOT_HOOKS" ]; then
464            return
465        fi
466        if [ -d "$NFSROOT_HOOKS"  ]; then
467            echo "Running hooks..."
468            for file in $(ls $NFSROOT_HOOKS/* 2>/dev/null); do
469                . $file
470            done
471        fi
472    }
473    # - - - - - - - - - - - - - - - - - - - - - - - - - -
474  # main routine  # main routine
475    
476  # remove all kernels from nfsroot  # remove all kernels from nfsroot
477  [ -n "$kremove" ] && {  [ -n "$kremove" ] && {
478      echo "Removing all kernels from NFSROOT."      echo "Removing all kernels from NFSROOT."
479      rm -f $NFSROOT/boot/{System.map,vmlinuz,config}*      $ROOTCMD aptitude -y purge ~nlinux-image
480      rm -rf $NFSROOT/lib/modules/2.*      exit
481  }  }
482    
483  # just install a new kernel to the nfsroot  # just install a new kernel to the nfsroot
484  [ -n "$kinstall" ] && {  [ -n "$kinstall" ] && {
485      trap "true" EXIT      trap "true" EXIT
486      echo "Installing new kernel into the nfsroot."      echo "Installing new kernel into the nfsroot."
487        if [ $divert = 1 ]; then
488            fdivert /usr/sbin/update-initramfs
489            ln -s /bin/true $NFSROOT/usr/sbin/fai
490        fi
491        LC_ALL=C add_packages_nfsroot
492      kernel_install      kernel_install
493      echo "New kernel from $KERNELPACKAGE installed into the nfsroot."      run_hooks
494      exit      umount_dirs
495        trap "true" EXIT
496        echo "make-fai-nfsroot finished $merror."
497        exit 0
498  }  }
499    
500  echo Creating FAI nfsroot can take a long time and will  echo "Creating FAI nfsroot in $NFSROOT."
501  echo need more than $nfssize disk space in $NFSROOT.  echo "By default it needs more than 330 MBytes disk space."
502    echo "This may take a long time."
503    
504    if [ $sshpreserve = 1 ]; then
505        # save old .ssh directory
506        tmptar=$(mktemp) || exit 12
507        # should we set the umask before? Does it influence the other parts?
508        tar -C $NFSROOT -cvf $tmptar root/.ssh
509    fi
510    
511  # Kill the directory if not in recover mode  # Kill the directory if not in recover mode
512  if [ -d $NFSROOT/$FAI -a ! "$recover" ]  if [ -d $NFSROOT/$FAI -a ! "$recover" ]
513  then  then
514      echo $NFSROOT already exists. Removing $NFSROOT      echo $NFSROOT already exists. Removing $NFSROOT
515      umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true      umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true
516      rm -rf $NFSROOT/.??* $NFSROOT/*      rm -rf $oldnfsroot/.??* $oldnfsroot/*
517      # also remove files $NFSROOT/.? but not . and ..      # also remove files $NFSROOT/.? but not . and ..
518      find $NFSROOT ! -type d -xdev -maxdepth 1 | xargs -r rm -f      find $oldnfsroot -xdev -maxdepth 1 ! -type d | xargs -r rm -f
519  fi  fi
520    
521  # Create a new nfsroot  # Create a new nfsroot
522    if [ ! -x "$(which debootstrap)" ]; then
523        die "Can't find debootstrap command. Aborting."
524    fi
525  call_with_stamp create_nfsroot  call_with_stamp create_nfsroot
526    
527  kernel_install  kernel_install
528    run_hooks
529    check_nfsroot
530  umount_dirs  umount_dirs
531  trap "true" EXIT  trap "true" EXIT
532  echo "make-fai-nfsroot finished $merror."  echo "make-fai-nfsroot finished $merror."
533  exit 0  exit 0
534    } 2>&1 | tee /var/log/fai/make-fai-nfsroot.log
535    echo "Log file written to /var/log/fai/make-fai-nfsroot.log"

Legend:
Removed from v.2478  
changed lines
  Added in v.4743

  ViewVC Help
Powered by ViewVC 1.1.5