Subversion Repositories livecd

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
18 beyerle@PS 1
#!/bin/bash --norc
2
 
3
#
4
# livecd-mkinitrd:
5
#  mkinitrd used by livecd-install script
6
#  - based on mkinitrd from RHEL4
7
#  - TMPDIR=/tmp
8
#  - comment out test of TMPDIR
9
#
10
# Urs Beyerle, PSI
11
#
12
 
13
# mkinitrd
14
#
15
# Copyright 2005 Red Hat, Inc.
16
#
17
# Written by Erik Troan <ewt@redhat.com>
18
#
19
# Contributors:
20
#	Elliot Lee <sopwith@cuc.edu>
21
#	Miguel de Icaza <miguel@nuclecu.unam.mx>
22
#	Christian 'Dr. Disk' Hechelmann <drdisk@ds9.au.s.shuttle.de>
23
#	Michael K. Johnson <johnsonm@redhat.com>
24
#	Pierre Habraken <Pierre.Habraken@ujf-grenoble.fr>
25
#	Jakub Jelinek <jakub@redhat.com>
26
#	Carlo Arenas Belon (carenas@chasqui.lared.net.pe>
27
#	Keith Owens <kaos@ocs.com.au>
28
#	Bernhard Rosenkraenzer <bero@redhat.com>
29
#	Matt Wilson <msw@redhat.com>
30
#       Trond Eivind Glomsrød <teg@redhat.com>
31
#       Jeremy Katz <katzj@redhat.com>
32
#       Preston Brown <pbrown@redhat.com>
33
#	Bill Nottingham <notting@redhat.com>
34
#       Guillaume Cottenceau <gc@mandrakesoft.com>
35
#	Peter Jones <pjones@redhat.com>
36
 
37
umask 0022
38
 
39
PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH
40
export PATH
41
 
42
VERSION=4.2.15
43
 
44
compress=1
45
allowmissing=""
46
target=""
47
kernel=""
48
force=""
49
verbose=""
50
MODULES=""
51
img_vers=""
52
builtins=""
53
pivot=1
54
initramfs=""
55
modulefile=/etc/modules.conf
56
rc=0
57
 
58
IMAGESIZE=8000
59
PRESCSIMODS="scsi_mod sd_mod unknown"
60
fstab="/etc/fstab"
61
 
62
if [ -f /etc/udev/udev.conf ]; then
63
    USE_UDEV="yes"
64
    UDEV_TMPFS="yes"
65
    UDEV_KEEP_DEV="yes"
66
    . /etc/udev/udev.conf
67
    [ -x /sbin/udev.static ] || USE_UDEV=
68
fi
69
 
70
usage () {
71
    echo "usage: `basename $0` [--version] [-v] [-f] [--preload <module>]" >&2
72
    echo "       [--omit-scsi-modules] [--omit-raid-modules] [--omit-lvm-modules]" >&2
73
    echo "       [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]" >&2
74
    echo "       [--builtin=<module>] [--nopivot] <initrd-image> <kernel-version>" >&2
75
    echo "" >&2
76
    echo "       (ex: `basename $0` /boot/initrd-2.2.5-15.img 2.2.5-15)" >&2
77
    exit 1
78
}
79
 
