4
#*********************************************************************
6
# fai-cd -- make a fai CD, a bootable CD that performs the FAI
8
# This script is part of FAI (Fully Automatic Installation)
9
# (c) 2004-2005 by Thomas Lange, lange@informatik.uni-koeln.de
10
# Universitaet zu Koeln
12
# based on a script called make-fai-bootcd by Niall Young <niall@holbytla.org>
14
#*********************************************************************
15
# This program is free software; you can redistribute it and/or modify
16
# it under the terms of the GNU General Public License as published by
17
# the Free Software Foundation; either version 2 of the License, or
18
# (at your option) any later version.
20
# This program is distributed in the hope that it will be useful, but
21
# WITHOUT ANY WARRANTY; without even the implied warranty of
22
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23
# General Public License for more details.
25
# A copy of the GNU General Public License is available as
26
# `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution
27
# or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html. You
28
# can also obtain it by writing to the Free Software Foundation, Inc.,
29
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30
#*********************************************************************
33
version="fai-cd 1.2.1"
35
isoversion="$version -- build $(date '+%c')"
36
vname="Fully Automatic Installation CD"
37
aname="Fully Automatic Installation by Thomas Lange, $isoversion"
39
grub_config=/etc/fai/menu.lst
42
bimagesize=2.88 # mkbimage can create greater images, but mkisofs only accepts up to 2.88
43
hidedirs="/usr/share/locale /usr/share/doc /var/lib/apt /var/cache/apt /usr/share/man /var/lib/dpkg/info /media/mirror/aptcache /media/mirror/.apt-move"
45
# we need FAI_CONFIGDIR, NFSROOT
48
trap "unhide_dirs;umount_dirs; mhide -u xfs reiserfs ext3" EXIT ERR
50
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
54
$version. Copyright (C) 2004-2005 Thomas Lange
55
Report bugs to <fai@informatik.uni-koeln.de>.
57
Usage: fai-cd [OPTIONS] -m MIRRORDIR ISONAME
58
Create a fai CD, a bootable CD that performs the FAI.
59
Read the man pages pages fai-cd(8).
63
# - - - - - - - - - - - - - - - - - - - - - - - - - -
66
local e=$1 # first parameter is the exit code
69
echo "$@" # print error message
72
# - - - - - - - - - - - - - - - - - - - - - - - - - -
83
# - - - - - - - - - - - - - - - - - - - - - - - - - -
86
# hide or unhide a kernel module, so mkinitrd-cd can't see it
87
# therefore we rename the modules to XXX-<modulename.o>
88
# this works for 2.4 and 2.6 kernel (.o and .ko modules)
90
local dir module newname nam
91
local kdir=$NFSROOT/lib/modules/$kernelversion
102
found=$(find $kdir -name ${nam}.o -o -name ${nam}.ko)
103
# echo "FOUND: $found"
104
if [ -z "$found" ]; then
105
# echo "$module not found."
108
[ -f $found ] || return
110
newname=$(basename $found)
111
newname=${newname/XXX-/} # substitute XXX- with nothing
112
dir=$(dirname $found)
116
-h) mv $found $dir/XXX-$newname ;;
117
-u) mv $found $dir/$newname ;;
121
# - - - - - - - - - - - - - - - - - - - - - - - - - -
122
create_initrd_image() {
124
local size=min # full is often bigger than 2.88mb
125
local kdir=$NFSROOT/lib/modules/$kernelversion
127
echo "Creating initrd image with kernel $kernelversion"
129
sed "s/_VERSION_/$isoversion/" < /etc/mkinitrd-cd/id.txt > $NFSROOT/id.txt
131
# mkbimage complains if the image will be too large. So do not include some modules
132
# It would be nice if mkinitrd-cd had a config file!
134
mhide -h xfs reiserfs ext3
136
mkinitrd-cd $kdir $tmp/initrd.img $size "$isoversion"
137
mhide -u xfs reiserfs ext3
139
# - - - - - - - - - - - - - - - - - - - - - - - - - -
140
create_grub_image() {
142
echo -n "Creating grub boot image ..."
144
mkdir -p $tmp/boot/grub
145
> $tmp/boot/RUNNING_FROM_FAICD
146
cp /lib/grub/i386-pc/stage{1,2} $tmp/boot/grub
147
cp $grub_config $tmp/boot/grub/menu.lst
148
# insert date into grub menu
149
perl -pi -e "s/_VERSIONSTRING_/ $isoversion /" $tmp/boot/grub/menu.lst
150
cp $NFSROOT/boot/vmlinuz-$kernelversion $tmp/boot
151
ln -s boot/vmlinuz-$kernelversion $tmp/vmlinuz
152
tar -C $tmp -cf $tmp/make-fai-cd.tar boot vmlinuz initrd.img
153
mkbimage -d $tmp -f $tmp/make-fai-cd.tar -t $bimagesize >/dev/null 2>&1
154
# mkbimage creates the file $tmp/$bimagesize.image
155
rm $tmp/initrd.img $tmp/make-fai-cd.tar
156
mv $tmp/$bimagesize.image $tmp/boot
159
# - - - - - - - - - - - - - - - - - - - - - - - - - -
160
customize_nfsroot() {
162
# hide some dirs to save space and make the CD image smaller
166
for d in $hidedirs; do
167
if [ -d $NFSROOT/$d ]; then
168
[ "$debug" ] && echo "hiding $d"
169
mount --bind $tmp/empty $NFSROOT/$d
173
# - - - - - - - - - - - - - - - - - - - - - - - - - -
177
for d in $hidedirs; do
178
if [ -d $NFSROOT/$d ]; then
179
[ "$debug" ] && echo "disclosing $d"
180
umount $NFSROOT/$d 2>/dev/null
185
# - - - - - - - - - - - - - - - - - - - - - - - - - -
190
local dirs="boot fai media/mirror etc/apt/sources.list"
192
umount $NFSROOT/$d 2>/dev/null
196
# - - - - - - - - - - - - - - - - - - - - - - - - - -
199
# Create the El Torito bootable iso9660 cdrom image
201
echo "Mounting all needed parts"
203
mkdir -p $NFSROOT/media/mirror
204
mount --bind $tmp/boot $NFSROOT/boot
205
mount --bind $FAI_CONFIGDIR $NFSROOT/fai && echo "Config space $FAI_CONFIGDIR mounted"
206
mount --bind $mirrordir $NFSROOT/media/mirror && echo "Mirror $mirrordir mounted"
207
# TODO: customize /etc/apt, copy apt preferences etc.
209
# this will be the sources.list for the CD
212
# mirror location for fai CD, file generated by fai-cd
214
deb file:/media/mirror testing main contrib non-free
215
deb file:/fai/files packages/
217
mount --bind $tmp1 $NFSROOT/etc/apt/sources.list
219
echo "Writing FAI CD-ROM image to $isoname. This may need some time."
220
mkisofs -V "$vname" -A "$aname" -log-file /dev/null -quiet -RU -b boot/$bimagesize.image -c boot.catalog -o $isoname $NFSROOT
221
echo -n "ISO image size and filename: "; du -h $isoname
222
rm $tmp/boot/$bimagesize.image $tmp1
226
# - - - - - - - - - - - - - - - - - - - - - - - - - -
229
cdrecord -v -eject $isoname
231
# - - - - - - - - - - - - - - - - - - - - - - - - - -
234
# Parse commandline options
235
while getopts "hg:bm:" opt ; do
238
g) grub_config="$OPTARG" ;;
239
m) mirrordir="$OPTARG" ;;
244
shift $(($OPTIND - 1))
247
[ "$#" -eq 0 ] && die 2 "Please specify the output file for the ISO image."
248
[ -z "$mirrordir" ] && die 4 "Please specify the directory of your mirror using -m"
249
[ -d "$mirrordir" ] || die 5 "$mirrordir is not a directory"
250
[ -f "$isoname" ] && die 3 "Outputfile $isoname already exists. Please remove it."
251
[ -f "$grub_config" ] || die 6 "Grub menu file $grub_config not found."
252
[ `id -u` -ne 0 ] && die 9 "Run this program as root."
254
[ -x "$(which mkinitrd-cd)" ] || die 4 "mkinitrd-cd not found. Please install package."
255
tmp=$(mktemp -t -d fai-cd.XXXXXX)
256
kernelversion=$(ls -tr $NFSROOT/boot/vmlinu?-* | tail -1 | sed -e 's#.*/vmlinuz-##')
262
[ "$burn" -eq 1 ] && burniso