| 1 |
#! /bin/sh
|
| 2 |
|
| 3 |
# $Id$
|
| 4 |
#*********************************************************************
|
| 5 |
#
|
| 6 |
# make-fai-bootfloppy -- create a boot floppy for FAI
|
| 7 |
#
|
| 8 |
# This script is part of FAI (Fully Automatic Installation)
|
| 9 |
# (c) 2000-2002 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 |
version="version 1.6, january 2001"
|
| 31 |
set -e
|
| 32 |
MKIMAGE=0
|
| 33 |
floppydev=/dev/fd0
|
| 34 |
mountopts=""
|
| 35 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 36 |
die() {
|
| 37 |
|
| 38 |
echo -e $*
|
| 39 |
exit 99
|
| 40 |
}
|
| 41 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 42 |
determine_kernel_version() {
|
| 43 |
|
| 44 |
local num all
|
| 45 |
all=$(ls $NFSROOT/boot/System.map-*)
|
| 46 |
if [ `echo $all | wc -l ` = 1 ]; then
|
| 47 |
KERNELVERSION=$(echo "kernel version $all" | sed -e 's#.*/System.map-##')
|
| 48 |
else
|
| 49 |
die "Can't determine kernel version for $all"
|
| 50 |
fi
|
| 51 |
}
|
| 52 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 53 |
usage() {
|
| 54 |
|
| 55 |
cat <<EOF
|
| 56 |
make-fai-bootfloppy, create a boot floppy for FAI. $version
|
| 57 |
|
| 58 |
Copyright (C) 2000, 2001 by Thomas Lange
|
| 59 |
|
| 60 |
Usage: make-fai-bootfloppy [parameter]
|
| 61 |
|
| 62 |
-h print this message.
|
| 63 |
-f file make a 1440k floppy image
|
| 64 |
|
| 65 |
DESCRIPTION
|
| 66 |
Creates a boot floppy for booting a FAI install client.
|
| 67 |
No arguments are needed but you must be root.
|
| 68 |
All parameters are passed to the kernel via append in lilo.conf.
|
| 69 |
|
| 70 |
EXAMPLE
|
| 71 |
To make a boot floppy for my old SMC EtherCard Plus Elite 16T, I use
|
| 72 |
|
| 73 |
# make-fai-bootfloppy "reserve=0x300,32 ether=10,0x300,eth0"
|
| 74 |
|
| 75 |
EOF
|
| 76 |
exit 0
|
| 77 |
}
|
| 78 |
|
| 79 |
# - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 80 |
# main part
|
| 81 |
while getopts "f:h" opt ; do
|
| 82 |
case "$opt" in
|
| 83 |
h) usage ;;
|
| 84 |
f) MKIMAGE=1; floppydev="$OPTARG";;
|
| 85 |
?) echo "Error parsing arguments"; exit 1;;
|
| 86 |
esac
|
| 87 |
done
|
| 88 |
shift `expr $OPTIND - 1`
|
| 89 |
|
| 90 |
if [ "$UID" -ne 0 ]; then
|
| 91 |
echo "You must be root!"
|
| 92 |
exit 9
|
| 93 |
fi
|
| 94 |
|
| 95 |
# additional kernel parameter
|
| 96 |
params=$*
|
| 97 |
|
| 98 |
. /etc/fai/fai.conf
|
| 99 |
|
| 100 |
determine_kernel_version
|
| 101 |
grep -q ic_bootp $NFSROOT/boot/System.map-$KERNELVERSION && TYPE=BOOTP
|
| 102 |
grep -q ic_dhcp $NFSROOT/boot/System.map-$KERNELVERSION && TYPE=DHCP
|
| 103 |
|
| 104 |
[ "$TYPE" ] || die "Can't determine kernel boot protocol.\nMaybe there's no $NFSROOT/boot/System.map-$KERNELVERSION"
|
| 105 |
|
| 106 |
ndevices=0
|
| 107 |
devices=`egrep -v "lo:|^Inter-|^ face" /proc/net/dev | awk -F: '{print $1}'`
|
| 108 |
for dev in $devices; do
|
| 109 |
ndevices=$(($ndevices+1))
|
| 110 |
done
|
| 111 |
[ $ndevices = 0 ] && die "No network interface found. Can't determine IP address."
|
| 112 |
if [ $ndevices = 1 ]; then
|
| 113 |
SERVERINTERFACE=$dev
|
| 114 |
else
|
| 115 |
while [ -z "$SERVERINTERFACE" ]; do
|
| 116 |
echo "Your machine has multiple network interfaces: $devices"
|
| 117 |
echo -n "Specify which one will be used for FAI (eg. eth1): "
|
| 118 |
read SERVERINTERFACE
|
| 119 |
done
|
| 120 |
fi
|
| 121 |
SERVERIP=`LC_ALL=C ifconfig $SERVERINTERFACE | perl -ne '/inet addr:([0-9\.]+)/ && print $1'`
|
| 122 |
echo "Using interface $SERVERINTERFACE with IP address: $SERVERIP"
|
| 123 |
unset SERVERINTERFACE ndevices devices dev
|
| 124 |
|
| 125 |
if [ $MKIMAGE -eq 1 ]; then
|
| 126 |
dd if=/dev/zero of=$floppydev bs=1024 count=1440
|
| 127 |
mountopts="$mountopts -o loop"
|
| 128 |
mkfsopt=-F
|
| 129 |
fi
|
| 130 |
|
| 131 |
mke2fs $mkfsopt -q -i 8192 -m 0 $floppydev || die "Can't create ext2 file system on $floppydev"
|
| 132 |
mount $mountopts $floppydev /floppy || die "Can't mount floppy $floppydev"
|
| 133 |
cp -ad $NFSROOT/boot /floppy
|
| 134 |
mkdir -p /floppy/etc
|
| 135 |
ln -s boot/vmlinuz-$KERNELVERSION /floppy/vmlinuz
|
| 136 |
# since lilo 21.5, boot.b is a link
|
| 137 |
[ -e /floppy/boot/boot.b ] || ln -fs /floppy/boot/boot-compat.b /floppy/boot/boot.b
|
| 138 |
|
| 139 |
[ $MKIMAGE -eq 1 ] && cat > /floppy/etc/lilo.conf << EOF
|
| 140 |
disk=/dev/loop0
|
| 141 |
bios=0x00
|
| 142 |
cylinders=80
|
| 143 |
heads=2
|
| 144 |
sectors=18
|
| 145 |
EOF
|
| 146 |
|
| 147 |
cat >> /floppy/etc/lilo.conf <<-EOF
|
| 148 |
boot=$floppydev
|
| 149 |
root=$NFSROOT/dev/boot255
|
| 150 |
install=/floppy/boot/boot.b
|
| 151 |
map=/floppy/boot/map
|
| 152 |
append="NFSROOT=$SERVERIP:$NFSROOT $params"
|
| 153 |
delay=10
|
| 154 |
compact
|
| 155 |
image=/floppy/vmlinuz
|
| 156 |
label=FAI-$TYPE
|
| 157 |
read-only
|
| 158 |
EOF
|
| 159 |
|
| 160 |
echo now writing boot data to floppy
|
| 161 |
$NFSROOT/sbin/lilo -C /floppy/etc/lilo.conf
|
| 162 |
cd /
|
| 163 |
umount /floppy
|
| 164 |
|
| 165 |
cat <<EOF
|
| 166 |
FAI boot floppy created.
|
| 167 |
boot protocol : $TYPE
|
| 168 |
nfsroot : $SERVERIP:$NFSROOT
|
| 169 |
parameters : $params
|
| 170 |
The kernel configuration is $NFSROOT/boot/config-$KERNELVERSION-$TYPE.
|
| 171 |
EOF
|