80
moduledep() {
81
    if [ ! -f "/lib/modules/$kernel/modules.dep" ]; then
82
	echo "No dep file found for kernel $kernel" >&2
83
	exit 1
84
    fi
85
 
86
    [ -n "$verbose" ] && echo -n "Looking for deps of module $1"
87
    deps=$(awk 'BEGIN { searched=ARGV[2]; ARGV[2]=""; rc=1 } \
88
                function modname(filename) { match(filename, /\/([^\/]+)\.k?o:?$/, ret); return ret[1] } \
89
                function show() { if (orig == searched) { print dep; orig=""; rc=0; exit } } \
90
                /^\/lib/ { show(); \
91
                           orig=modname($1); dep=""; \
92
                           if ($2) { for (i = 2; i <= NF; i++) { dep=sprintf("%s %s", dep, modname($i)); } } } \
93
                /^	/ { dep=sprintf("%s %s", dep, modname($1));  } \
94
                END      { show(); exit(rc) }' /lib/modules/$kernel/modules.dep $1)
95
    [ -n "$verbose" ] && echo -e "\t$deps"
96
}
97
 
98
findmodule() {
99
    skiperrors=""
100
 
101
    if [ $1 == "--skiperrors" ]; then
102
	skiperrors=--skiperrors
103
	shift
104
    fi
105
 
106
    local modName=$1
107
 
108
    if [ "$modName" = "off" -o "$modName" = "null" ]; then
109
	return
110
    fi
111
 
112
    if [ $(echo $modName | cut -b1) = "-" ]; then
113
	skiperrors=--skiperrors
114
	modName=$(echo $modName | cut -b2-)
115
    fi
116
 
117
    if echo $builtins | egrep -q '(^| )'$modName'( |$)' ; then
118
	[ -n "$verbose" ] && echo "module $modName assumed to be built in"
119
	set +x
120
	return
121
    fi
122
 
123
    # special cases
124
    if [ "$modName" = "i2o_block" ]; then
125
	findmodule i2o_core
126
	findmodule -i2o_pci
127
	modName="i2o_block"
128
    elif [ "$modName" = "ppa" ]; then
129
	findmodule parport
130
	findmodule parport_pc
131
	modName="ppa"
132
    elif [ "$modName" = "sbp2" ]; then
133
	findmodule ieee1394
134
	findmodule ohci1394
135
	modName="sbp2"
136
    else
137
	moduledep $modName
138
	for i in $deps; do
139
	    findmodule $i
140
	done
141
    fi
142
 
143
    for modExt in o.gz o ko ; do
144
	if [ -d /lib/modules/$kernel/updates ]; then
145
	    fmPath=`(cd /lib/modules/$kernel/updates; echo find . -name $modName.$modExt -type f | /sbin/nash --quiet) | /bin/awk {'print $1; exit;'}`
146
	fi
147
 
148
	if [ -f /lib/modules/$kernel/updates/$fmPath ]; then
149
	    fmPath=updates/$fmPath
150
	    break
151
	fi
152
 
153
	fmPath=`(cd /lib/modules/$kernel; echo find . -name $modName.$modExt -type f | /sbin/nash --quiet) | /bin/awk {'print $1; exit;'}`
154
	if [ -f /lib/modules/$kernel/$fmPath ]; then
155
	    break
156
	fi
157
    done
158
 
159
    if [ ! -f /lib/modules/$kernel/$fmPath ]; then
160
	if [ -n "$skiperrors" ]; then
161
	    return
162
	fi
163
 
164
        # ignore the absence of the scsi modules
165
	for n in $PRESCSIMODS; do
166
	    if [ "$n" = "$modName" ]; then
167
		return;
168
	    fi
169
	done;
170
 
171
	if [ -n "$allowmissing" ]; then
172
	    echo "WARNING: No module $modName found for kernel $kernel, continuing anyway" >&2
173
	    return
174
	fi
175
 
176
	echo "No module $modName found for kernel $kernel, aborting." >&2
177
	exit 1
178
    fi
179
 
180
    # only need to add each module once
181
    if ! echo $MODULES | grep -q "$fmPath" 2>/dev/null ; then
182
	MODULES="$MODULES $fmPath"
183
    fi
184
}
185
 
186
inst() {
187
    if [ "$#" != "2" ];then
188
        echo "usage: inst <file> <destination>"
189
        return
190
    fi 
191
    [ -n "$verbose" ] && echo "$1 -> $2"
192
    cp $1 $2
193
}
194
 
195
while [ $# -gt 0 ]; do
196
    case $1 in
197
	--fstab*)
198
	    if echo $1 | grep -q '=' ; then
199
	    	fstab=`echo $1 | sed 's/^--fstab=//'`
200
	    else
201
		fstab=$2
202
		shift
203
	    fi		    
204
	    ;;
205
 
206
	--with-usb)
207
	    withusb=yes
208
	    ;;
209
 
210
	--with*)
211
	    if echo $1 | grep -q '=' ; then
212
	    	modname=`echo $1 | sed 's/^--with=//'`
213
	    else
214
		modname=$2
215
		shift
