#! /bin/sh # $Id$ #********************************************************************* # # make-fai-nfsroot -- create nfsroot directory and add additional packages # # This script is part of FAI (Fully Automatic Installation) # (c) 2000 by Thomas Lange, lange@informatik.uni-koeln.de # Universitaet zu Koeln # #********************************************************************* # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # A copy of the GNU General Public License is available as # `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution # or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html. You # can also obtain it by writing to the Free Software Foundation, Inc., # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #********************************************************************* # Thomas Lange, Universitaet Koeln, 2000 PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin while getopts v opt ; do case "$opt" in v) verbose=1 ;; esac done . /etc/fai.conf conffile=$NFSROOT/etc/rcS_fai.conf # Additional packages that are install to nfsroot packages="$NFSROOT_PACKAGES perl-5.005 dhcp-client file rdate cfengine bootpc wget rsh-client less dump ext2resize raidtools2 lvm strace expect5.31" export DEBIAN_FRONTEND=Noninteractive if [ "$verbose" ]; then devnull=/dev/tty else devnull=/dev/null fi # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - die() { echo $* exit 99 } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - setup_ssh() { # enable root login perl -pi -e 's/PermitRootLogin no/PermitRootLogin yes/' $NFSROOT/etc/ssh/sshd_config if [ -f "$SSH_IDENTITY" ]; then mkdir -p -m 700 $NFSROOT/root/.ssh cp -p $SSH_IDENTITY $NFSROOT/root/.ssh/authorized_keys echo You can log into install clients without password using $SSH_IDENTITY fi } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - copy_fai_files() { perl -pi -e "s/^root::/root:${FAI_ROOTPW}:/" etc/passwd mkdir -p $NFSROOT/fai/fai_config $NFSROOT/usr/share/fai cp -p $LIBFAI/sbin/dhclient-script $LIBFAI/etc/dhclient.conf $NFSROOT/etc cp -p $LIBFAI/sbin/* $NFSROOT/sbin cp -p /usr/share/fai/* $NFSROOT/usr/share/fai cp -p $LIBFAI/etc/apt.conf $NFSROOT/etc/apt cp -p /usr/lib/perl5/Debian/Fai.pm $NFSROOT/usr/lib/perl5/Debian/ cp -p /etc/fai.conf $NFSROOT/etc cp -p /tmp/base?_?.tgz $NFSROOT/var/tmp cat > $conffile <<-EOF # rcS_fai.conf -- created by make-fai-nfsroot LOGUSER=$LOGUSER KERNELVERSION=$KERNELVERSION FAI_PACKAGEDIR=$FAI_PACKAGEDIR FAI_BASETGZ=$FAI_BASETGZ MNTPOINT=$MNTPOINT UTC=$UTC EOF } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - create_nfsroot() { mkdir -p $NFSROOT cd $NFSROOT || die "Error: Can't cd to $NFSROOT" get_basetgz echo -n "Unpacking " ; ls /tmp/base?_?.tgz tar -C $NFSROOT -zxpf /tmp/base?_?.tgz mknod $NFSROOT/dev/boot255 c 0 255 mkdir -p $NFSROOT/$MNTPOINT if [ "$FAI_PACKAGEDIR" ]; then mount -o ro,rsize=8192 $FAI_PACKAGEDIR $NFSROOT/$MNTPOINT || die "Can't mount $FAI_PACKAGEDIR" fi # hoaks some packages touch etc/fstab etc/raidtab # dump and raidtool2 needs these files mkdir -p lib/modules/$KERNELVERSION # dirty trick to hoax lvm touch lib/modules/$KERNELVERSION/modules.dep # dirty trick to hoax lvm mkdir -p $NFSROOT/etc/ssh touch $NFSROOT/etc/ssh/NOSERVER echo "$FAI_SOURCES_LIST" > $NFSROOT/etc/apt/sources.list upgrade_nfsroot copy_fai_files # set timezone rm -f $NFSROOT/etc/localtime cp -d /etc/localtime /etc/timezone $NFSROOT/etc # make little changes to nfsroot, because file systems are # read only for the install clients rm -rf etc/mtab var/run mv $NFSROOT/etc/init.d/rcS $NFSROOT/etc/init.d/rcS.orig ln -s /proc/mounts $NFSROOT/etc/mtab ln -s /tmp/var/run $NFSROOT/var/run ln -s /tmp/etc/resolv.conf $NFSROOT/etc/resolv.conf ln -s /sbin/rcS_fai $NFSROOT/etc/init.d/rcS # turn off logging of loading kernel modules rmdir $NFSROOT/var/log/ksymoops/ ln -s /dev/null $NFSROOT/var/log/ksymoops # definition for loopback device cat >$NFSROOT/etc/network/interfaces <<-EOF iface lo inet static address 127.0.0.1 netmask 255.0.0.0 EOF # if package ssh is installed [ -f /var/lib/dpkg/info/ssh.list ] && setup_ssh umount $NFSROOT/dev/pts 2>/dev/null 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 } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - upgrade_nfsroot() { echo "Upgrading $NFSROOT" { chroot $NFSROOT apt-get update chroot $NFSROOT apt-get check chroot $NFSROOT mount -n -t proc proc /proc rm -rf $NFSROOT/etc/pcmcia $NFSROOT/etc/apm chroot $NFSROOT apt-get -y remove pcmcia-cs $devnull echo "Adding additional packages to $NFSROOT:" echo "$packages" { chroot $NFSROOT apt-get -y --fix-missing install $packages $devnull } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - get_basetgz() { [ -f /tmp/base?_?.tgz ] && return [ "$BASETGZ" ] || die "no /tmp/base?_?.tgz found and BASETGZ not defined." case $BASETGZ in ftp:*|http:*) echo "Getting $BASETGZ via wget. This may take some time." TMPBDIR=`mktemp /tmp/FAI-wget-XXXXXX` || exit 1 rm $TMPBDIR; mkdir $TMPBDIR || exit wget -P$TMPBDIR $BASETGZ mv $TMPBDIR/base?_?.tgz /tmp rm -rf $TMPBDIR ;; /*/base?_?.tgz) cd /tmp rm -f base?_?.tgz ln -s $BASETGZ ;; *) die "BASETGZ $BASETGZ seems strong." ;; esac } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # main routine if [ -d $NFSROOT/fai ]; then echo $NFSROOT already exists. Removing $NFSROOT umount $NFSROOT/dev/pts 1>/dev/null 2>&1 rm -rf $NFSROOT fi create_nfsroot test -d $NFSROOT/$MNTPOINT && umount $NFSROOT/$MNTPOINT exit 0