1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
|
#!/bin/bash
usage () {
echo "usage: mk-images <kernelpath> <imagepath> <fullmodpath> <imgpath> <temlpatepath>"
exit 0
}
if [ -z "$1" -o -z "$2" -o -z "$3" -o -z "$4" -o -z "$5" ]; then usage; fi
TOPDIR=$(echo $0 | sed "s,/[^/]*$,,")
if [ $TOPDIR = $0 ]; then
$TOPDIR="."
fi
TOPDIR=$(cd $TOPDIR; pwd)
# Set, verify, and create paths
KERNELPATH=$1
IMAGEPATH=$2
FULLMODPATH=$3
INSTIMGPATH=$4
INSTIMGTEMPLATE=$5
IMGPATH=$(echo $FULLMODPATH | sed 's,/[^/]*$,,')
KERNELROOT=/tmp/updboot.kernel.$$
MODDEPS=$KERNELROOT/moddeps
ARCH=$(uname -m | sed 's/i.86/i386/')
if [ ! -d "$1" ]; then
LATEST=latest --arch $ARCH
else
LATEST=findPackage
fi
rm -rf $IMAGEPATH
rm -rf $FULLMODPATH
rm -rf $KERNELROOT
mkdir -p $IMAGEPATH
mkdir -p $FULLMODPATH
mkdir -p $KERNELROOT
mkdir -p $INSTIMGPATH
# Stuff that we need
TRIMPCITABLE=$IMGPATH/usr/lib/anaconda-runtime/trimpcitable
GETMODDEPS=$IMGPATH/usr/lib/anaconda-runtime/moddeps
MODLIST=$IMGPATH/usr/lib/anaconda-runtime/modlist
MODINFO=$IMGPATH/usr/lib/anaconda-runtime/loader/module-info
FILTERMODDEPS=$IMGPATH/usr/lib/anaconda-runtime/filtermoddeps
LOADERBINDIR=$IMGPATH/usr/lib/anaconda-runtime/loader
BOOTDISKDIR=$IMGPATH/usr/lib/anaconda-runtime/boot
LANGTABLE=$IMGPATH/usr/lib/anaconda/lang-table
SYSLINUX=$IMGPATH/usr/bin/syslinux
PCITABLE=$IMGPATH/usr/share/kudzu/pcitable
CACHE=$KERNELROOT/lib/modules/.cache
MODULESUSED=$KERNELROOT/modules-used
touch $MODULESUSED
dieLater=
for n in $TRIMPCITABLE $PCITABLE $GETMODDEPS $MODINFO $FILTERMODDEPS \
$LANGTABLE $SYSLINUX; do
if [ ! -f $n ]; then
echo "$n doesn't exist"
dieLater=1
fi
done
for n in $BOOTDISKDIR; do
if [ ! -d $n ]; then
echo "$n doesn't exist"
dieLater=1
fi
done
if [ -n "$dieLater" ]; then exit 1; fi
findPackage() {
dir=$1
name=$2
for n in $dir/$name*; do
thisName=$(rpm --qf '%{NAME}' -qp $n)
if [ $thisName = $name ]; then
echo $n
return
fi
done
echo "cannot find package $name in path $dir" >&2
kill -9 $$
}
findmodule () {
if [ ! -f $CACHE ]; then
find $KERNELROOT/lib/modules > $CACHE
fi
grep "/$1\.o" $CACHE
}
rundepmod () {
what=$1
final=$2
exclpattern="tc90x|FPT|BusLogic|Pci2000|Pci2220i"
depmod -e -i -m $KERNELROOT/boot/System.map-$version \
$what > $final.foo 2>&1 |
egrep -v "modprobe: (${exclpattern}) multiply defined"
PARIDE="aten bpck comm dstr epat epia fit2 fit3 friq frpw kbic ktti on20 on26"
cat $final.foo | sed -e 's/\.o//g' \
-e 's/: parport$/: parport_pc/g' \
-e 's/^\(parport_pc: parport\)_pc$/\1/' \
-e "s/^pcd:.*/pcd: $PARIDE/" | $FILTERMODDEPS > $final
rm -f $final.foo
}
getmoddeps () {
what=$1
final=$2
egrep $(echo $what | sed 's/\.o */|^/g;s/\.o$//') $MODDEPS > $final
}
intcopymodules () {
dir=$2
for n in $1; do
m=$(findmodule $n)
if [ -z "$m" ]; then
echo "Module $n not found in kernel rpm"
else
echo $n >> $MODULESUSED
if ! cp $m $dir ; then
echo "Failed to copy $m to $dir (for module $n)"
fi
fi
done
}
resdeps () {
$GETMODDEPS -m $MODDEPS $* 2>&1
if [ $? != "0" ] ; then
kill -9 $$
fi
list=`$GETMODDEPS -m $MODDEPS $*`
items=$(for n in $* $list; do echo $n; done | sort -u)
echo $items
}
expandModuleSet() {
SET=""
for name in $1; do
char=$(echo $name | cut -c1)
if [ $char = '=' ]; then
NAME=$(echo $name | cut -c2-)
SET="$SET $($MODLIST --modinfo-file $MODINFO $NAME)"
elif [ $char = '+' ]; then
NAME=$(echo $name | cut -c2-)
# all of the modules of this type
$MODLIST --modinfo-file $MODINFO $NAME > /tmp/emsAll.$$
# the modules used that are of this type
cat $MODULESUSED /tmp/emsAll.$$ | sort | uniq -d > /tmp/emsUsed.$$
# the modules that are of this type, but not used
SET=$(cat /tmp/emsAll.$$ /tmp/emsUsed.$$ | sort | uniq -u)
rm -f /tmp/emsAll.$$ /tmp/emsUsed.$$
else
SET="$SET $name"
fi
done
echo $SET
}
makemoduleball() {
unset MMB_DD
MMB_MODINFO="module-info"
if [ $1 = "--dd" ]; then
shift
MMB_DD="$1"
shift
MMB_MODINFO="modinfo"
fi
MMB_DIR=$1
MMB_MODULESET=$(resdeps $2)
rm -rf $MMB_DIR/modules $MMB_DIR/modules.cgz $MMB_DIR/modules.dep \
$MMB_DIR/pcitable $MMB_DIR/$MMB_MODINFO
mkdir -p $MMB_DIR/modules
intcopymodules "$MMB_MODULESET" $MMB_DIR/modules
pushd $MMB_DIR/modules > /dev/null
$MODLIST --modinfo-file $MODINFO --ignore-missing --modinfo \
$MMB_MODULESET > ../$MMB_MODINFO
getmoddeps "*.o" ../modules.dep
# create the pcitable
$TRIMPCITABLE *.o < $PCITABLE > ../pcitable
if [ -n "$MMB_DD" ]; then
echo $MMB_DD > $MMB_DIR/rhdd-6.1
fi
mkdir $version
mv *.o $version
find $version -type f | cpio --quiet -H crc -o | gzip -9 > ../modules.cgz
cd ..
rm -rf modules
popd > /dev/null
}
makemainmodules() {
modlist=`expandModuleSet "$1"`
rm -rf $FULLMODPATH
makemoduleball $FULLMODPATH "$modlist"
}
makebootdisk() {
MBD_FILENAME=$IMAGEPATH/$1
LOADERBIN=$2
MODSET=`expandModuleSet "$3"`
MBD_DIR=/tmp/makebootdisk.dir.$$
MBD_FSIMAGE=/tmp/makebootdisk.initrdimage.$$
MBD_MNTPOINT=/tmp/makebootdisk.mount.$$
MBD_TMPIMAGE=/tmp/makebootdisk.image.$$
MBD_BOOTTREE=/tmp/makebootdisk.tree.$$
INITBIN=init
rm -rf $MBD_DIR MBD_FSIMAGE
mkdir -p $MBD_DIR/modules
mkdir -p $MBD_DIR/sbin
mkdir -p $MBD_DIR/dev/pts
mkdir -p $MBD_DIR/etc
mkdir -p $MBD_DIR/proc
mkdir -p $MBD_DIR/tmp
mkdir -p $MBD_DIR/etc/terminfo/l
makemoduleball $MBD_DIR/modules "$MODSET"
cat > $MBD_DIR/etc/passwd << EOF
root::0:0:root:/:/bin/bash
EOF
# FIXME
#cp -a keymaps/keymaps.gz initrd/etc
#cp -a fonts.cgz initrd/etc
install -s -m 755 $LOADERBINDIR/$LOADERBIN $MBD_DIR/sbin/loader
install -s -m 755 $LOADERBINDIR/$INITBIN $MBD_DIR/sbin
install -m 644 $LANGTABLE $MBD_DIR/etc
install -m 644 $LANGTABLE $LOADERBINDIR/loader.tr $MBD_DIR/etc
install -m 644 /usr/share/terminfo/l/linux $MBD_DIR/etc/terminfo/l/linux
for n in insmod rmmod modprobe; do
ln -s loader $MBD_DIR/sbin/$n
done
ln -s /usr/bin/sh $MBD_DIR/sbin/sh
ln -s /sbin/init $MBD_DIR/linuxrc
ln -s /proc/mounts $MBD_DIR/etc/mtab
ln -s sbin $MBD_DIR/bin
# FIXME: keymaps?
# FIXME: fonts?
awk '{ printf("mknod %s/dev/%s %s %s %s\n", $1, $2, $3, $4, $5);
printf("chmod %s %s/dev/%s\n", $6, $1, $2);
printf("chown %s %s/dev/%s\n", $7, $1, $2);
}' <<EOF | sh
$MBD_DIR console c 5 1 600 root:root
$MBD_DIR ttyS0 c 4 64 600 root:root
$MBD_DIR ttyS1 c 4 65 600 root:root
$MBD_DIR ttyS2 c 4 66 600 root:root
$MBD_DIR ttyS3 c 4 67 600 root:root
$MBD_DIR psaux c 10 1 644 root:root
$MBD_DIR null c 1 3 666 root:root
$MBD_DIR zero c 1 5 666 root:root
$MBD_DIR md0 b 9 0 644 root:root
$MBD_DIR mem c 1 1 600 root:root
$MBD_DIR ram b 1 1 640 root:root
$MBD_DIR ptmx c 5 2 666 root:root
$MBD_DIR tty0 c 4 0 600 root:tty
$MBD_DIR tty1 c 4 1 600 root:tty
$MBD_DIR tty2 c 4 2 600 root:tty
$MBD_DIR tty3 c 4 3 600 root:tty
$MBD_DIR tty4 c 4 4 600 root:tty
$MBD_DIR tty5 c 4 5 600 root:tty
$MBD_DIR tty6 c 4 6 600 root:tty
$MBD_DIR tty7 c 4 7 600 root:tty
EOF
cat > $MBD_DIR/.profile <<EOF
PATH=/bin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/mnt/sbin:/mnt/usr/sbin:/mnt/bin:/mnt/usr/bin
export PATH
EOF
if [ $ARCH = "i386" ]; then
INITRDSIZE=2000
FLOPPYSIZE=1440
else
echo "I don't know how big to make the image!" >&2
exit 1
fi
rm -f $MBD_FSIMAGE
dd if=/dev/zero of=$MBD_FSIMAGE bs=1k count=$INITRDSIZE 2> /dev/null
echo y | mke2fs -i 8096 -q $MBD_FSIMAGE $INITRDSIZE > /dev/null 2>/dev/null
rm -rf $MBD_MNTPOINT
mkdir $MBD_MNTPOINT
mount -o loop -t ext2 $MBD_FSIMAGE $MBD_MNTPOINT
(cd $MBD_DIR; find . | cpio --quiet -p $MBD_MNTPOINT)
df $MBD_MNTPOINT | tail +2
umount $MBD_MNTPOINT
mv -f $MBD_FSIMAGE $MBD_FSIMAGE.uncompressed
gzip -9 < $MBD_FSIMAGE.uncompressed > $MBD_FSIMAGE
rm -rf $MBD_FSIMAGE.uncompressed $MBD_DIR
rm -rf $MBD_TMPIMAGE $MBD_BOOTTREE
dd if=/dev/zero bs=1k count=$FLOPPYSIZE of=/$MBD_TMPIMAGE
# Create the bootdisk image as $MBD_TMPIMAGE, mount it, copy
# $MBD_FSIMAGE (the initrd) to it, add a kernel, umount it. It should be
# left as $MBD_TMPIMAGE, with no side affects.
if [ $ARCH = "i386" ]; then
gunzip < $BOOTDISKDIR/template.img.gz |
dd of=$MBD_TMPIMAGE conv=notrunc > /dev/null 2> /dev/null
$SYSLINUX $MBD_TMPIMAGE
mkdir -p $MBD_BOOTTREE
mount -o loop -t msdos $MBD_TMPIMAGE $MBD_BOOTTREE
(cd $BOOTDISKDIR; find . ! -name "*.msg" -maxdepth 1 ! -type d | cpio --quiet -p $MBD_BOOTTREE)
cp $MBD_FSIMAGE $MBD_BOOTTREE/initrd.img
cp $KERNELROOT/boot/vmlinuz-* $MBD_BOOTTREE/vmlinuz
cp $BOOTDISKDIR/*.msg $MBD_BOOTTREE
df $MBD_BOOTTREE | tail +2
umount $MBD_BOOTTREE
else
echo "I don't know how big to make the image!" >&2
exit 1
fi
rmdir $MBD_BOOTTREE
rm -f $MBD_FILENAME
mv -f $MBD_TMPIMAGE $MBD_FILENAME
rm -rf $MBD_TMPIMAGE $MBD_FSIMAGE
}
makeinstimage () {
imagename=$1
modlist=$(expandModuleSet "$2")
tmpimage=/tmp/instimage.img
mntpoint=/tmp/instimage.mnt
tmpdir=/tmp/instimage.dir
rm -rf $tmpimage $mntpoint $tmpdir
mkdir -p $mntpoint $tmpdir
mkdir -p $tmpdir
(cd $INSTIMGTEMPLATE; find . | cpio --quiet -p $tmpdir)
makemoduleball $tmpdir/modules "$modlist"
if [ $ARCH = "i386" ]; then
SIZE=4096
else
echo "I don't know how big to make the image!" >&2
exit 1
fi
dd if=/dev/zero of=$tmpimage bs=1k count=$SIZE 2>/dev/null
echo y | mke2fs -i 4096 $tmpimage > /dev/null 2>/dev/null
mount -o loop $tmpimage $mntpoint
(cd $tmpdir; find . | cpio --quiet -p $mntpoint)
umount $mntpoint
rmdir $mntpoint
rm -rf $tmpdir
gzip -9 < $tmpimage > $INSTIMGPATH/${imagename}.img
rm $tmpimage
}
makedriverdisk () {
modlabel=$1
diskname=$2
modlist=$(expandModuleSet "$3")
diskpath=/tmp/makedriverdisk.$$
rm -rf $diskpath
mkdir -p $diskpath
makemoduleball --dd "$modlabel" $diskpath "$modlist"
size=$(expr 60 + $(du -sk $diskpath | awk '{print $1}'))
if [ $size -lt 57 ]; then
size=64
fi
dd if=/dev/zero of=/tmp/$diskname.img bs=1k count=$size 2> /dev/null
echo y | mke2fs -i 4096 /tmp/$diskname.img > /dev/null 2>/dev/null
mkdir -p /tmp/mkdd.$$
mount -t ext2 -o loop /tmp/$diskname.img /tmp/mkdd.$$
rmdir /tmp/mkdd.$$/lost+found
(cd $diskpath; tar cSpf - .) | (cd /tmp/mkdd.$$; tar xSpf -)
DIE=""
if [ $(du -s $diskpath | cut -f1) != $(du -s /tmp/mkdd.$$ | cut -f1) ]; then
echo copy to disk image failed
ls -l /tmp/mkdd.$$
echo "disk size: $size"
ls -l $diskpath
DIE=1
fi
umount /tmp/mkdd.$$
rm -rf /tmp/mkdd.$$
if [ -n "$DIE" ]; then
kill -9 $$
fi
cp /tmp/${diskname}.img $IMAGEPATH/${diskname}.img
rm /tmp/${diskname}.img
rm -rf $diskpath
}
# Find the kernel, unpack it, and verify it
kpackage=$($LATEST $KERNELPATH kernel-BOOT)
ppackage=$($LATEST $KERNELPATH kernel-pcmcia-cs)
version=$(rpm --qf '%{VERSION}-%{RELEASE}' -qp $kpackage)BOOT
rpm2cpio $kpackage | (cd $KERNELROOT; cpio --quiet -iumd)
rpm2cpio $ppackage | (cd $KERNELROOT; cpio --quiet -iumd etc/pcmcia/*)
if [ ! -d "$KERNELROOT/lib/modules/$version/scsi" ]; then
echo "$1 is not a valid modules directory" 2>&1
usage
fi
if [ ! -f "$KERNELROOT/boot/vmlinuz-$version" ]; then
echo "$KERNELROOT/boot/vmlinuz-$version does not exist"
usage
fi
rundepmod "$KERNELROOT/lib/modules/$version/*/*.o" $MODDEPS
rm -f $MODDEPS.foo
. $TOPDIR/mk-images.${ARCH}
rm -rf $KERNELROOT
|