216
	    fi		    
217
 
218
	    basicmodules="$basicmodules $modname"
219
	    ;;
220
 
221
	--builtin*)
222
	    if echo $1 | grep -q '=' ; then
223
	    	modname=`echo $1 | sed 's/^--builtin=//'`
224
	    else
225
		modname=$2
226
		shift
227
	    fi		    
228
	    builtins="$builtins $modname"
229
	    ;;
230
 
231
	--version)
232
	    echo "mkinitrd: version $VERSION"
233
	    exit 0
234
	    ;;
235
 
236
	-v)
237
	    verbose=-v
238
	    ;;
239
 
240
	--nocompress)
241
	    compress=""
242
	    ;;
243
 
244
	--nopivot)
245
	    pivot=""
246
	    ;;
247
 
248
	--ifneeded)
249
	    # legacy
250
	    ;;
251
 
252
	-f)
253
	    force=1
254
	    ;;
255
	--preload*)
256
	    if echo $1 | grep -q '=' ; then
257
	    	modname=`echo $1 | sed 's/^--preload=//'`
258
	    else
259
		modname=$2
260
		shift
261
	    fi		    
262
	    PREMODS="$PREMODS $modname"
263
	    ;;
264
	--omit-scsi-modules)
265
	    PRESCSIMODS=""
266
	    noscsi=1;
267
	    ;;
268
	--omit-raid-modules)
269
	    noraid=1;
270
	    ;;
271
	--omit-lvm-modules)
272
	    nolvm=1
273
	    ;;
274
	--image-version)
275
	    img_vers=yes
276
	    ;;
277
	--noudev)
278
	    USE_UDEV=
279
	    ;;
280
	--allow-missing)
281
	    allowmissing=yes
282
	    ;;
283
	*)
284
	    if [ -z "$target" ]; then
285
		target=$1
286
	    elif [ -z "$kernel" ]; then
287
		kernel=$1
288
	    else
289
		usage
290
	    fi
291
	    ;;
292
    esac
293
 
294
    shift
295
done
296
 
297
if [ -z "$target" -o -z "$kernel" ]; then
298
    usage
299
fi
300
 
301
if [ -n "$img_vers" ]; then
302
    target="$target-$kernel"
303
fi
304
 
305
if [ -z "$force" -a -f $target ]; then
306
    echo "$target already exists." >&2
307
    exit 1
308
fi
309
 
310
if [ ! -d /lib/modules/$kernel ]; then
311
    echo "/lib/modules/$kernel is not a directory." >&2
312
    exit 1
313
fi
314
 
315
if [ $UID != 0 ]; then
316
    echo "mkinitrd must be run as root"
317
    exit 1
318
fi
319
 
320
kernelmajor=`echo $kernel | cut -d . -f 1,2`
321
 
322
if [ "$kernelmajor" == "2.4" ]; then
323
    if [ -n "$verbose" ]; then echo "Creating old-style initrd"; fi
324
    USE_UDEV=
325
else
326
    if [ -n "$verbose" ]; then echo "Creating initramfs"; fi
327
    modulefile=/etc/modprobe.conf
328
    initramfs=1
329
    pivot=""
330
fi
331
 
332
# if we're not using udev, don't set any of the other bits
333
[ -z "$USE_UDEV" ] && UDEV_TMPFS= && UDEV_KEEP_DEV=
334
 
335
# find a temporary directory which doesn't use tmpfs
336
# changed by Urs Beyerle, PSI
337
TMPDIR="/tmp"
338
# for t in /tmp /var/tmp /root ${PWD}; do
339
#    if [ ! -d $t ]; then continue; fi
340
#    if ! echo access -w $t | /sbin/nash --quiet; then continue; fi
341
#
342
#    fs=$(df -T $t 2>/dev/null | awk '{line=$1;} END {printf $2;}')
343
#    if [ "$fs" != "tmpfs" ]; then 
344
#	TMPDIR=$t
345
#	break
346
#    fi
347
# done
348
 
349
if [ -z "$TMPDIR" ]; then
350
    echo "no temporary directory could be found" >&2
351
    exit 1
352
fi
353
 
