/[fai]/trunk/scripts/make-fai-bootfloppy
ViewVC logotype

Contents of /trunk/scripts/make-fai-bootfloppy

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1674 - (show annotations) (download)
Thu Feb 6 14:59:51 2003 UTC (10 years, 3 months ago) by lange
File size: 8604 byte(s)
add example
1 #! /bin/bash
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-2003 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 2.0.1, 6-feb-2003"
31 set -e
32 timeout=15
33 mkimage=0
34 floppydev=/dev/fd0
35 mountpoint=/floppy
36 mountopts=""
37 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
38 umount_dirs() {
39 cd /
40 umount "$mountpoint" 2>/dev/null || true
41 }
42 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
43 die() {
44
45 echo -e "$@"
46 exit 99
47 }
48 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
49 determine_kernel_version() {
50
51 local num all
52 all=$(ls $NFSROOT/boot/vmlinuz-*)
53 if [ `echo $all | wc -l` = 1 ]; then
54 KERNELVERSION=$(echo "kernel version $all" | sed -e 's#.*/vmlinuz-##')
55 else
56 die "Can't determine kernel version for $all"
57 fi
58 }
59 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
60 usage() {
61
62 cat <<EOF
63 make-fai-bootfloppy, create a boot floppy for FAI. $version
64
65 Copyright (C) 2000-2003 by Thomas Lange
66
67 Usage: make-fai-bootfloppy [parameter]
68
69 -d label use label when selection the default boot kernel (and parameters).
70 d for DHCP
71 b for BOOTP
72 f for the fixed IP address for the server
73 Without this option both (dhcp and booth) are used
74 -h print this message.
75 -f file make a 1440k floppy image
76 -m dir use dir as mountpoint [/floppy]
77 -s host use a static ip for host (try to get from DNS)
78 -v print verbose output (print lilo.conf)
79
80 DESCRIPTION
81 Creates a boot floppy for booting a FAI install client.
82 No arguments are needed but you must be root.
83 All parameters are passed to the kernel via append in lilo.conf.
84
85 EXAMPLE
86 Create a generic boot floppy for James ;-)
87 # make-fai-bootfloppy "FAI_FLAGS=verbose,createvt,sshd BOND=007"
88
89 To make a boot floppy for my old SMC EtherCard Plus Elite 16T, I use
90 # make-fai-bootfloppy "reserve=0x300,32 ether=10,0x300,eth0"
91
92 To make a boot floppy using the DHCP protocol
93 # make-fai-bootfloppy -d d
94
95 EOF
96 exit 0
97 }
98
99 # - - - - - - - - - - - - - - - - - - - - - - - - - -
100 determine_network_parameters() {
101
102 ndevices=0
103 devices=`egrep -v "lo:|^Inter-|^ face" /proc/net/dev | awk -F: '{print $1}'`
104 for dev in $devices; do
105 ndevices=$(($ndevices+1))
106 done
107 [ $ndevices = 0 ] && die "No network interface found. Can't determine IP address."
108 if [ $ndevices = 1 ]; then
109 SERVERINTERFACE=$dev
110 else
111 while [ -z "$SERVERINTERFACE" ]; do
112 echo "Your machine has multiple network interfaces: $devices"
113 echo -n "Specify which one will be used for FAI (e.g. eth1): "
114 read SERVERINTERFACE
115 done
116 fi
117 SERVERIP=`LC_ALL=C ifconfig $SERVERINTERFACE | perl -ne '/inet addr:([0-9\.]+)/ && print $1'`
118 echo "Using interface $SERVERINTERFACE with IP address: $SERVERIP"
119
120 if [ -n "${TARGETHOST}" ] ; then
121 BROADCAST=`LC_ALL=C ifconfig $SERVERINTERFACE | perl -ne '/Bcast:([0-9\.]+)/ && print $1'`
122 NETMASK=`LC_ALL=C ifconfig $SERVERINTERFACE | perl -ne '/Mask:([0-9\.]+)/ && print $1'`
123 GATEWAY=`LC_ALL=C route -n | grep '^0\.0\.0\.0' | awk '{ print $2 }'`
124 TARGETIP=`host -t a ${TARGETHOST} 2> /dev/null | awk '{print $3}'`
125 fixedparams="ip=${TARGETIP}:${SERVERIP}:${GATEWAY}:${NETMASK}:${TARGETHOST}::off"
126 fi
127 }
128 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
129 lilo_floppy() {
130
131 # make a boot floppy using lilo
132
133 echo "Using lilo for the boot floppy."
134 mkdir $mountpoint/boot $mountpoint/etc
135 rmdir $mountpoint/lost+found
136
137 cd $NFSROOT && cp -dp boot/boot-menu.b boot/vmlinuz-$KERNELVERSION $mountpoint/boot
138 ln -s boot/vmlinuz-$KERNELVERSION $mountpoint/vmlinuz
139 ln -fs $mountpoint/boot/boot-menu.b $mountpoint/boot/boot.b
140
141 [ $mkimage -eq 1 ] && cat > $mountpoint/etc/lilo.conf <<-EOF
142 disk=$(mount | grep $mountpoint | sed -e 's/.*loop=\([^)]*\))/\1/')
143 bios=0x00
144 cylinders=80
145 heads=2
146 sectors=18
147 EOF
148
149 cat >> $mountpoint/etc/lilo.conf <<-EOF
150
151 boot=$floppydev
152 install=$mountpoint/boot/boot-menu.b
153 map=$mountpoint/boot/map
154 delay=$timeout
155 compact
156 read-only
157
158 default=$lilodef
159
160 image=$mountpoint/vmlinuz
161 append="ip=both root=/dev/nfs $params"
162 label=FAI-BOTH
163
164 image=$mountpoint/vmlinuz
165 append="ip=bootp root=/dev/nfs $params"
166 label=FAI-BOOTP
167
168 image=$mountpoint/vmlinuz
169 append="ip=dhcp root=/dev/nfs $params"
170 label=FAI-DHCP
171
172 image=$mountpoint/vmlinuz
173 label=FAI-FIXED-IP
174 append="root=$SERVERIP:$NFSROOT ip=both $fixedparams $params"
175 EOF
176 $NFSROOT/sbin/lilo -C $mountpoint/etc/lilo.conf
177 }
178 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
179 grub_floppy() {
180
181 echo "Using grub for the boot floppy."
182 # make a boot floppy using grub
183 kernel=vmlinuz-$KERNELVERSION
184 mkdir -p $mountpoint/boot/grub
185 cp -p /usr/lib/grub/i386-pc/stage? $mountpoint/boot/grub
186 cp $NFSROOT/boot/$kernel $mountpoint
187
188 grubconf="
189 default $grubdef
190 #default saved
191 timeout $timeout
192
193 title FAI-BOTH
194 kernel (fd0)/$kernel root=/dev/nfs ip=both $params
195 savedefault
196
197 title FAI-BOOTP
198 kernel (fd0)/$kernel root=/dev/nfs ip=bootp $params
199 savedefault
200
201 title FAI-DHCP
202 kernel (fd0)/$kernel root=/dev/nfs ip=dhcp $params
203 savedefault
204
205 title FAI-FIXED-IP
206 kernel (fd0)/$kernel root=$SERVERIP:$NFSROOT ip=both $fixedparams $params
207 savedefault
208 "
209 echo "$grubconf" > $mountpoint/boot/grub/menu.lst
210 umount $mountpoint
211 grub --batch --device-map=/dev/null >/dev/null <<EOF
212 device (fd0) $floppydev
213 root (fd0)
214 setup (fd0)
215 quit
216 EOF
217 }
218 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
219 # main part
220
221 while getopts "lgvf:s:m:hd:" opt ; do
222 case "$opt" in
223 l) lilo=1 ;;
224 g) grub=1 ;;
225 h) usage ;;
226 f) mkimage=1; floppydev="$OPTARG" ;;
227 m) mountpoint="$OPTARG" ;;
228 s) TARGETHOST="$OPTARG" ;;
229 d) BTYPE="$OPTARG" ;;
230 v) verbose=1 ;;
231 ?) echo "Error parsing arguments"; exit 1;;
232 esac
233 done
234 shift `expr $OPTIND - 1`
235 case "$BTYPE" in
236 b) lilodef=FAI-BOOTP ; grubdef=1 ;;
237 d) lilodef=FAI-DHCP ; grubdef=2 ;;
238 f) lilodef=FAI-FIXED-IP ; grubdef=3 ;;
239 *) lilodef=FAI-BOTH ; grubdef=0 ;;
240 esac
241
242 [ $lilo ] && [ $grub ] && die "Specify only one of -l or -g"
243 [ $lilo ] || [ $grub ] || grub=1
244 [ `id -u` -eq 0 ] || die "You must be root! Or try $0 -h"
245
246 trap "umount_dirs" EXIT
247 # additional kernel parameter
248 params="$@"
249
250 . /etc/fai/fai.conf
251 determine_kernel_version
252 determine_network_parameters
253
254 if [ $mkimage -eq 1 ]; then
255 [ -e $floppydev ] && die "$floppydev already exists. Please remove it and restart again."
256 dd if=/dev/zero of=$floppydev bs=1024 count=1440
257 mountopts="$mountopts -o loop"
258 mkfsopt=-F
259 fi
260
261 # pay attention: if -i option is too large, then too few inodes
262 # are created on the floppy. Check it with df -i
263 mke2fs $mkfsopt -q -i 40000 -m 0 $floppydev || \
264 die "Can't create ext2 file system on $floppydev"
265 mount $mountopts $floppydev $mountpoint || die "Can't mount floppy $floppydev"
266
267 [ $lilo ] && lilo_floppy
268 [ $grub ] && grub_floppy
269 cat <<-EOF
270 Writing boot data to floppy. The default boot label is: $liloboot
271 The kernel configuration is $NFSROOT/boot/config-$KERNELVERSION.
272 EOF
273
274 [ "$params" ] && echo "Additional kernel parameters: $params"
275
276 [ "$verbose" ] && [ $lilo ] && {
277 echo "The lilo.conf is:"
278 echo
279 cat $mountpoint/etc/lilo.conf
280 }
281 [ "$verbose" ] && [ $grub ] && {
282 echo "The grub menu is:"
283 echo
284 echo "$grubconf"
285 }

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.5