| 1 |
#! /bin/sh
|
| 2 |
|
| 3 |
# $Id$
|
| 4 |
#*********************************************************************
|
| 5 |
#
|
| 6 |
# make-fai-nfsroot -- create nfsroot directory and add additional packages
|
| 7 |
#
|
| 8 |
# This script is part of FAI (Fully Automatic Installation)
|
| 9 |
# (c) 2000-2001 by Thomas Lange, lange@informatik.uni-koeln.de
|
| 10 |
# Universitaet zu Koeln
|
| 11 |
#
|
| 12 |
#*********************************************************************
|
| 13 |
# This program is free software; you can redistribute it and/or modify
|
| 14 |
# it under the terms of the GNU General Public License as published by
|
| 15 |
# the Free Software Foundation; either version 2 of the License, or
|
| 16 |
# (at your option) any later version.
|
| 17 |
#
|
| 18 |
# This program is distributed in the hope that it will be useful, but
|
| 19 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 20 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 21 |
# General Public License for more details.
|
| 22 |
#
|
| 23 |
# A copy of the GNU General Public License is available as
|
| 24 |
# `/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
|
| 26 |
# can also obtain it by writing to the Free Software Foundation, Inc.,
|
| 27 |
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 28 |
#*********************************************************************
|
| 29 |
|
| 30 |
# 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 hwtools dosfstools sysutils"
|
| 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/fai.conf
|
| 49 |
packages="$packages $NFSROOT_PACKAGES"
|
| 50 |
ROOTCMD="chroot $NFSROOT"
|
| 51 |
|
| 52 |
LIBFAI=/usr/lib/fai
|
| 53 |
conffile=$NFSROOT/etc/rcS_fai.conf
|
| 54 |
export DEBIAN_FRONTEND=Noninteractive
|
| 55 |
|
| 56 |
trap "umount_dirs" EXIT
|
| 57 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 58 |
die() {
|
| 59 |
|
| 60 |
echo $*
|
| 61 |
exit 99
|
| 62 |
}
|
| 63 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 64 |
call_verbose() {
|
| 65 |
|
| 66 |
if [ "$verbose" ]; then
|
| 67 |
$*
|
| 68 |
else
|
| 69 |
$* > /dev/null
|
| 70 |
fi
|
| 71 |
}
|
| 72 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 73 |
install_kernel_nfsroot() {
|
| 74 |
|
| 75 |
rm -rf $NFSROOT/boot/*-$KERNELVERSION $NFSROOT/lib/modules/$KERNELVERSION
|
| 76 |
dpkg -x $KERNELPACKAGE $NFSROOT
|
| 77 |
# if $NFROOT/proc/modules exists, then update-modules calls depmod -a without
|
| 78 |
# these special flags; so umount first
|
| 79 |
umount $NFSROOT/proc
|
| 80 |
chroot $NFSROOT update-modules
|
| 81 |
chroot $NFSROOT depmod -a -F /boot/System.map-$KERNELVERSION $KERNELVERSION
|
| 82 |
}
|
| 83 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 84 |
setup_ssh() {
|
| 85 |
|
| 86 |
# nothing to do if no ssh is available in nfsroot
|
| 87 |
[ -f $NFSROOT/var/lib/dpkg/info/ssh.list ] || return 0
|
| 88 |
mkdir -p -m 700 $NFSROOT/root/.ssh
|
| 89 |
[ -f /etc/ssh/ssh_known_hosts ] && cp /etc/ssh/ssh_known_hosts $NFSROOT/root/.ssh/known_hosts
|
| 90 |
loguserhome=`eval "cd ~$LOGUSER 2>/dev/null && pwd;true"`
|
| 91 |
[ -d $loguserhome/.ssh ] && cp -p $loguserhome/.ssh/identity* $NFSROOT/root/.ssh/
|
| 92 |
|
| 93 |
# enable root login
|
| 94 |
perl -pi -e 's/PermitRootLogin no/PermitRootLogin yes/' $NFSROOT/etc/ssh/sshd_config
|
| 95 |
if [ -f "$SSH_IDENTITY" ]; then
|
| 96 |
cp -p $SSH_IDENTITY $NFSROOT/root/.ssh/authorized_keys
|
| 97 |
echo You can log into install clients without password using $SSH_IDENTITY
|
| 98 |
fi
|
| 99 |
}
|
| 100 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 101 |
copy_fai_files() {
|
| 102 |
|
| 103 |
# copy to nfsroot
|
| 104 |
perl -pi -e "s/^root::/root:${FAI_ROOTPW}:/" etc/passwd
|
| 105 |
mkdir -p $NFSROOT/fai/fai_config $NFSROOT/usr/share/fai
|
| 106 |
cd $NFSROOT
|
| 107 |
cp -p $LIBFAI/sbin/dhclient-script $LIBFAI/etc/dhclient.conf etc/
|
| 108 |
cp -p /etc/fai/fai.conf etc/fai/
|
| 109 |
cp -p $LIBFAI/sbin/* sbin/
|
| 110 |
cp -p $LIBFAI/etc/fai_modules_off etc/modutils/
|
| 111 |
|
| 112 |
cp -p /usr/share/fai/subroutines usr/share/fai
|
| 113 |
cp -p $LIBFAI/etc/apt.conf etc/apt
|
| 114 |
# potato / woody code
|
| 115 |
if [ -d /usr/lib/perl5/Debian ]; then
|
| 116 |
cp -p /usr/lib/perl5/Debian/Fai.pm usr/lib/perl5/Debian/
|
| 117 |
else
|
| 118 |
cp -p /usr/lib/perl5/Debian/Fai.pm usr/share/perl5/Debian/
|
| 119 |
fi
|
| 120 |
cp -p /usr/lib/perl5/Debian/Fai.pm usr/lib/perl5/Debian/
|
| 121 |
echo $NFSROOT_ETC_HOSTS >> etc/hosts
|
| 122 |
}
|
| 123 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 124 |
call_debootstrap() {
|
| 125 |
|
| 126 |
echo "Creating nfsroot for $1 using debootstrap"
|
| 127 |
[ "$verbose" ] && echo "calling debootstrap $1 $NFSROOT $2"
|
| 128 |
yes '' | debootstrap $1 $NFSROOT $2
|
| 129 |
}
|
| 130 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 131 |
create_base() {
|
| 132 |
|
| 133 |
if [ "$FAI_DEBOOTSTRAP" ]; then
|
| 134 |
call_verbose call_debootstrap $FAI_DEBOOTSTRAP
|
| 135 |
$ROOTCMD apt-get clean
|
| 136 |
echo "Creating base.tgz"
|
| 137 |
tar -C $NFSROOT -cf - . | gzip > $NFSROOT/../base.tgz
|
| 138 |
mv $NFSROOT/../base.tgz $NFSROOT/var/tmp/base.tgz
|
| 139 |
else
|
| 140 |
# old method for potato
|
| 141 |
get_basetgz
|
| 142 |
echo "Unpacking base2_2.tgz"
|
| 143 |
zcat /tmp/base2_2.tgz | tar -C $NFSROOT -xpf -
|
| 144 |
cp -p /tmp/base2_2.tgz $NFSROOT/var/tmp/base.tgz
|
| 145 |
fi
|
| 146 |
}
|
| 147 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 148 |
create_nfsroot() {
|
| 149 |
|
| 150 |
mkdir -p $NFSROOT/fai
|
| 151 |
cd $NFSROOT || die "Error: Can't cd to $NFSROOT"
|
| 152 |
create_base
|
| 153 |
mknod dev/boot255 c 0 255
|
| 154 |
|
| 155 |
if [ "$FAI_DEBMIRROR" ]; then
|
| 156 |
mkdir -p $NFSROOT/$MNTPOINT
|
| 157 |
mount -o ro,rsize=8192 $FAI_DEBMIRROR $NFSROOT/$MNTPOINT || die "Can't mount $FAI_DEBMIRROR"
|
| 158 |
fi
|
| 159 |
|
| 160 |
# hoaks some packages
|
| 161 |
# liloconfig, dump and raidtool2 needs these files
|
| 162 |
echo "# UNCONFIGURED FSTAB FOR BASE SYSTEM" > etc/fstab
|
| 163 |
> etc/raidtab
|
| 164 |
mkdir -p lib/modules/$KERNELVERSION # dirty trick to hoax lvm
|
| 165 |
> lib/modules/$KERNELVERSION/modules.dep # dirty trick to hoax lvm
|
| 166 |
mkdir -p etc/ssh
|
| 167 |
|
| 168 |
# potato only
|
| 169 |
> etc/ssh/NOSERVER
|
| 170 |
# woody uses debconf
|
| 171 |
|
| 172 |
if [ "$FAI_SOURCES_LIST" ]; then
|
| 173 |
echo "$FAI_SOURCES_LIST" > etc/apt/sources.list
|
| 174 |
else
|
| 175 |
cp /etc/apt/sources.list etc/apt/sources.list
|
| 176 |
fi
|
| 177 |
echo "Upgrading $NFSROOT"
|
| 178 |
call_verbose upgrade_nfsroot
|
| 179 |
echo "Adding additional packages to $NFSROOT:"
|
| 180 |
echo "$packages"
|
| 181 |
call_verbose add_packages_nfsroot
|
| 182 |
copy_fai_files
|
| 183 |
|
| 184 |
# set timezone
|
| 185 |
rm -f etc/localtime
|
| 186 |
cp -d /etc/localtime /etc/timezone etc
|
| 187 |
|
| 188 |
# make little changes to nfsroot, because nfsroot is
|
| 189 |
# read only for the install clients
|
| 190 |
rm -rf etc/mtab var/run
|
| 191 |
mv etc/init.d/rcS etc/init.d/rcS.orig
|
| 192 |
ln -s /proc/mounts etc/mtab
|
| 193 |
ln -s /tmp/var/run var/run
|
| 194 |
ln -sf /tmp/etc/resolv.conf etc/resolv.conf
|
| 195 |
ln -s /sbin/rcS_fai etc/init.d/rcS
|
| 196 |
ln -s /dev/null etc/network/ifstate
|
| 197 |
# for nis
|
| 198 |
[ -d var/yp ] && ln -s /tmp/binding var/yp/binding
|
| 199 |
|
| 200 |
# turn off logging of loading kernel modules
|
| 201 |
[ -d var/log/ksymoops/ ] && rmdir var/log/ksymoops/
|
| 202 |
ln -s /dev/null var/log/ksymoops
|
| 203 |
|
| 204 |
# definition for loopback device
|
| 205 |
echo "iface lo inet loopback" > etc/network/interfaces
|
| 206 |
|
| 207 |
echo "*.* /tmp/syslog.log" > etc/syslog.conf
|
| 208 |
echo ". /usr/share/fai/subroutines" >> root/.profile
|
| 209 |
|
| 210 |
setup_ssh
|
| 211 |
|
| 212 |
cat >$NFSROOT/etc/rc2.d/S01fai_abort <<-EOF
|
| 213 |
#!/bin/sh
|
| 214 |
echo FAI: installation aborted.
|
| 215 |
echo reboot with: faireboot
|
| 216 |
echo or after a logout
|
| 217 |
sh
|
| 218 |
cd /
|
| 219 |
umount -ar
|
| 220 |
reboot -dfi
|
| 221 |
EOF
|
| 222 |
chmod a+rx $NFSROOT/etc/rc2.d/S01fai_abort
|
| 223 |
}
|
| 224 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 225 |
upgrade_nfsroot() {
|
| 226 |
|
| 227 |
cp /etc/resolv.conf $NFSROOT/etc
|
| 228 |
$ROOTCMD apt-get update
|
| 229 |
$ROOTCMD apt-get check
|
| 230 |
rm -rf $NFSROOT/etc/apm
|
| 231 |
mount -t proc /proc $NFSROOT/proc
|
| 232 |
$ROOTCMD apt-get --purge -y remove debconf+ pcmcia-cs ppp pppconfig </dev/null
|
| 233 |
|
| 234 |
# fake start-stop-dameon
|
| 235 |
$ROOTCMD dpkg-divert --quiet --package fai --add --rename /sbin/start-stop-daemon
|
| 236 |
cp $LIBFAI/sbin/start-stop-daemon $NFSROOT/sbin
|
| 237 |
$ROOTCMD apt-get -y upgrade
|
| 238 |
}
|
| 239 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 240 |
add_packages_nfsroot() {
|
| 241 |
|
| 242 |
$ROOTCMD apt-get -y --fix-missing install $packages </dev/null
|
| 243 |
$ROOTCMD apt-get clean
|
| 244 |
}
|
| 245 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 246 |
get_basetgz() {
|
| 247 |
|
| 248 |
[ -f /tmp/base2_2.tgz ] && return
|
| 249 |
[ "$FAI_BASETGZ" ] || die "No /tmp/base2_2.tgz found and FAI_BASETGZ not defined."
|
| 250 |
case $FAI_BASETGZ in
|
| 251 |
ftp:*|http:*)
|
| 252 |
echo "Fetching $FAI_BASETGZ via wget. This may take some time."
|
| 253 |
TMPBDIR=`mktemp /tmp/FAI-wget-XXXXXX` || exit 1
|
| 254 |
rm $TMPBDIR; mkdir $TMPBDIR || exit
|
| 255 |
wget -P$TMPBDIR $FAI_BASETGZ
|
| 256 |
mv $TMPBDIR/base2_2.tgz /tmp
|
| 257 |
rm -rf $TMPBDIR
|
| 258 |
;;
|
| 259 |
/*/base2_2.tgz)
|
| 260 |
rm -f /tmp/base2_2.tgz
|
| 261 |
test -r $FAI_BASETGZ || die "Can't read $FAI_BASETGZ. Check FAI_BASETGZ in fai.conf."
|
| 262 |
ln -s $FAI_BASETGZ /tmp
|
| 263 |
;;
|
| 264 |
*)
|
| 265 |
die "FAI_BASETGZ in fai.conf is $FAI_BASETGZ and looks very strange."
|
| 266 |
;;
|
| 267 |
esac
|
| 268 |
}
|
| 269 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 270 |
umount_dirs() {
|
| 271 |
|
| 272 |
cd /
|
| 273 |
sleep 2
|
| 274 |
umount $NFSROOT/proc 1>/dev/null 2>&1 || true
|
| 275 |
umount $NFSROOT/dev/pts 1>/dev/null 2>&1 ||true
|
| 276 |
if [ "$FAI_DEBMIRROR" ]; then
|
| 277 |
test -d $NFSROOT/$MNTPOINT && umount $NFSROOT/$MNTPOINT || true
|
| 278 |
fi
|
| 279 |
# show directories still mounted on nfsroot
|
| 280 |
mount | grep " on $NFSROOT " || true
|
| 281 |
}
|
| 282 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 283 |
# main routine
|
| 284 |
|
| 285 |
if [ -d $NFSROOT/fai ]; then
|
| 286 |
echo $NFSROOT already exists. Removing $NFSROOT
|
| 287 |
umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true
|
| 288 |
rm -rf $NFSROOT/.??* $NFSROOT/*
|
| 289 |
# also remove files $NFSROOT/.? but not . and ..
|
| 290 |
find $NFSROOT ! -type d -xdev -maxdepth 1 | xargs -r rm -f
|
| 291 |
fi
|
| 292 |
|
| 293 |
create_nfsroot
|
| 294 |
|
| 295 |
if [ -f $KERNELPACKAGE ]; then
|
| 296 |
# create tftp boot images
|
| 297 |
install_kernel_nfsroot
|
| 298 |
|
| 299 |
grep -q ic_bootp $NFSROOT/boot/System.map-$KERNELVERSION && TYPE=BOOTP
|
| 300 |
# only BOOTP need a netboot image, DHCP can do with raw kernels
|
| 301 |
if [ "$TYPE" = BOOTP ]; then
|
| 302 |
mknbi-linux --verbose $NFSROOT/boot/vmlinuz-$KERNELVERSION /boot/fai/installimage
|
| 303 |
else
|
| 304 |
cp -p $NFSROOT/boot/vmlinuz-$KERNELVERSION /boot/fai/installimage
|
| 305 |
fi
|
| 306 |
# TODO: does dhcp need imggen ?
|
| 307 |
# imggen is free software from 3com
|
| 308 |
# it converts netboot image to images, that are bootable by 3com network cards
|
| 309 |
imggen=`which imggen || true`
|
| 310 |
if [ -x "$imggen" ]; then
|
| 311 |
imggen -a /boot/fai/installimage /boot/fai/installimage_3com
|
| 312 |
fi
|
| 313 |
else
|
| 314 |
echo "Kernel package $KERNELPACKAGE not found."
|
| 315 |
echo "No install kernel installed in /boot/fai."
|
| 316 |
echo "No kernel modules available in nfsroot."
|
| 317 |
fi
|
| 318 |
|
| 319 |
echo make-fai-nfsroot finished.
|
| 320 |
exit 0
|