/[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 1028 by lange, Mon Jan 28 14:59:21 2002 UTC revision 1035 by lange, Tue Feb 5 13:33:07 2002 UTC
# 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  # Packages that are install to nfsroot by default  # Packages that are install to nfsroot by default Additional packages are
31  # Additional packages are defined with $NFSROOT_PACKAGES in fai.conf  # 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 hwtools dosfstools sysutils"  packages="dhcp-client file rdate cfengine bootpc wget rsh-client less dump
33    ext2resize strace hdparm parted dnsutils grub ntpdate psmisc hwtools
34    dosfstools sysutils"
35    
36  PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin  PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
37    
38  if [ "$UID" -ne 0 ]; then  if [ "$UID" -ne 0 ]; then
39   echo "Run this program as root."      echo "Run this program as root."
40   exit 9      exit 9
41  fi  fi
42    
43  while getopts v opt ; do  while getopts rv opt ; do
44          case "$opt" in      case "$opt" in
45          v) verbose=1 ;;          v) verbose=1 ;;
46          esac          r) recover=1 ;;
47        esac
48  done  done
49    
50  set -e  set -e
51  . /etc/fai/fai.conf  . /etc/fai/fai.conf
52  packages="$packages $NFSROOT_PACKAGES"  packages="$packages $NFSROOT_PACKAGES"
53    
54  ROOTCMD="chroot $NFSROOT"  ROOTCMD="chroot $NFSROOT"
55    
56    RUNDIR=/var/run/fai/make-nfs-root
57    [ ! -d $RUNDIR ] && mkdir -p $RUNDIR
58    [ ! "$recover" ] && rm -rf $RUNDIR/*
59    
60  LIBFAI=/usr/lib/fai  LIBFAI=/usr/lib/fai
61  SHAREFAI=/usr/share/fai  SHAREFAI=/usr/share/fai
62  conffile=$NFSROOT/etc/rcS_fai.conf  conffile=$NFSROOT/etc/rcS_fai.conf
# Line 62  die() { Line 70  die() {
70      exit 99      exit 99
71  }  }
72  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
73    call_with_stamp() {
74    
75        local func=$1
76        local stamp=$RUNDIR/$func
77        # call subroutine
78        [ "$recover" -a -f $stamp ] && return 0
79        "$@"
80        > $stamp
81    }
82    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
83  call_verbose() {  call_verbose() {
84    
85      if [ "$verbose" ]; then      if [ "$verbose" ]; then
86          "$@"          "$@"
87      else      else
88          "$@" > /dev/null          "$@" > /dev/null
89      fi      fi
90  }  }
91  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Line 79  install_kernel_nfsroot() { Line 97  install_kernel_nfsroot() {
97      dpkg -x $KERNELPACKAGE $NFSROOT      dpkg -x $KERNELPACKAGE $NFSROOT
98      # if $NFROOT/proc/modules exists, then update-modules calls depmod -a without      # if $NFROOT/proc/modules exists, then update-modules calls depmod -a without
99      # these special flags; so umount first      # these special flags; so umount first
100      umount $NFSROOT/proc      [ -e $NFSROOT/proc/modules ] && umount $NFSROOT/proc
101      chroot $NFSROOT update-modules      chroot $NFSROOT update-modules
102      chroot $NFSROOT depmod -a -F /boot/System.map-$KERNELVERSION $KERNELVERSION      chroot $NFSROOT depmod -a -F /boot/System.map-$KERNELVERSION $KERNELVERSION
103  }  }
# Line 96  setup_ssh() { Line 114  setup_ssh() {
114      # enable root login      # enable root login
115      perl -pi -e 's/PermitRootLogin no/PermitRootLogin yes/' $NFSROOT/etc/ssh/sshd_config      perl -pi -e 's/PermitRootLogin no/PermitRootLogin yes/' $NFSROOT/etc/ssh/sshd_config
116      if [ -f "$SSH_IDENTITY" ]; then      if [ -f "$SSH_IDENTITY" ]; then
117          cp -p $SSH_IDENTITY $NFSROOT/root/.ssh/authorized_keys          cp -p $SSH_IDENTITY $NFSROOT/root/.ssh/authorized_keys
118          echo You can log into install clients without password using $SSH_IDENTITY          echo You can log into install clients without password using $SSH_IDENTITY
119      fi      fi
120  }  }
121  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Line 108  copy_fai_files() { Line 126  copy_fai_files() {
126      mkdir -p $NFSROOT/$FAI/fai_config $NFSROOT/$SHAREFAI $NFSROOT/etc/fai      mkdir -p $NFSROOT/$FAI/fai_config $NFSROOT/$SHAREFAI $NFSROOT/etc/fai
127      cd $NFSROOT      cd $NFSROOT
128      cp -p $LIBFAI/sbin/dhclient-script $SHAREFAI/etc/dhclient.conf etc/      cp -p $LIBFAI/sbin/dhclient-script $SHAREFAI/etc/dhclient.conf etc/
129      cp -p /etc/fai/* etc/fai/      cp -Rp /etc/fai etc/
130      [ -f /etc/fai/.cvspass ] && cp -p /etc/fai/.cvspass .cvspass      [ -f /etc/fai/.cvspass ] && cp -p /etc/fai/.cvspass .cvspass
131      cp -p $LIBFAI/sbin/* sbin/      cp -p $LIBFAI/sbin/* sbin/
132      cp -p $SHAREFAI/etc/fai_modules_off etc/modutils/      cp -p $SHAREFAI/etc/fai_modules_off etc/modutils/
133    
134      cp -p $SHAREFAI/subroutines usr/share/fai      cp -p $SHAREFAI/subroutines usr/share/fai
135      cp -p $SHAREFAI/etc/apt.conf etc/apt      cp -p $SHAREFAI/etc/apt.conf etc/apt
136  # potato / woody code      # potato / woody code
137      if [ -d usr/lib/perl5/Debian ]; then      if [ -d usr/lib/perl5/Debian ]; then
138          cp -p /usr/lib/perl5/Debian/Fai.pm usr/lib/perl5/Debian/          cp -p /usr/lib/perl5/Debian/Fai.pm usr/lib/perl5/Debian/
139      else      else
140          cp -p /usr/share/perl5/Debian/Fai.pm usr/share/perl5/Debian/          cp -p /usr/share/perl5/Debian/Fai.pm usr/share/perl5/Debian/
141      fi      fi
142      echo $NFSROOT_ETC_HOSTS >> etc/hosts      echo $NFSROOT_ETC_HOSTS >> etc/hosts
143  }  }
144  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
145  call_debootstrap() {  call_debootstrap() {
146    
147      echo "Creating nfsroot for $1 using debootstrap"      echo "Creating nfsroot for $1 using debootstrap"
148      [ "$verbose" ] && echo "calling debootstrap $1 $NFSROOT $2"      [ "$verbose" ] && echo "calling debootstrap $1 $NFSROOT $2"
149      yes '' | debootstrap $1 $NFSROOT $2      yes '' | debootstrap $1 $NFSROOT $2
# Line 134  call_debootstrap() { Line 152  call_debootstrap() {
152  create_base() {  create_base() {
153    
154      if [ "$FAI_DEBOOTSTRAP" ]; then      if [ "$FAI_DEBOOTSTRAP" ]; then
155          call_verbose call_debootstrap $FAI_DEBOOTSTRAP          call_verbose call_with_stamp call_debootstrap $FAI_DEBOOTSTRAP
156          $ROOTCMD apt-get clean          $ROOTCMD apt-get clean
157          echo "Creating base.tgz"          echo "Creating base.tgz"
158          tar -C $NFSROOT -cf - . | gzip > $NFSROOT/../base.tgz          tar -C $NFSROOT -cf - . | gzip > $NFSROOT/../base.tgz
159          mv $NFSROOT/../base.tgz $NFSROOT/var/tmp/base.tgz          mv $NFSROOT/../base.tgz $NFSROOT/var/tmp/base.tgz
160      else      else
161          # old method for potato          # old method for potato
162          get_basetgz          call_with_stamp get_basetgz
163          echo "Unpacking base2_2.tgz"          echo "Unpacking base2_2.tgz"
164          zcat /tmp/base2_2.tgz | tar -C $NFSROOT -xpf -          zcat /tmp/base2_2.tgz | tar -C $NFSROOT -xpf -
165          cp -p /tmp/base2_2.tgz $NFSROOT/var/tmp/base.tgz          cp -p /tmp/base2_2.tgz $NFSROOT/var/tmp/base.tgz
166      fi      fi
167  }  }
168  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Line 152  create_nfsroot() { Line 170  create_nfsroot() {
170    
171      mkdir -p $NFSROOT/$FAI      mkdir -p $NFSROOT/$FAI
172      cd $NFSROOT || die "Error: Can't cd to $NFSROOT"      cd $NFSROOT || die "Error: Can't cd to $NFSROOT"
173      create_base  
174      mknod dev/boot255 c 0 255      call_with_stamp create_base
175    
176        [ ! -c dev/boot255 ] && mknod dev/boot255 c 0 255
177    
178      if [ "$FAI_DEBMIRROR" ]; then      if [ "$FAI_DEBMIRROR" ]; then
179          mkdir -p $NFSROOT/$MNTPOINT          mkdir -p $NFSROOT/$MNTPOINT
180          mount -o ro,rsize=8192 $FAI_DEBMIRROR $NFSROOT/$MNTPOINT || die "Can't mount $FAI_DEBMIRROR"          mount -o ro,rsize=8192 $FAI_DEBMIRROR $NFSROOT/$MNTPOINT || \
181      fi                  die "Can't mount $FAI_DEBMIRROR"
182            fi
183    
184      # hoaks some packages      # hoaks some packages
185      # liloconfig, dump and raidtool2 needs these files      # liloconfig, dump and raidtool2 needs these files
# Line 173  create_nfsroot() { Line 194  create_nfsroot() {
194      # woody uses debconf      # woody uses debconf
195    
196      if [ "$FAI_SOURCES_LIST" ]; then      if [ "$FAI_SOURCES_LIST" ]; then
197          echo "$FAI_SOURCES_LIST" > etc/apt/sources.list          echo "$FAI_SOURCES_LIST" > etc/apt/sources.list
198      else      else
199          cp /etc/apt/sources.list etc/apt/sources.list          cp /etc/apt/sources.list etc/apt/sources.list
200      fi      fi
201      [ -f /etc/apt/preferences ] && cp /etc/apt/preferences etc/apt      [ -f /etc/apt/preferences ] && cp /etc/apt/preferences etc/apt
202      echo "Upgrading $NFSROOT"      echo "Upgrading $NFSROOT"
203      call_verbose upgrade_nfsroot      call_verbose call_with_stamp upgrade_nfsroot
204      echo "Adding additional packages to $NFSROOT:"      echo "Adding additional packages to $NFSROOT:"
205      echo "$packages"      echo "$packages"
206      call_verbose add_packages_nfsroot      call_verbose call_with_stamp add_packages_nfsroot
207      copy_fai_files      call_with_stamp copy_fai_files
208    
209      # set timezone      # set timezone
210      rm -f etc/localtime      rm -f etc/localtime
# Line 211  create_nfsroot() { Line 232  create_nfsroot() {
232      echo "*.* /tmp/syslog.log" > etc/syslog.conf      echo "*.* /tmp/syslog.log" > etc/syslog.conf
233      echo ". $SHAREFAI/subroutines" >> root/.profile      echo ". $SHAREFAI/subroutines" >> root/.profile
234    
235      setup_ssh      call_verbose call_with_stamp setup_ssh
236    
237      cat >$NFSROOT/etc/rc2.d/S01fai_abort <<-EOF      cat >$NFSROOT/etc/rc2.d/S01fai_abort <<-EOF
238          #!/bin/sh          #!/bin/sh
239          echo FAI: installation aborted.          echo FAI: installation aborted.
240          echo reboot with: faireboot          echo reboot with: faireboot
241          echo or after a logout          echo or after a logout
242          sh          sh
243          cd /          cd /
244          umount -ar          umount -ar
245          reboot -dfi          reboot -dfi
246  EOF  EOF
247      chmod a+rx $NFSROOT/etc/rc2.d/S01fai_abort      chmod a+rx $NFSROOT/etc/rc2.d/S01fai_abort
248  }  }
# Line 252  get_basetgz() { Line 273  get_basetgz() {
273      [ -f /tmp/base2_2.tgz ] && return      [ -f /tmp/base2_2.tgz ] && return
274      [ "$FAI_BASETGZ" ] || die "No /tmp/base2_2.tgz found and FAI_BASETGZ not defined."      [ "$FAI_BASETGZ" ] || die "No /tmp/base2_2.tgz found and FAI_BASETGZ not defined."
275      case $FAI_BASETGZ in      case $FAI_BASETGZ in
276          ftp:*|http:*)          ftp:*|http:*)
277              echo "Fetching $FAI_BASETGZ via wget. This may take some time."              echo "Fetching $FAI_BASETGZ via wget. This may take some time."
278              TMPBDIR=`mktemp /tmp/FAI-wget-XXXXXX` || exit 1              TMPBDIR=`mktemp /tmp/FAI-wget-XXXXXX` || exit 1
279              rm $TMPBDIR; mkdir $TMPBDIR || exit              rm $TMPBDIR; mkdir $TMPBDIR || exit
280              wget -P$TMPBDIR $FAI_BASETGZ              wget -P$TMPBDIR $FAI_BASETGZ
281              mv $TMPBDIR/base2_2.tgz /tmp              mv $TMPBDIR/base2_2.tgz /tmp
282              rm -rf $TMPBDIR              rm -rf $TMPBDIR
283              ;;              ;;
284          /*/base2_2.tgz)          /*/base2_2.tgz)
285              rm -f /tmp/base2_2.tgz              rm -f /tmp/base2_2.tgz
286              test -r $FAI_BASETGZ || die "Can't read $FAI_BASETGZ. Check FAI_BASETGZ in fai.conf."              test -r $FAI_BASETGZ || die "Can't read $FAI_BASETGZ. Check FAI_BASETGZ in fai.conf."
287              ln -s $FAI_BASETGZ /tmp              ln -s $FAI_BASETGZ /tmp
288              ;;              ;;
289          *)          *)
290              die "FAI_BASETGZ in fai.conf is $FAI_BASETGZ and looks very strange."              die "FAI_BASETGZ in fai.conf is $FAI_BASETGZ and looks very strange."
291              ;;              ;;
292      esac      esac
293  }  }
294  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Line 278  umount_dirs() { Line 299  umount_dirs() {
299      umount $NFSROOT/proc 1>/dev/null 2>&1 || true      umount $NFSROOT/proc 1>/dev/null 2>&1 || true
300      umount $NFSROOT/dev/pts 1>/dev/null 2>&1 ||true      umount $NFSROOT/dev/pts 1>/dev/null 2>&1 ||true
301      if [ "$FAI_DEBMIRROR" ]; then      if [ "$FAI_DEBMIRROR" ]; then
302          test -d $NFSROOT/$MNTPOINT && umount $NFSROOT/$MNTPOINT || true          test -d $NFSROOT/$MNTPOINT && umount $NFSROOT/$MNTPOINT || true
303      fi      fi
304      # show directories still mounted on nfsroot      # show directories still mounted on nfsroot
305      mount | grep " on $NFSROOT " || true      mount | grep " on $NFSROOT " || true
# Line 290  get_kernel_version() { Line 311  get_kernel_version() {
311      KERNELVERSION=`dpkg --info $1 | grep "Package: kernel-image" | sed -e 's/.*kernel-image-'//`      KERNELVERSION=`dpkg --info $1 | grep "Package: kernel-image" | sed -e 's/.*kernel-image-'//`
312  }  }
313  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
314    setup_bootp(){
315    
316        mknbi-linux --verbose $NFSROOT/boot/vmlinuz-$KERNELVERSION /boot/fai/installimage
317        # imggen is free software from 3com
318        # it converts netboot image to images, that are bootable by 3com network cards
319        imggen=`which imggen || true`
320        if [ -x "$imggen" ]; then
321            imggen -a /boot/fai/installimage /boot/fai/installimage_3com
322        fi
323        echo "BOOTP environment prepared."
324    }
325    
326    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
327    setup_dhcp(){
328    
329        # pxe and dhcp environment
330        cp -p $NFSROOT/boot/vmlinuz-$KERNELVERSION /boot/fai/installkernel
331        rdev /boot/fai/installkernel $NFSROOT/dev/boot255
332        [ -f /usr/lib/syslinux/pxelinux.bin ] && cp /usr/lib/syslinux/pxelinux.bin /boot/fai
333        [ -d /boot/fai/pxelinux.cfg ] || mkdir /boot/fai/pxelinux.cfg || true
334        cp -p /usr/share/fai/etc/pxelinux.cfg /boot/fai/pxelinux.cfg/default
335        echo "DHCP environment prepared. Now enable dhcpd and the special tftp daemon"
336    }
337    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
338  # main routine  # main routine
339    
340  if [ -d $NFSROOT/$FAI ]; then  # Kill the directory if not in recover mode
341    if [ -d $NFSROOT/$FAI -a ! "$recover" ]
342    then
343      echo $NFSROOT already exists. Removing $NFSROOT      echo $NFSROOT already exists. Removing $NFSROOT
344      umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true      umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true
345      rm -rf $NFSROOT/.??* $NFSROOT/*      rm -rf $NFSROOT/.??* $NFSROOT/*
# Line 300  if [ -d $NFSROOT/$FAI ]; then Line 347  if [ -d $NFSROOT/$FAI ]; then
347      find $NFSROOT ! -type d -xdev -maxdepth 1 | xargs -r rm -f      find $NFSROOT ! -type d -xdev -maxdepth 1 | xargs -r rm -f
348  fi  fi
349    
350  create_nfsroot  # Create a new nfsroot
351    call_with_stamp create_nfsroot
352    
353    # Install the kernel package
354  if [ -f $KERNELPACKAGE ]; then  if [ -f $KERNELPACKAGE ]; then
   
355      # determine kernel version      # determine kernel version
356      get_kernel_version $KERNELPACKAGE      get_kernel_version $KERNELPACKAGE
357    
358      # create tftp boot images      # create tftp boot images
359      install_kernel_nfsroot      call_with_stamp install_kernel_nfsroot
360    
361      grep -q _dhcp_ $NFSROOT/boot/System.map-$KERNELVERSION && TYPE=DHCP      grep -q _dhcp_ $NFSROOT/boot/System.map-$KERNELVERSION && TYPE=DHCP
362      # only BOOTP need a netboot image, DHCP can do with raw kernels      # only BOOTP need a netboot image, DHCP can do with raw kernels
363      if [ "$TYPE" = DHCP ]; then      if [ "$TYPE" = DHCP ]; then
364          # pxe and dhcp environment          call_with_stamp setup_dhcp
         cp -p $NFSROOT/boot/vmlinuz-$KERNELVERSION /boot/fai/installkernel  
         rdev /boot/fai/installkernel $NFSROOT/dev/boot255  
         [ -f /usr/lib/syslinux/pxelinux.bin ] && cp /usr/lib/syslinux/pxelinux.bin /boot/fai  
         [ -d /boot/fai/pxelinux.cfg ] || mkdir /boot/fai/pxelinux.cfg || true  
         cp -p /usr/lib/fai/etc/pxelinux.cfg /boot/fai/pxelinux.cfg/default  
         echo "DHCP environment prepared. Now enable dhcpd and the special tftp daemon"  
365      else      else
366          mknbi-linux --verbose $NFSROOT/boot/vmlinuz-$KERNELVERSION /boot/fai/installimage          call_with_stamp setup_bootp
         # imggen is free software from 3com  
         # it converts netboot image to images, that are bootable by 3com network cards  
         imggen=`which imggen || true`  
         if [ -x "$imggen" ]; then  
             imggen -a /boot/fai/installimage /boot/fai/installimage_3com  
         fi  
         echo "BOOTP environment prepared."  
367      fi      fi
368  else  else
369      echo "Kernel package $KERNELPACKAGE not found."      echo "Kernel package $KERNELPACKAGE not found."

Legend:
Removed from v.1028  
changed lines
  Added in v.1035

  ViewVC Help
Powered by ViewVC 1.1.5