354
if [ $TMPDIR = "/root" -o $TMPDIR = "${PWD}" ]; then 
355
    echo "WARNING: using $TMPDIR for temporary files" >&2
356
fi
357
 
358
for n in $PREMODS; do
359
	findmodule $n
360
done
361
 
362
needusb=""
363
if [ -n "$withusb" ]; then
364
    # If / or /boot is on a USB device include the driver. With root by
365
    # label we could still get some odd behaviors
366
    for fs in / /boot ; do
367
	esc=$(echo $fs | sed 's,/,\\/,g')
368
	dev=$(mount | awk "/ on ${esc} / { print \$1 }" | sed 's/[0-9]*$//' | cut -d/ -f3)
369
	if [ "$(echo $dev | cut -c1-2)" = sd ]; then
370
          if [ `which kudzu 2>/dev/null` ]; then
371
	    host=$(kudzu --probe -b scsi |
372
	      gawk '/^device: '${dev}'/,/^host:/ { if (/^host/) { print $2; exit; } }')
373
	    if [ -d /proc/scsi/usb-storage-${host} -o -f /proc/scsi/usb-storage/${host} ]; then
374
		needusb=1
375
	    fi
376
          fi
377
	fi
378
    done
379
fi
380
 
381
if [ -n "$needusb" ]; then
382
    drivers=$(awk '/^alias[[:space:]]+usb-controller[0-9]* / { print $3}' < $modulefile)
383
    if [ -n "$drivers" ]; then
384
	for driver in $drivers; do
385
	    findmodule $driver
386
	done
387
	findmodule scsi_mod
388
	findmodule sd_mod
389
	findmodule usb-storage
390
    fi
391
fi
392
 
393
if [ -z "$noscsi" ]; then
394
    if [ ! -f $modulefile ]; then
395
        modulefile=/etc/conf.modules
396
    fi
397
 
398
    if [ -f $modulefile ]; then
399
	scsimodules=`grep "alias[[:space:]]\+scsi_hostadapter" $modulefile | grep -v '^[ 	]*#' | LC_ALL=C sort -u | awk '{ print $3 }'`
400
 
401
	if [ -n "$scsimodules" ]; then
402
	    for n in $PRESCSIMODS; do
403
		findmodule $n
404
	    done
405
 
406
	    for n in $scsimodules; do
407
    # for now allow scsi modules to come from anywhere.  There are some
408
    # RAID controllers with drivers in block/
409
		findmodule $n
410
	    done
411
	fi
412
    fi
413
fi
414
 
415
# If we have ide devices and module ide, do the right thing
416
ide=/proc/ide/ide*
417
if [ -n "$ide" ]; then
418
    findmodule -ide-disk
419
fi
420
 
421
# If we use LVM, include lvm-mod
422
if [ -z "$nolvm" ]; then
423
    if [ -f /proc/lvm/global  ]; then
424
        if  grep -q '^VG:' /proc/lvm/global ; then
425
	    if [ "$kernelmajor" == "2.4" ]; then
426
		findmodule -lvm-mod
427
	    else
428
		findmodule -dm-mod
429
	    fi
430
        fi
431
    fi
432
 
433
    if [ -x /sbin/dmsetup -a -e /dev/mapper/control ]; then
434
	dmout=$(/sbin/dmsetup ls 2>/dev/null)
435
	if [ "$dmout" != "No devices found" -a "$dmout" != "" ]; then
436
	    findmodule -dm-mod
437
	fi
438
    fi
439
fi
440
 
441
# If we have dasd devices, include the necessary modules (S/390)
442
if [ -d /proc/dasd ]; then
443
    findmodule -dasd_mod
444
    findmodule -dasd_eckd_mod
445
    findmodule -dasd_fba_mod
446
fi
447
 
448
if [ -z "$noraid" -a -f /proc/mdstat ]; then
449
    # load appropriate raid devices if necessary -- we'll load whatever
450
    # /proc/mdstat suggests
451
 
452
    # note that the awk below contains a space and a tab
453
    for level in $(awk '/^md[0-9][0-9]*[ 	]*:/ { print $4 }' \
454
		    /proc/mdstat | sort -u); do
455
	case $level in
456
	linear)
