/[fai]/trunk/scripts/make-fai-nfsroot
ViewVC logotype

Diff of /trunk/scripts/make-fai-nfsroot

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 44 by lange, Fri Jul 7 12:59:26 2000 UTC revision 691 by lange, Fri Jul 13 13:10:03 2001 UTC
# Line 1  Line 1 
1  #! /bin/sh -xv  #! /bin/sh
2    
3  # $Id$  # $Id$
4  #*********************************************************************  #*********************************************************************
# Line 6  Line 6 
6  # make-fai-nfsroot -- create nfsroot directory and add additional packages  # make-fai-nfsroot -- create nfsroot directory and add additional packages
7  #  #
8  # This script is part of FAI (Fully Automatic Installation)  # This script is part of FAI (Fully Automatic Installation)
9  # (c) 2000 by Thomas Lange, lange@informatik.uni-koeln.de  # (c) 2000-2001 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  # Thomas Lange, Universitaet Koeln, 7/2000  # Packages that are install to nfsroot by default
31    # Additional packages are defined with $NFSROOT_PACKAGES in fai.conf
32    packages="dhcp-client file rdate cfengine bootpc wget rsh-client less dump ext2resize strace hdparm parted dnsutils grub ntpdate psmisc"
33    
34    PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
35    
36    if [ "$UID" -ne 0 ]; then
37     echo "Run this program as root."
38     exit 9
39    fi
40    
41    while getopts v opt ; do
42            case "$opt" in
43            v) verbose=1 ;;
44            esac
45    done
46    
47    set -e
48    . /etc/fai.conf
49    packages="$packages $NFSROOT_PACKAGES"
50    ROOTCMD="chroot $NFSROOT"
51    
52  # configuration of some packages will need some interactive input  LIBFAI=/usr/lib/fai
53  # lilo, netbase,... will not be set up correctly, but that doesn't matter  conffile=$NFSROOT/etc/rcS_fai.conf
 # apt-get must been working on your server (sources.list must be OK)  
   
 PATH=/bin:/sbin:/usr/bin:/usr/sbin  
   
 rootpw="56hNVqht51tzc"  
 url=ftp://ftp.debian.org/debian   # format for http or ftp  
 #url=/mnt   # format for a mounted directory  
 dversion=2_2  
 dname=potato  
 verbose=1  
 # Additional packages that are install to nfsroot  
 packages="debconf file rdate cfengine bootpc wget rsh-client less ssh dump ext2resize raidtools2 lvm"  
   
   
 basetgz=base${dversion}.tgz  
 fai=/usr/lib/fai  
 root=$fai/nfsroot  
 aptconf=$fai/etc/apt.conf.nfsroot  
