3
# $Id: make-fai-nfsroot 4592 2007-09-17 10:19:07Z lange $
4
#*********************************************************************
6
# make-fai-nfsroot -- create nfsroot directory and add additional packages
8
# This script is part of FAI (Fully Automatic Installation)
9
# (c) 2000-2007 by Thomas Lange, lange@informatik.uni-koeln.de
10
# Universitaet zu Koeln
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.
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.
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
#*********************************************************************
30
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
34
Copyright (C) 1999-2007 Thomas Lange
35
Report bugs to <fai@informatik.uni-koeln.de>.
37
Usage: make-fai-nfsroot [OPTIONS]
38
Create an NFSROOT for FAI.
39
Read the man pages pages make-fai-nfsroot(8).
43
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
49
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
51
PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin
53
kfile="vmlinuz" # some architectures use different names
58
if [ -f /etc/lsb-release ]; then
65
# option e currently does nothing
66
while getopts hervC:f:kKpU opt ; do
69
v) verbose=1 ; v=-v ;;
71
f) die "Option -f is not supported any more. Use option -C instead" ;;
75
e) expert=1 ;; # a dummy option, that only fai-setup uses
78
?) exit 5 ;; # error in option parsing
82
if [ $(id -u) != "0" ]; then
83
echo "Run this program as root."
89
# use FAI_ETC_DIR from environment variable
90
if [ -n "$FAI_ETC_DIR" -a -z "$cfdir" ]; then
91
echo "Using environment variable \$FAI_ETC_DIR."
93
[ -z "$cfdir" ] && cfdir=${FAI_ETC_DIR:=/etc/fai}
94
cfdir=$(readlink -f $cfdir) # canonicalize path
95
if [ ! -d "$cfdir" ]; then
96
echo "$cfdir is not a directory"
99
[ "$verbose" ] && echo "Using configuration files from $cfdir"
102
# read config file for this tool
103
if [ -f "$cfdir/make-fai-nfsroot.conf" ]; then
104
. $cfdir/make-fai-nfsroot.conf
106
echo "Can't read $cfdir/make-fai-nfsroot.conf"
110
# IMO this may be removed, since all information should be included into sources.list
111
[ -n "$FAI_LOCAL_REPOSITORY" ] && die "The use of \$FAI_LOCAL_REPOSITORY is now deprecated. Please include this information into sources.list."
112
[ -n "$packages" ] && die "The use of \$packages in make-fai-nfsroot.conf is now deprecated. Please include this information into $cfdir/NFSROOT."
113
[ -n "$NFSROOT_PACKAGES" ] && die "The use of \$NFSROOT_PACKAGES in make-fai-nfsroot.conf is now deprecated. Please include this information into $cfdir/NFSROOT."
114
[ -n "$FAI_SOURCES_LIST" ] && die "The use of \$FAI_SOURCES_LIST is deprecated. Please use sources.list now."
116
[ -z "$NFSROOT" ] && die "\$NFSROOT is not set. Please check your settings in $cfdir/fai.conf."
117
[ ! -d "$cfdir/apt" ] && die "$cfdir/apt/ does not exists. Can't continue."
119
NFSROOT="$NFSROOT/live/filesystem.dir"
120
ROOTCMD="chroot $NFSROOT"
122
RUNDIR=/var/run/fai/make-fai-nfsroot
124
export DEBIAN_FRONTEND=noninteractive
125
[ "$recover" ] || rm -rf $RUNDIR/*
127
trap 'echo "Aborting";umount_dirs' EXIT
129
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
133
echo "An error occured during make-fai-nfsroot."
134
echo "Please fix the error or try make-fai-nfsroot -v"
136
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
140
local stamp=$RUNDIR/$func
142
[ "$recover" -a -f $stamp ] && return 0
146
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
149
if [ "$verbose" ]; then
155
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
156
install_kernel_nfsroot() {
158
if [ $divert = 1 ]; then
159
rm $NFSROOT/usr/sbin/update-initramfs
160
LC_ALL=C $ROOTCMD dpkg-divert --rename --remove /usr/sbin/update-initramfs
161
$ROOTCMD update-initramfs -k all -t -u
164
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
167
# nothing to do if no ssh is available in nfsroot
168
[ -f $NFSROOT/usr/bin/ssh ] || return 0
169
if [ $sshpreserve = 1 ]; then
170
tar -C $NFSROOT -xf $tmptar
175
mkdir -p -m 700 $NFSROOT/root/.ssh
176
if [ -n "$LOGUSER" ] ; then
177
loguserhome=`eval "cd ~$LOGUSER 2>/dev/null && pwd;true"`
178
[ -f $loguserhome/.ssh/known_hosts ] && cp $loguserhome/.ssh/known_hosts $NFSROOT/root/.ssh/known_hosts
179
[ -d $loguserhome/.ssh ] && {
180
[ -f $loguserhome/.ssh/id_dsa ] &&
181
cp -p $loguserhome/.ssh/id_dsa* $NFSROOT/root/.ssh/
182
[ -f $loguserhome/.ssh/id_rsa ] &&
183
cp -p $loguserhome/.ssh/id_rsa* $NFSROOT/root/.ssh/
188
perl -pi -e 's/PermitRootLogin no/PermitRootLogin yes/' $NFSROOT/etc/ssh/sshd_config
189
if [ -f "$SSH_IDENTITY" ]; then
190
cp $SSH_IDENTITY $NFSROOT/root/.ssh/authorized_keys
191
chmod 0644 $NFSROOT/root/.ssh/authorized_keys
192
echo You can log into install clients without password using $SSH_IDENTITY
195
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
199
echo "root:$FAI_ROOTPW" | $ROOTCMD chpasswd --encrypted
200
cp -Rpv $cfdir/* $NFSROOT/etc/fai
201
# append additional variables to fai.conf for the install clients
202
[ -z "$FAI_CONFIG_SRC" ] && echo "FAI_CONFIG_SRC=nfs://`hostname`$FAI_CONFIGDIR" >> $NFSROOT/etc/fai/fai.conf
204
# remove some files that should not be copied
205
rm -f $NFSROOT/etc/fai/make-fai-nfsroot.conf
206
[ -f $cfdir/.cvspass ] && cp -p $v $cfdir/.cvspass $NFSROOT/.cvspass
207
$ROOTCMD shadowconfig on
209
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
212
local dversion=$(dpkg -l debootstrap | grep debootstrap | cut -f7 -d' ')
213
echo "Creating base system using debootstrap version $dversion"
214
echo "Calling debootstrap $1 $NFSROOT $2"
215
yes '' | LC_ALL=C call_verbose debootstrap $FAI_DEBOOTSTRAP_OPTS $1 $NFSROOT $2
217
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
218
add_all_host_entries() {
220
local ips=$(ifconfig | grep -w inet | cut -d : -f 2 | cut -d ' ' -f 1 | grep -v 127.0.0.1)
222
getent hosts $eth >> etc/hosts || true
225
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
228
if [ "$FAI_DEBOOTSTRAP" ]; then
229
call_with_stamp call_debootstrap $FAI_DEBOOTSTRAP
230
$ROOTCMD apt-get clean
231
rm -f $NFSROOT/etc/resolv.conf
232
echo "Creating base.tgz"
233
tar --one-file-system -C $NFSROOT -cf - --exclude var/tmp/base.tgz . | gzip > $NFSROOT/var/tmp/base.tgz
234
touch $NFSROOT/.THIS_IS_THE_FAI_NFSROOT
236
die "\$FAI_DEBOOTSTRAP not defined."
239
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
242
mkdir -p $NFSROOT/$FAI
243
cd $NFSROOT || die "Can't cd to $NFSROOT"
245
call_with_stamp create_base
246
# save the list of all packages in the base.tgz
247
$ROOTCMD dpkg --get-selections | egrep 'install$' | awk '{print $1}' > var/tmp/base-pkgs.lis
249
if [ "$FAI_DEBMIRROR" ]; then
250
[ "$verbose" ] && echo "Mounting $FAI_DEBMIRROR to $NFSROOT/$MNTPOINT."
251
mkdir -p $NFSROOT/$MNTPOINT
252
mount -o ro,noatime,rsize=8192 $FAI_DEBMIRROR $NFSROOT/$MNTPOINT || \
253
die "Can't mount $FAI_DEBMIRROR to $NFSROOT/$MNTPOINT."
256
# hoaks some packages
257
# liloconfig, dump and raidtool2 needs these files
258
echo "# UNCONFIGURED FSTAB FOR BASE SYSTEM" > etc/fstab
260
echo 'NTPSERVERS=""' > etc/default/ntp-servers
262
# live.conf will set hostname to debian
263
cp /dev/null etc/live.conf
265
cp -a $cfdir/apt $NFSROOT/etc
267
ainsl -as $NFSROOT/etc/hosts "127.0.0.1 localhost"
268
ainsl $NFSROOT/etc/hosts "$NFSROOT_ETC_HOSTS"
271
# we need these option before installing the first package. So we
272
# can't put this into fai-nfsroot /etc/apt/apt.conf.d/90fai
273
cat <<EOF >$NFSROOT/etc/apt/apt.conf.d/10fai
274
APT::Get::AllowUnauthenticated "true";
275
Aptitude::CmdLine::Ignore-Trust-Violations yes;
277
echo "Upgrading $NFSROOT"
278
LC_ALL=C call_verbose call_with_stamp upgrade_nfsroot
279
LC_ALL=C call_with_stamp add_packages_nfsroot
280
call_with_stamp copy_fai_files
282
# set timezone in nfsroot
283
timezone=$(readlink /etc/localtime | sed 's%^/usr/share/zoneinfo/%%')
284
echo $timezone > etc/timezone
285
rm -f etc/localtime && ln -sf /usr/share/zoneinfo/$timezone etc/localtime
287
rm etc/mtab && ln -s /proc/mounts etc/mtab
288
ln -s /usr/sbin/fai etc/init.d/rcS
290
# [ -d var/yp ] && ln -s /tmp/binding var/yp/binding
292
# definition for loopback device
293
echo "iface lo inet loopback" > etc/network/interfaces
295
cat >> root/.profile <<-EOF
296
PATH=/usr/local/sbin:/usr/local/bin:/usr/lib/fai:/bin:/sbin:/usr/bin:/usr/sbin:
298
. /usr/lib/fai/subroutines
299
. /usr/lib/fai/subroutines-linux
301
. /tmp/fai/variables.log 2>/dev/null
304
call_verbose call_with_stamp setup_ssh
306
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
309
if [ -f /etc/resolv.conf ]; then
310
cp -p $v /etc/resolv.conf $NFSROOT/etc/resolv.conf-installserver
311
cp -p $v /etc/resolv.conf $NFSROOT/etc/resolv.conf # this is needed during make-fai-nfsroot
313
$ROOTCMD apt-get update
314
$ROOTCMD apt-get -fy install fai-nfsroot
315
$ROOTCMD apt-get check
316
rm -rf $NFSROOT/etc/apm
317
mount -t proc /proc $NFSROOT/proc
319
if [ $divert = 1 ]; then
320
fdivert /usr/sbin/update-initramfs
321
ln -s /bin/true $NFSROOT/usr/sbin/update-initramfs
323
fdivert /sbin/start-stop-daemon /sbin/discover-modprobe
324
cp -p /sbin/fai-start-stop-daemon $NFSROOT/sbin
325
cp -p /sbin/fai-start-stop-daemon $NFSROOT/sbin/start-stop-daemon
326
$ROOTCMD apt-get -y dist-upgrade
328
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
329
add_packages_nfsroot() {
331
local iarch=$($ROOTCMD dpkg --print-installation-architecture|tr /a-z/ /A-Z/)
332
export FAI_ROOT=$NFSROOT
333
export classes="NFSROOT $iarch"
334
cat > $NFSROOT/etc/kernel-img.conf << EOF
339
install_packages -l -p$cfdir > $NFSROOT/var/tmp/packages.nfsroot
340
echo "Adding additional packages to $NFSROOT:"
341
cat $NFSROOT/var/tmp/packages.nfsroot
342
call_verbose install_packages $v -p$cfdir
344
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
347
[ -f $NFSROOT/usr/sbin/dpkg-divert ] &&
348
LC_ALL=C $ROOTCMD dpkg-divert --rename --remove /sbin/discover-modprobe
350
[ -d $NFSROOT/proc/self ] && umount $NFSROOT/proc
351
[ -d $NFSROOT/proc/self ] && umount $NFSROOT/dev/pts
352
if [ "$FAI_DEBMIRROR" ]; then
353
test -d $NFSROOT/$MNTPOINT && umount $NFSROOT/$MNTPOINT || true
355
# show directories still mounted on nfsroot
356
mount | grep " on $NFSROOT " || true
358
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
359
get_kernel_version() {
363
KERNELVERSION=`dpkg --info $package | grep ' Package: '`
364
KERNELVERSION=${KERNELVERSION/*-image-/}
366
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
370
if [ -x "`which mkelf-linux`" ]; then
371
# does not work any mork if we do not know the excatly kernel name
373
# mkelf-linux --ip=any --output=$TFTPROOT/installimage \
374
# $NFSROOT/boot/$kfile-$KERNELVERSION
376
echo "Command mkelf-linux not found. Can not set up BOOTP booting. Please install the package mknbi and rerun fai-setup."
380
# imggen is free software from 3com - use ver1.00: 1.01 produces "Image too Big" errors.
381
# it converts netboot images to images which are bootable by 3com network cards
382
if [ -x "`which imggen`" ]; then
383
imggen -a $TFTPROOT/installimage $TFTPROOT/installimage_3com
385
echo "BOOTP environment prepared."
388
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
391
# pxe and dhcp environment
392
local pxebin=/usr/lib/syslinux/pxelinux.0
393
rm -f $NFSROOT/boot/*.bak
394
mkdir -p $TFTPROOT/pxelinux.cfg
395
cp -pv $NFSROOT/boot/$kfile-* $TFTPROOT
396
cp -pv $NFSROOT/boot/initrd.img-* $TFTPROOT
397
[ -f $pxebin ] && cp $pxebin $TFTPROOT
398
echo "DHCP environment prepared. If you want to use it, you have to enable the dhcpd and the tftp-hpa daemon."
400
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
405
LC_ALL=C $ROOTCMD dpkg-divert --quiet --add --rename $item
408
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
411
# Install the kernel package
413
# create tftp boot images
414
call_with_stamp install_kernel_nfsroot
416
# setup for DHCP, BOOTP or both
417
[ "x$FAI_BOOT" = "x" ] && FAI_BOOT="dhcp bootp"
419
for bootopt in $FAI_BOOT; do
422
call_with_stamp setup_dhcp ;;
424
call_with_stamp setup_bootp ;;
426
echo "Unknown boot option" ;;
430
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
434
if [ -z "$NFSROOT_HOOKS" ]; then
437
if [ -d "$NFSROOT_HOOKS" ]; then
438
echo "Running hooks..."
439
for file in `ls $NFSROOT_HOOKS/* 2>/dev/null`; do
444
# - - - - - - - - - - - - - - - - - - - - - - - - - -
447
# remove all kernels from nfsroot
448
[ -n "$kremove" ] && {
449
echo "Removing all kernels from NFSROOT."
450
$ROOTCMD aptitude -y purge ~nlinux-image
454
# just install a new kernel to the nfsroot
455
[ -n "$kinstall" ] && {
457
echo "Installing new kernel into the nfsroot."
458
if [ $divert = 1 ]; then
459
fdivert /usr/sbin/update-initramfs
460
ln -s /bin/true $NFSROOT/usr/sbin/fai
462
LC_ALL=C add_packages_nfsroot
467
echo "make-fai-nfsroot finished $merror."
471
echo "Creating FAI nfsroot in $NFSROOT."
472
echo "By default it needs more than 330 MBytes disk space."
473
echo "This may take a long time."
475
if [ $sshpreserve = 1 ]; then
476
# save old .ssh directory
477
tmptar=$(mktemp) || exit 12
478
# should we set the umask before? Does it influence the other parts?
479
tar -C $NFSROOT -cvf $tmptar root/.ssh
482
# Kill the directory if not in recover mode
483
if [ -d $NFSROOT/$FAI -a ! "$recover" ]
485
echo $NFSROOT already exists. Removing $NFSROOT
486
umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true
487
rm -rf $NFSROOT/.??* $NFSROOT/*
488
# also remove files $NFSROOT/.? but not . and ..
489
find $NFSROOT -xdev -maxdepth 1 ! -type d | xargs -r rm -f
492
# Create a new nfsroot
493
if [ ! -x "`which debootstrap`" ]; then
494
die "Can't find debootstrap command. Aborting."
496
call_with_stamp create_nfsroot
502
echo "make-fai-nfsroot finished $merror."