457
	    findmodule linear
458
	    startraid=1
459
	    ;;
460
	multipath)
461
	    findmodule multipath
462
	    startraid=1
463
	    ;;
464
	raid[01456])
465
	    findmodule $level
466
	    startraid=1
467
	    ;;
468
	*)
469
	    echo "raid level $level (in /proc/mdstat) not recognized" >&2
470
	    ;;
471
	esac
472
    done
473
 
474
    if [ -n "$startraid" ]; then
475
	raiddevices=$(awk '/^md[0-9][0-9]*[        ]*:/ { print $1 }' \
476
			    /proc/mdstat | sort)
477
    fi
478
fi
479
 
480
# check to see if we need to set up a loopback filesystem
481
rootdev=$(awk '/^[ \t]*[^#]/ { if ($2 == "/") { print $1; }}' $fstab)
482
if echo $rootdev | cut -d/ -f3 | grep -q loop ; then
483
    key="^# $(echo $rootdev | cut -d/ -f3 | tr '[a-z]' '[A-Z]'):"
484
    if ! grep "$key" $fstab >> /dev/null; then
485
	echo "The root filesystem is on a $rootdev, but there is no magic entry in $fstab" >&2
486
	echo "for this device. Consult the mkinitrd man page for more information" >&2
487
	exit 1
488
    fi
489
 
490
    line=$(grep "$key" $fstab)
491
    loopDev=$(echo $line | awk '{print $3}')
492
    loopFs=$(echo $line | awk '{print $4}')
493
    loopFile=$(echo $line | awk '{print $5}')
494
 
495
    basicmodules="$basicmodules -loop"
496
    if [ "$loopFs" = "vfat" -o "$loopFs" = "msdos" ]; then
497
	basicmodules="$basicmodules -fat"
498
    fi
499
    basicmodules="$basicmodules -${loopFs}"
500
# check if the root fs is on a logical volume
501
elif ! echo $rootdev | cut -c1-6 |grep -q "LABEL=" ; then
502
    if echo $rootdev | grep -q /dev/mapper 2>/dev/null; then
503
        root_vg=$(echo $rootdev | cut -d/ -f4 | cut -d- -f1)
504
    else
505
        root_vg=$(echo $rootdev | cut -d/ -f3)
506
    fi
507
    rootdev=$(echo "readlink $rootdev" | /sbin/nash --quiet)
508
    major=`ls -l $rootdev | sed -e "s/.* \\([0-9]\+\\), *[0-9]\+.*/\\1/"`
509
    [ "$major" != "58" ] || root_lvm=1
510
    if echo $rootdev |grep -q /dev/mapper 2>/dev/null ; then root_lvm=1 ; fi
511
fi
512
 
513
rootfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $3; }}' $fstab)
514
rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' $fstab \
515
    | sed -e 's/\(^rw,\|rw,$\)//' -e 's/,rw,/,/' -e 's/^rw$/ro/')
516
 
517
# in case the root filesystem is modular
518
findmodule -${rootfs}
519
 
520
if [ -n "$root_lvm" ]; then
521
    if [ "$kernelmajor" == "2.4" ]; then    
522
	findmodule -lvm-mod
523
    else
524
	findmodule -dm-mod
525
	# DM requires all of these to be there in case someone used the
526
	# feature.  broken.  (#132001)
527
	findmodule -dm-mirror
528
	findmodule -dm-zero
529
	findmodule -dm-snapshot
530
    fi
531
fi
532
 
533
for n in $basicmodules; do 
534
    findmodule $n
535
done
536
 
537
if [ -n "$verbose" ]; then
538
    echo "Using modules: $MODULES"
539
fi
540
 
541
 
542
MNTIMAGE=`mktemp -d ${TMPDIR}/initrd.XXXXXX`
543
IMAGE=`mktemp ${TMPDIR}/initrd.img.XXXXXX`
544
if [ -z "$initramfs" ]; then
545
    MNTPOINT=`mktemp -d ${TMPDIR}/initrd.mnt.XXXXXX`
546
    RCFILE=$MNTIMAGE/linuxrc
547
else
548
    RCFILE=$MNTIMAGE/init
549
fi
550
 