54  export DEBIAN_FRONTEND=Noninteractive  export DEBIAN_FRONTEND=Noninteractive
55    
56  if [ "$verbose" ]; then  if [ "$verbose" ]; then
# Line 57  else Line 59  else
59          devnull=/dev/null          devnull=/dev/null
60  fi  fi
61    
62    trap "umount_dirs" EXIT
63    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
64    die() {
65    
66        echo $*
67        exit 99
68    }
69    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
70    install_kernel_nfsroot() {
71    
72        rm -rf $NFSROOT/boot/*-$KERNELVERSION $NFSROOT/lib/modules/$KERNELVERSION
73        dpkg -x $KERNELPACKAGE $NFSROOT
74        # if $NFROOT/proc/modules exists, then update-modules calls depmod -a without
75        # these special flags; so umount first
76        umount $NFSROOT/proc
77        chroot $NFSROOT update-modules
78        chroot $NFSROOT depmod -a -F /boot/System.map-$KERNELVERSION $KERNELVERSION
79    }
80    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
81    setup_ssh() {
82    
83        # nothing to do if no ssh is available in nfsroot
84        [ -f $NFSROOT/var/lib/dpkg/info/ssh.list ] || return 0
85        mkdir -p -m 700 $NFSROOT/root/.ssh
86        [ -f /etc/ssh/ssh_known_hosts ] && cp /etc/ssh/ssh_known_hosts $NFSROOT/root/.ssh/known_hosts
87        loguserhome=`eval "cd ~$LOGUSER 2>/dev/null && pwd;true"`
88        [ -d $loguserhome/.ssh ] && cp -p $loguserhome/.ssh/identity* $NFSROOT/root/.ssh/
89    
90        # enable root login
91        perl -pi -e 's/PermitRootLogin no/PermitRootLogin yes/' $NFSROOT/etc/ssh/sshd_config
92        if [ -f "$SSH_IDENTITY" ]; then
93            cp -p $SSH_IDENTITY $NFSROOT/root/.ssh/authorized_keys
94            echo You can log into install clients without password using $SSH_IDENTITY
95        fi
96    }
97    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
98    copy_fai_files() {
99    
100        # copy to nfsroot
101        perl -pi -e "s/^root::/root:${FAI_ROOTPW}:/" etc/passwd
102        mkdir -p $NFSROOT/fai/fai_config $NFSROOT/usr/share/fai
103        cd $NFSROOT
104        cp -p $LIBFAI/sbin/dhclient-script $LIBFAI/etc/dhclient.conf /etc/fai.conf etc
105        cp -p $LIBFAI/sbin/* sbin
106        cp -p $LIBFAI/etc/fai_modules_off etc/modutils
107    
108        cp -p /usr/share/fai/subroutines usr/share/fai
109        cp -p $LIBFAI/etc/apt.conf etc/apt
110        cp -p /usr/lib/perl5/Debian/Fai.pm usr/lib/perl5/Debian/
111        echo $NFSROOT_ETC_HOSTS >> etc/hosts
112    }
113  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
114  recreate_nfsroot() {  call_debootstrap() {
115    
116      echo Removing old nfsroot $root      echo "Creating nfsroot for $1 using debootstrap"
117      rm -rf $root/*      [ "$verbose" ] && echo "calling debootstrap $1 $NFSROOT $2"
118      cd $root      LC_ALL=C debootstrap $1 $NFSROOT $2 > $devnull 2>&1
119      echo Unpacking $basetgz  }
120      tar zxpf /tmp/$basetgz  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
121      touch etc/fstab etc/raidtab # dump and raidtool2 needs these files  create_base() {
122    
123        if [ "$FAI_DEBOOTSTRAP" ]; then
124            call_debootstrap $FAI_DEBOOTSTRAP
125            echo "Creating base.tgz"
126            tar -C $NFSROOT -cf - . | gzip > $NFSROOT/../base.tgz
127            mv $NFSROOT/../base.tgz $NFSROOT/var/tmp/base.tgz
128        else
129            # old method for potato
130            get_basetgz
131            echo "Unpacking base2_2.tgz"
132            zcat /tmp/base2_2.tgz | tar -C $NFSROOT -xpf -
133            cp -p /tmp/base2_2.tgz $NFSROOT/var/tmp/base.tgz
134        fi
135    }
136    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
137    create_nfsroot() {
138    
139        mkdir -p $NFSROOT/fai
140        cd $NFSROOT || die "Error: Can't cd to $NFSROOT"
141        create_base
142        mknod dev/boot255 c 0 255
143    
144        if [ "$FAI_DEBMIRROR" ]; then
145            mkdir -p $NFSROOT/$MNTPOINT
146            mount -o ro,rsize=8192 $FAI_DEBMIRROR $NFSROOT/$MNTPOINT || die "Can't mount $FAI_DEBMIRROR"
147        fi
148    
149        # hoaks some packages
150        > etc/fstab # dump and raidtool2 needs these files
151        > etc/raidtab
152        mkdir -p lib/modules/$KERNELVERSION           # dirty trick to hoax lvm
153        >  lib/modules/$KERNELVERSION/modules.dep  # dirty trick to hoax lvm
154      mkdir -p etc/ssh      mkdir -p etc/ssh
155      touch etc/ssh/NOSERVER      # don't start sshd on the host where fai is installed      > etc/ssh/NOSERVER
156      mkdir -p lib/modules/`uname -r`             # dirty trick to hoax lvm  
157      touch lib/modules/`uname -r`/modules.dep    # dirty trick to hoax lvm      echo "$FAI_SOURCES_LIST" > etc/apt/sources.list
158      upgrade_nfsroot      upgrade_nfsroot
159        copy_fai_files
160      perl -pi -e "s/^root::/root:${rootpw}:/" etc/passwd  
161      mkdir -p $root/fai/fai_config      # set timezone
162      touch $root/fai/BOOTP   # enable BOOTP support      rm -f etc/localtime
163      cp -p /usr/lib/fai/sbin/* $root/sbin      cp -d /etc/localtime /etc/timezone etc
164      cp -p /usr/lib/fai/etc/apt.conf $root/etc/apt  
165      cp -p /usr/lib/perl5/Debian/Fai.pm $root/usr/lib/perl5/Debian/      # make little changes to nfsroot, because nfsroot is
166      rm -rf etc/mtab etc/apt/sources.list var/run      # read only for the install clients
167      mv $root/etc/init.d/rcS $root/etc/init.d/rcS.orig      rm -rf etc/mtab var/run
168      ln -s /proc/mounts $root/etc/mtab      mv etc/init.d/rcS etc/init.d/rcS.orig
169      ln -s /tmp/var/run $root/var/run      ln -s /proc/mounts etc/mtab
170      ln -s /tmp/etc/resolv.conf $root/etc/resolv.conf      ln -s /tmp/var/run var/run
171      ln -s /sbin/rcS_fai $root/etc/init.d/rcS      ln -sf /tmp/etc/resolv.conf etc/resolv.conf
172        ln -s /sbin/rcS_fai etc/init.d/rcS
173      cat >$root/etc/rc2.d/S01fai_abort <<EOF  
174      #!/bin/sh      # turn off logging of loading kernel modules
175      echo FAI: installation aborted.      rmdir var/log/ksymoops/
176      echo reboot with: faireboot      ln -s /dev/null var/log/ksymoops
177      echo or after a logout  
178      sh      # definition for loopback device
179      cd /      echo "iface lo inet loopback" > etc/network/interfaces
180      umount -ar  
181      reboot -dfi      echo "*.* /tmp/syslog.log" > etc/syslog.conf
182        echo ". /usr/share/fai/subroutines" >> root/.profile
183    
184        setup_ssh
185    
186        cat >$NFSROOT/etc/rc2.d/S01fai_abort <<-EOF
187            #!/bin/sh
188            echo FAI: installation aborted.
189            echo reboot with: faireboot
190            echo or after a logout
191            sh
192            cd /
193            umount -ar
194            reboot -dfi
195  EOF  EOF
196      chmod a+rx $root/etc/rc2.d/S01fai_abort      chmod a+rx $NFSROOT/etc/rc2.d/S01fai_abort
197  }  }
198  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
199  upgrade_nfsroot() {  upgrade_nfsroot() {
200    
201      echo Upgrading $root      echo "Upgrading $NFSROOT"
202      apt-get -c $aptconf update  > $devnull      {
203      apt-get -c $aptconf check    > $devnull      cp /etc/resolv.conf $NFSROOT/etc
204      chroot $root mount -n -t proc proc /proc      $ROOTCMD apt-get update
205      apt-get -c $aptconf -y remove pcmcia-cs </dev/null  > $devnull      $ROOTCMD apt-get check
206      apt-get -c $aptconf -y upgrade </dev/null  > $devnull      rm -rf $NFSROOT/etc/pcmcia $NFSROOT/etc/apm
207      echo Adding additional packages to $root      mount -t proc /proc $NFSROOT/proc
208      apt-get -c $aptconf -y --fix-missing install $packages </dev/null  > $devnull      $ROOTCMD apt-get -y install debconf pcmcia-cs- ppp- </dev/null
209      chroot $root umount -n /proc >/dev/null  
210        # fake start-stop-dameon
211        $ROOTCMD dpkg-divert --quiet --package fai --add --rename /sbin/start-stop-daemon
212        cp $LIBFAI/sbin/start-stop-daemon $NFSROOT/sbin
213        $ROOTCMD apt-get -y upgrade
214        } > $devnull
215        echo "Adding additional packages to $NFSROOT:"
216        echo "$packages"
217        {
218        $ROOTCMD apt-get -y --fix-missing install $packages </dev/null
219        $ROOTCMD apt-get clean
220        } > $devnull
221  }  }
222  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
223    get_basetgz() {
224    
225  # create installation filesystem that will be      [ -f /tmp/base2_2.tgz ] && return
226  # mounted readonly by all clients during installation process      [ "$FAI_BASETGZ" ] || die "No /tmp/base2_2.tgz found and FAI_BASETGZ not defined."
227  # get base2_2.tgz via wget from ftp.debian.org (default no)      case $FAI_BASETGZ in
   
   
 # TODO: parse sources.list and guess location for baseX_X.tgz  
 if [ ! -f /tmp/$basetgz ]; then  
     case $url in  
228          ftp:*|http:*)          ftp:*|http:*)
229             wget -Nv -P/tmp $url/dists/$dname/main/disks-i386/current/base${dversion}.tgz              echo "Fetching $FAI_BASETGZ via wget. This may take some time."
230             ;;              TMPBDIR=`mktemp /tmp/FAI-wget-XXXXXX` || exit 1
231          *) cp -p $url/dists/$dname/main/disks-i386/current/base${dversion}.tgz /tmp              rm $TMPBDIR; mkdir $TMPBDIR || exit
232             ;;              wget -P$TMPBDIR $FAI_BASETGZ
233                mv $TMPBDIR/base2_2.tgz /tmp
234                rm -rf $TMPBDIR
235                ;;
236            /*/base2_2.tgz)
237                rm -f /tmp/base2_2.tgz
238                test -r $FAI_BASETGZ || die "Can't read $FAI_BASETGZ. Check FAI_BASETGZ in fai.conf."
239                ln -s $FAI_BASETGZ /tmp
240                ;;
241            *)
242                die "FAI_BASETGZ in fai.conf is $FAI_BASETGZ and looks very strong."
243                ;;
244      esac      esac
245  fi  }
246    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
247    umount_dirs() {
248    
249        cd /
250        sleep 2
251        umount $NFSROOT/proc 1>/dev/null 2>&1 || true
252        umount $NFSROOT/dev/pts 1>/dev/null 2>&1 ||true
253        if [ "$FAI_DEBMIRROR" ]; then
254            test -d $NFSROOT/$MNTPOINT && umount $NFSROOT/$MNTPOINT || true
255        fi
256        # show directories still mounted on nfsroot
257        mount | grep " on $NFSROOT " || true
258    }
259    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
260    # main routine
261    
262  if [ ! -f /tmp/$basetgz ]; then  if [ -d $NFSROOT/fai ]; then
263      echo "Please put the Debian $basetgz file into /tmp before creating nfsroot for fai."      echo $NFSROOT already exists. Removing $NFSROOT
264      exit 1      umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true
265        rm -rf $NFSROOT/.??* $NFSROOT/*
266        # also remove files $NFSROOT/.? but not . and ..
267        find $NFSROOT ! -type d -xdev -maxdepth 1 | xargs -r rm -f
268  fi  fi
269    
270  if [ -d $root/fai ]; then  create_nfsroot
271      echo $root/fai already exists  
272      echo "Do you want to delete and recreate it ?:"  if [ -f $KERNELPACKAGE ]; then
273      read answer      # create tftp boot images
274      case "$answer" in      install_kernel_nfsroot
275          [yY])      mknbi-linux --verbose $NFSROOT/boot/vmlinuz-$KERNELVERSION /boot/fai/installimage
276              recreate_nfsroot      # imggen is free software from 3com
277              ;;      # it converts netboot image to images, that are bootable by 3com network cards
278      esac      imggen=`which imggen || true`
279        if [ -x "$imggen" ]; then
280            imggen -a /boot/fai/installimage /boot/fai/installimage_3com
281        fi
282  else  else
283      recreate_nfsroot      echo "Kernel package $KERNELPACKAGE not found."
284        echo "No install kernel installed in /boot/fai."
285        echo "No kernel modules available in nfsroot."
286  fi  fi
287    
288    echo make-fai-nfsroot finished.
289  exit 0  exit 0

Legend:
Removed from v.44  
changed lines
  Added in v.691

  ViewVC Help
Powered by ViewVC 1.1.5