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-2005 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
PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin
32
if [ `id -u` -ne 0 ]; then
33
echo "Run this program as root."
38
# option e currently does nothing
39
while getopts ervc:f:kK opt ; do
42
v) verbose=1 ; v=-v ;;
46
K) kremove=1; kinstall=1 ;;
48
?) exit 5 ;; # error in option parsing
54
[ -z "$cfdir" ] && cfdir=/etc/fai
55
if [ ! -d "$cfdir" ]; then
56
echo "$cfdir is not a directory"
59
[ "$verbose" ] && echo "Using configuration files from directory $cfdir"
60
if [ -n "$cfg" ]; then
66
# read config file for this tool
67
if [ -f "$cfdir/make-fai-nfsroot.conf" ]; then
68
. $cfdir/make-fai-nfsroot.conf
70
echo "Can't read $cfdir/make-fai-nfsroot.conf"
74
if [ -z "$NFSROOT" ]; then
75
echo "\$NFSROOT is not set. Please check your settings in $cfdir/fai.conf."
79
if [ "$FAI_SOURCES_LIST" ]; then
80
echo "The usage of the variable \$FAI_SOURCES_LIST is deprecated. Please use sources.list now."
84
if [ ! -s "$cfdir/sources.list" -a ! -f /etc/apt/sources.list ]; then
85
echo "Neither $cfdir/sources.list nor /etc/apt/sources.list exists."
86
echo "I think something is wrong. Can't continue."
91
case `dpkg --print-installation-architecture` in
93
arch_packages="grub lilo kudzu dmidecode hwtools read-edid" ;;
96
arch_packages="grub lilo kudzu dmidecode" ;;
99
arch_packages="elilo gnu-efi efibootmgr" ;;
102
arch_packages="silo sparc-utils" ;;
108
arch_packages="aboot" ;;
110
*) arch_packages="" ;;
115
ROOTCMD="chroot $NFSROOT"
117
RUNDIR=/var/run/fai/make-fai-nfsroot
118
[ ! -d $RUNDIR ] && mkdir -p $RUNDIR
119
export DEBIAN_FRONTEND=noninteractive
120
[ "$recover" ] || rm -rf $RUNDIR/*
122
trap "umount_dirs" EXIT
124
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
128
echo "An error occured during make-fai-nfsroot."
129
echo "Please fix the error or try make-fai-nfsroot -v"
131
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
137
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
141
local stamp=$RUNDIR/$func
143
[ "$recover" -a -f $stamp ] && return 0
147
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
150
if [ "$verbose" ]; then
156
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
157
install_kernel_nfsroot() {
159
rm -rf $NFSROOT/boot/*-$KERNELVERSION $NFSROOT/lib/modules/$KERNELVERSION
160
# since woody we can install the kernel using dpkg -i
161
echo "do_boot_enable=no" > $NFSROOT/etc/kernel-img.conf
162
dpkg -x $KERNELPACKAGE $NFSROOT
163
# if $NFROOT/proc/modules exists, then update-modules calls depmod -a without
164
# these special flags; so umount first
165
[ -e $NFSROOT/proc/modules ] && umount $NFSROOT/proc
166
chroot $NFSROOT update-modules
167
chroot $NFSROOT depmod -qaF /boot/System.map-$KERNELVERSION $KERNELVERSION || true
169
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
172
# nothing to do if no ssh is available in nfsroot
173
[ -f $NFSROOT/var/lib/dpkg/info/ssh.list ] || return 0
174
mkdir -p -m 700 $NFSROOT/root/.ssh
175
if [ -n "$LOGUSER" ] ; then
176
loguserhome=`eval "cd ~$LOGUSER 2>/dev/null && pwd;true"`
177
# is copying of *.pub important?
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/
184
cp -p $loguserhome/.ssh/*.pub $NFSROOT/root/.ssh/
189
perl -pi -e 's/PermitRootLogin no/PermitRootLogin yes/' $NFSROOT/etc/ssh/sshd_config
190
if [ -f "$SSH_IDENTITY" ]; then
191
cp $SSH_IDENTITY $NFSROOT/root/.ssh/authorized_keys
192
chmod 0644 $NFSROOT/root/.ssh/authorized_keys
193
echo You can log into install clients without password using $SSH_IDENTITY
196
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
200
perl -pi -e "s#^root::#root:${FAI_ROOTPW}:#" etc/passwd
202
cp -Rpv $cfdir/* $NFSROOT/etc/fai
203
# remove some files that should not be copied
204
rm -f $NFSROOT/etc/fai/make-fai-nfsroot.conf
205
[ -f $cfdir/.cvspass ] && cp -p $v $cfdir/.cvspass $NFSROOT/.cvspass
206
$ROOTCMD shadowconfig on
208
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
211
echo "Creating nfsroot for $1 using debootstrap"
212
[ "$verbose" ] && echo "Calling debootstrap $1 $NFSROOT $2"
213
yes '' | LC_ALL=C call_verbose debootstrap $FAI_DEBOOTSTRAP_OPTS $1 $NFSROOT $2 || true
215
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
218
if [ "$FAI_DEBOOTSTRAP" ]; then
219
call_with_stamp call_debootstrap $FAI_DEBOOTSTRAP
220
$ROOTCMD apt-get clean
221
rm -f $NFSROOT/etc/resolv.conf
222
echo "Creating base.tgz"
223
tar -l -C $NFSROOT -cf - --exclude var/tmp/base.tgz . | gzip > $NFSROOT/var/tmp/base.tgz
224
touch $NFSROOT/.THIS_IS_THE_FAI_NFSROOT
226
die "\$FAI_DEBOOTSTRAP not defined."
229
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
232
mkdir -p $NFSROOT/$FAI
233
cd $NFSROOT || die "Error: Can't cd to $NFSROOT"
235
call_with_stamp create_base
236
# save the list of all packages in the base.tgz
237
$ROOTCMD dpkg --get-selections | egrep 'install$' | awk '{print $1}' > var/tmp/base-pkgs.lis
238
echo $arch_packages > $NFSROOT/var/tmp/packages.arch
240
if [ "$FAI_DEBMIRROR" ]; then
241
[ "$verbose" ] && echo "Mounting $FAI_DEBMIRROR to $NFSROOT/$MNTPOINT."
242
mkdir -p $NFSROOT/$MNTPOINT
243
mount -o ro,noatime,rsize=8192 $FAI_DEBMIRROR $NFSROOT/$MNTPOINT || \
244
die "Can't mount $FAI_DEBMIRROR to $NFSROOT/$MNTPOINT."
247
# hoaks some packages
248
# liloconfig, dump and raidtool2 needs these files
249
echo "# UNCONFIGURED FSTAB FOR BASE SYSTEM" > etc/fstab
251
mkdir -p lib/modules/$KERNELVERSION # dirty trick to hoax lvm
252
> lib/modules/$KERNELVERSION/modules.dep # dirty trick to hoax lvm
253
echo 'NTPSERVERS=""' > etc/default/ntp-servers
255
[ -d $NFSROOT/var/state ] || mkdir $NFSROOT/var/state
256
[ "$verbose" ] && echo "Try to copy $cfdir/sources.list or /etc/apt/sources.list."
257
cp -v $cfdir/sources.list $NFSROOT/etc/apt/sources.list || \
258
cp -v /etc/apt/sources.list $NFSROOT/etc/apt/sources.list || \
259
{ echo "No sources.list file found."
260
echo "I think something is wrong. But I'll try to continue."
263
echo "127.0.0.1 localhost" >> etc/hosts
264
echo "$NFSROOT_ETC_HOSTS" >> etc/hosts
265
[ -f /etc/apt/preferences ] && cp -v /etc/apt/preferences $NFSROOT/etc/apt
266
[ -f $cfdir/preferences ] && cp -v $cfdir/preferences $NFSROOT/etc/apt
267
echo "Upgrading $NFSROOT"
268
LC_ALL=C call_verbose call_with_stamp upgrade_nfsroot
269
echo "Adding additional packages to $NFSROOT:"
271
LC_ALL=C call_verbose call_with_stamp add_packages_nfsroot
272
call_with_stamp copy_fai_files
274
# set timezone in nfsroot
275
timezone=$(readlink /etc/localtime | sed 's%^/usr/share/zoneinfo/%%')
276
echo $timezone > etc/timezone
277
rm -f etc/localtime && ln -sf /usr/share/zoneinfo/$timezone etc/localtime
279
# make little changes to nfsroot, because nfsroot is
280
# read only for the install clients
281
rm -rf etc/mtab var/run etc/sysconfig
282
ln -s /proc/mounts etc/mtab
283
ln -s /tmp/var/run var/run
284
ln -sf /tmp/var/state/discover var/state/discover
285
ln -sf /tmp/var/lib/discover var/lib/discover
286
ln -s /tmp/etc/syslogsocket dev/log
287
ln -sf /tmp/etc/resolv.conf etc/resolv.conf
288
ln -sf /tmp etc/sysconfig
289
ln -s /usr/sbin/fai etc/init.d/rcS
290
ln -sf /dev/null etc/network/ifstate
292
[ -d var/yp ] && ln -s /tmp/binding var/yp/binding
294
# turn off logging of loading kernel modules
295
[ -d var/log/ksymoops/ ] && rmdir var/log/ksymoops/
296
ln -s /dev/null var/log/ksymoops
298
# definition for loopback device
299
echo "iface lo inet loopback" > etc/network/interfaces
301
echo "*.* /tmp/fai/syslog.log" > etc/syslog.conf
302
cat >> root/.profile <<-EOF
303
PATH=/usr/local/sbin:/usr/local/bin:/usr/lib/fai:/bin:/sbin:/usr/bin:/usr/sbin:
305
. /usr/lib/fai/subroutines
306
. /usr/lib/fai/subroutines-$OS_TYPE
308
. /tmp/fai/variables.sh 2>/dev/null
311
call_verbose call_with_stamp setup_ssh
313
cat >$NFSROOT/etc/rc2.d/S01fai_abort <<-EOF
315
echo FAI: installation aborted.
316
echo reboot with: faireboot
317
echo or after a logout
323
chmod a+rx $NFSROOT/etc/rc2.d/S01fai_abort
325
echo -e "\n$FAI_LOCAL_REPOSITORY" >> etc/apt/sources.list
327
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
330
cp -p $v /etc/resolv.conf $NFSROOT/etc/resolv.conf-installserver
331
cp -p $v /etc/resolv.conf $NFSROOT/etc/resolv.conf # this is needed during make-fai-nfsroot
332
$ROOTCMD apt-get update
333
$ROOTCMD apt-get -fyu install
334
$ROOTCMD apt-get check
335
rm -rf $NFSROOT/etc/apm
336
mount -t proc /proc $NFSROOT/proc
338
fdivert /sbin/start-stop-daemon /sbin/discover-modprobe
339
cp -p /sbin/fai-start-stop-daemon $NFSROOT/sbin/start-stop-daemon
340
$ROOTCMD apt-get -y dist-upgrade
342
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
343
add_packages_nfsroot() {
345
$ROOTCMD apt-get -y --fix-missing install $packages </dev/null
346
if [ -n "$NFSROOT_PACKAGES" ] ; then
347
LC_ALL=C $ROOTCMD apt-get -y --fix-missing install $NFSROOT_PACKAGES </dev/null
349
$ROOTCMD apt-get clean
351
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
354
[ -f $NFSROOT/usr/sbin/dpkg-divert ] &&
355
LC_ALL=C $ROOTCMD dpkg-divert --rename --remove /sbin/discover-modprobe
358
[ -d $NFSROOT/proc/self ] && umount $NFSROOT/proc
359
[ -d $NFSROOT/proc/self ] && umount $NFSROOT/dev/pts
360
if [ "$FAI_DEBMIRROR" ]; then
361
test -d $NFSROOT/$MNTPOINT && umount $NFSROOT/$MNTPOINT || true
363
# show directories still mounted on nfsroot
364
mount | grep " on $NFSROOT " || true
366
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
367
get_kernel_version() {
370
KERNELVERSION=`dpkg --info $package | grep "Package: kernel-image" | sed -e 's/.*kernel-image-'//`
372
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
375
if [ -x "`which mkelf-linux`" ]; then
376
mkelf-linux --ip=any --output=/boot/fai/installimage \
377
$NFSROOT/boot/$kfile-$KERNELVERSION
379
echo "Command mkelf-linux not found. Can not set up BOOTP booting. Please install the package mknbi and rerun fai-setup."
383
# imggen is free software from 3com - use ver1.00: 1.01 produces "Image too Big" errors.
384
# it converts netboot images to images which are bootable by 3com network cards
385
if [ -x "`which imggen`" ]; then
386
imggen -a /boot/fai/installimage /boot/fai/installimage_3com
388
echo "BOOTP environment prepared."
391
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
394
# pxe and dhcp environment
395
local pxebin=/usr/lib/syslinux/pxelinux.0
396
cp -p $NFSROOT/boot/$kfile-$KERNELVERSION /boot/fai/$kfile-install
397
[ -f $pxebin ] && cp $pxebin /boot/fai
398
[ -d /boot/fai/pxelinux.cfg ] || mkdir -p /boot/fai/pxelinux.cfg || true
399
echo "DHCP environment prepared. If you want to use it, you have to enable the dhcpd and the tftp-hpa daemon."
401
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
406
LC_ALL=C $ROOTCMD dpkg-divert --quiet --add --rename $item
409
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
412
# Install the kernel package
413
if [ -f $KERNELPACKAGE ]; then
414
# determine kernel version
415
get_kernel_version $KERNELPACKAGE
417
# create tftp boot images
418
call_with_stamp install_kernel_nfsroot
420
# setup for DHCP, BOOTP or both
421
[ "x$FAI_BOOT" = "x" ] && FAI_BOOT="dhcp bootp"
423
for bootopt in $FAI_BOOT; do
426
call_with_stamp setup_dhcp ;;
428
call_with_stamp setup_bootp ;;
430
echo "Unknown boot option" ;;
435
echo "Error. Kernel package $KERNELPACKAGE not found."
436
echo "No install kernel installed in /boot/fai."
437
echo "No kernel modules available in nfsroot."
440
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
443
[ -z "$KERNELPACKAGE" ] && die "\$KERNELPACKAGE is not set. Aborting."
445
# remove all kernels from nfsroot
446
[ -n "$kremove" ] && {
447
echo "Removing all kernels from NFSROOT."
448
rm -f $NFSROOT/boot/{System.map,vmlinuz,config}*
449
rm -rf $NFSROOT/lib/modules/2.*
452
# just install a new kernel to the nfsroot
453
[ -n "$kinstall" ] && {
455
echo "Installing new kernel into the nfsroot."
457
echo "New kernel from" $KERNELPACKAGE "installed into the nfsroot."
461
echo Creating FAI nfsroot can take a long time and will
462
echo need more than $nfssize disk space in $NFSROOT.
464
# Kill the directory if not in recover mode
465
if [ -d $NFSROOT/$FAI -a ! "$recover" ]
467
echo $NFSROOT already exists. Removing $NFSROOT
468
umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true
469
rm -rf $NFSROOT/.??* $NFSROOT/*
470
# also remove files $NFSROOT/.? but not . and ..
471
find $NFSROOT ! -type d -xdev -maxdepth 1 | xargs -r rm -f
474
# Create a new nfsroot
475
if [ ! -x "`which debootstrap`" ]; then
476
die "Can't find debootstrap command. Aborting."
478
call_with_stamp create_nfsroot
484
echo "make-fai-nfsroot finished $merror."