551
if [ -z "$MNTIMAGE" -o -z "$IMAGE" ]; then
552
    echo "Error creating temporaries.  Try again" >&2
553
    exit 1
554
fi
555
 
556
if [ -z "$initramfs" ]; then
557
  dd if=/dev/zero of=$IMAGE bs=1k count=$IMAGESIZE 2> /dev/null || exit 1
558
 
559
  LODEV=$(echo findlodev | /sbin/nash --quiet)
560
 
561
  if [ -z "$LODEV" ]; then
562
    rm -rf $MNTIMAGE $MNTPOINT $IMAGE
563
    echo "All of your loopback devices are in use." >&2
564
    exit 1
565
  fi
566
 
567
  losetup ${LODEV} $IMAGE || exit 1
568
 
569
  # We have to "echo y |" so that it doesn't complain about $IMAGE not
570
  # being a block device
571
  echo y | mke2fs $LODEV $IMAGESIZE >/dev/null 2>/dev/null
572
  tune2fs -i0 $LODEV >/dev/null
573
 
574
  if [ -n "$verbose" ]; then
575
      echo "Using loopback device $LODEV"
576
  fi
577
 
578
  mkdir -p $MNTPOINT
579
  mount -t ext2 $LODEV $MNTPOINT || {
580
	echo "Can't get a loopback device"
581
	exit 1
582
  }
583
 
584
  # We don't need this directory, so let's save space
585
  rmdir $MNTPOINT/lost+found >/dev/null 2>&1
586
fi
587
 
588
mkdir -p $MNTIMAGE
589
mkdir -p $MNTIMAGE/lib
590
mkdir -p $MNTIMAGE/bin
591
mkdir -p $MNTIMAGE/etc
592
mkdir -p $MNTIMAGE/dev
593
mkdir -p $MNTIMAGE/loopfs
594
mkdir -p $MNTIMAGE/proc
595
mkdir -p $MNTIMAGE/sys
596
mkdir -p $MNTIMAGE/sysroot
597
ln -s bin $MNTIMAGE/sbin
598
 
599
inst /sbin/nash "$MNTIMAGE/bin/nash"
600
inst /sbin/insmod.static "$MNTIMAGE/bin/insmod"
601
ln -s /sbin/nash $MNTIMAGE/sbin/modprobe
602
 
603
if [ -n "$USE_UDEV" ]; then
604
    inst /sbin/udev.static $MNTIMAGE/sbin/udev
605
    inst /sbin/udevstart.static $MNTIMAGE/sbin/udevstart
606
    mkdir -p $MNTIMAGE/etc/udev
607
    inst /etc/udev/udev.conf $MNTIMAGE/etc/udev/udev.conf
608
    ln -s /sbin/nash $MNTIMAGE/sbin/hotplug
609
fi
610
 
611
for MODULE in $MODULES; do
612
    if [ -x /usr/bin/strip ]; then
613
	/usr/bin/strip -g $verbose /lib/modules/$kernel/$MODULE -o $MNTIMAGE/lib/$(basename $MODULE)
614
    else
615
	cp $verbose -a /lib/modules/$kernel/$MODULE $MNTIMAGE/lib
616
    fi
617
done
618
 
619
# mknod'ing the devices instead of copying them works both with and
620
# without devfs...
621
mknod $MNTIMAGE/dev/console c 5 1
622
mknod $MNTIMAGE/dev/null c 1 3
623
mknod $MNTIMAGE/dev/ram b 1 1
624
mknod $MNTIMAGE/dev/systty c 4 0
625
for i in 1 2 3 4; do
626
    mknod $MNTIMAGE/dev/tty$i c 4 $i
627
done
628
 
629
# FIXME -- this won't work if you're using devfs
630
if [ -n "$root_lvm" -a "$kernelmajor" == "2.4" ]; then
631
    pvs=$(/sbin/pvscan | grep " PV " | /bin/awk {'print $5;'} |sed 's/"//g')
632
    for pv in $pvs; do
633
	cp $verbose --parents -a $pv $MNTIMAGE/
634
    done
635
 
636
    inst /sbin/vgwrapper "$MNTIMAGE/bin/vgwrapper"
637
    ln "$MNTIMAGE/bin/vgwrapper" "$MNTIMAGE/bin/vgscan"
638
    ln "$MNTIMAGE/bin/vgwrapper" "$MNTIMAGE/bin/vgchange"
639
 
640
    mknod $MNTIMAGE/dev/lvm b 109 0
641
fi
642
 
643
if [ -n "$root_lvm" -a "$kernelmajor" == "2.6" ]; then
644
    inst /sbin/lvm.static "$MNTIMAGE/bin/lvm"
645
    if [ -f /etc/lvm/lvm.conf ]; then
646
	cp $verbose --parents /etc/lvm/lvm.conf $MNTIMAGE/
647
    fi
648
fi
649
 
650
echo "#!/bin/nash" >| $RCFILE
651
echo "" >> $RCFILE
652
 
653
echo "mount -t proc /proc /proc" >> $RCFILE
654
echo "setquiet" >> $RCFILE
655
echo "echo Mounted /proc filesystem" >> $RCFILE
656
 
657
if [ "$kernelmajor" != "2.4" ]; then
658
    echo "echo Mounting sysfs" >> $RCFILE
659
    echo "mount -t sysfs /sys /sys" >> $RCFILE
660
fi
661
 
662
if [ -n "$USE_UDEV" ]; then
663
    if [ -n "$UDEV_TMPFS" ]; then
664
	cat >> $RCFILE <<EOF
665
echo Creating /dev
666
mount -o mode=0755 -t tmpfs /dev /dev
667
mknod /dev/console c 5 1
668
mknod /dev/null c 1 3
669
mknod /dev/zero c 1 5
670
mkdir /dev/pts
671
mkdir /dev/shm
672
EOF
673
    fi
674
    cat >> $RCFILE <<EOF
675
echo Starting udev
676
/sbin/udevstart
677
echo -n "/sbin/hotplug" > /proc/sys/kernel/hotplug
678
EOF
679
fi
680
 
681
for MODULE in $MODULES; do
682
    text=""
683
    module=`echo $MODULE | sed "s|.*/||" | sed "s/.k\?o$//"`
684
    fullmodule=`echo $MODULE | sed "s|.*/||"`
685
 
686
    options=`sed -n -e "s/^options[ 	][ 	]*$module[ 	][ 	]*//p" $modulefile 2>/dev/null`
687
 
688
    if [ -n "$verbose" ]; then
689
	if [ -n "$options" ]; then
690
	    text=" with options $options"
691
	fi
692
        echo "Loading module $module$text"
693
    fi
694
    echo "echo \"Loading $fullmodule module\"" >> $RCFILE
695
    echo "insmod /lib/$fullmodule $options" >> $RCFILE
696
 
697
    # Hack - we need a delay after loading usb-storage to give things
698
    #        time to settle down before we start looking a block devices
699
    if [ "$module" = "usb-storage" ]; then
700
	echo "sleep 8" >> $RCFILE
701
    fi
702
    if [ "$module" = "zfcp" -a -f /etc/zfcp.conf ]; then
703
        echo "sleep 2" >> $RCFILE
704
        cat /etc/zfcp.conf | grep -v "^#" | tr "A-Z" "a-z" | while read DEVICE SCSIID WWPN SCSILUN FCPLUN; do
705
            echo "echo -n $WWPN > /sys/bus/ccw/drivers/zfcp/${DEVICE/0x/}/port_add" >>$RCFILE
706
            echo "echo -n $FCPLUN > /sys/bus/ccw/drivers/zfcp/${DEVICE/0x/}/$WWPN/unit_add" >>$RCFILE
707
            echo "echo -n 1 > /sys/bus/ccw/drivers/zfcp/${DEVICE/0x/}/online" >>$RCFILE
708
        done
709
    fi
710
done
711
 
712
# HACK: module loading + device creation isn't necessarily synchronous...
713
# this will make sure that we have all of our devices before trying
714
# things like RAID or LVM
715
if [ -n "$USE_UDEV" ]; then
716
  echo "/sbin/udevstart" >> $RCFILE
717
fi
718
 
719
if [ -n "$startraid" ]; then
720
    for dev in $raiddevices; do
721
	cp -a /dev/${dev} $MNTIMAGE/dev
722
	echo "raidautorun /dev/${dev}" >> $RCFILE
723
    done
724
fi
725
 
726
if [ -z "$USE_UDEV" ]; then
727
    echo "echo Creating block devices" >> $RCFILE
728
    echo "mkdevices /dev" >> $RCFILE
729
fi
730
 
731
if [ -n "$loopDev" ]; then
732
    mkdir /initrd
733
    cp -a $loopDev $MNTIMAGE/dev
734
    cp -a $rootdev $MNTIMAGE/dev
735
    echo "echo Mounting device containing loopback root filesystem" >> $RCFILE
736
    echo "mount -t $loopFs $loopDev /loopfs" >> $RCFILE
737
    echo "echo Setting up loopback device $rootdev" >> $RCFILE
738
    echo "losetup $rootdev /loopfs$loopFile" >> $RCFILE
739
elif [ -n "$root_lvm" ]; then
740
  if [ "$kernelmajor" == "2.4" ]; then
741
    echo "echo Scanning logical volumes" >> $RCFILE
742
    echo "vgscan" >> $RCFILE
743
    echo "echo Activating logical volumes" >> $RCFILE
744
    echo "vgchange -ay" >> $RCFILE
745
  else
746
    echo "echo Making device-mapper control node" >> $RCFILE
747
    echo "mkdmnod" >> $RCFILE
748
    echo "echo Scanning logical volumes" >> $RCFILE
749
    echo "lvm vgscan --ignorelockingfailure" >> $RCFILE
750
    echo "echo Activating logical volumes" >> $RCFILE
751
    echo "lvm vgchange -ay --ignorelockingfailure $root_vg" >> $RCFILE
752
  fi
753
fi
754
 
755
echo "echo Creating root device" >> $RCFILE
756
echo "mkrootdev /dev/root" >> $RCFILE
757
rootdev=/dev/root
758
 
759
if [ -n "$initramfs" ]; then
760
  echo "echo Mounting root filesystem" >> $RCFILE
761
  echo "mount -o $rootopts --ro -t $rootfs $rootdev /sysroot" >> $RCFILE
762
 
763
  echo "echo Switching to new root" >> $RCFILE
764
  if [ -n "$UDEV_KEEP_DEV" ]; then
765
    echo "switchroot --movedev /sysroot" >> $RCFILE
766
  else
767
    echo "switchroot /sysroot" >> $RCFILE
768
  fi
769
else 
770
  if [ "$kernelmajor" != "2.4" ]; then
771
    echo "umount /sys" >> $RCFILE
772
  fi
773
 
774
  if [ -n "$pivot" ]; then
775
    echo "echo 0x0100 > /proc/sys/kernel/real-root-dev" >> $RCFILE
776
 
777
    echo "echo Mounting root filesystem" >> $RCFILE
778
    echo "mount -o $rootopts --ro -t $rootfs $rootdev /sysroot" >> $RCFILE
779
 
780
    echo "pivot_root /sysroot /sysroot/initrd" >> $RCFILE
781
    echo "umount /initrd/proc" >> $RCFILE
782
  else
783
    echo "umount /proc" >> $RCFILE
784
  fi
785
 
786
  [ -n "$UDEV_TMPFS" ] && echo "umount /initrd/dev" >> $RCFILE
787
fi
788
chmod +x $RCFILE
789
 
790
if [ -z "$initramfs" ]; then
791
  (cd $MNTIMAGE; tar cf - .) | (cd $MNTPOINT; tar xf -) || exit 1
792
 
793
  umount $MNTPOINT
794
  losetup -d $LODEV
795
else
796
  (cd $MNTIMAGE; find . | cpio --quiet -c -o) >| $IMAGE || exit 1
797
fi
798
 
799
if [ -n "$compress" ]; then
800
    gzip -9 < $IMAGE >| $target || rc=1
801
else
802
    cp -a $IMAGE $target || rc=1
803
fi
804
rm -rf $MNTIMAGE $IMAGE
805
if [ -n "$MNTPOINT" ]; then rm -rf $MNTPOINT ; fi
806
 
807
exit $rc