Subversion Repositories livecd

Rev

Rev 20 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
20 beyerle@PS 1
#!/bin/bash
2
 
3
#
4
# livecd-mkinitrd:
5
#
6
#  mkinitrd used by livecd-install script
7
#  - based on mkinitrd from RHEL4
8
#  - TMPDIR=/tmp
9
#  - comment out test of TMPDIR
10
#
169 beyerle@PS 11
# Urs Beyerle
20 beyerle@PS 12
#
13
 
14
 
15
# mkinitrd
16
#
17
# Copyright 2005,2006 Red Hat, Inc.
18
#
19
# Written by Erik Troan <ewt@redhat.com>
20
#
21
# Contributors:
22
#	Elliot Lee <sopwith@cuc.edu>
23
#	Miguel de Icaza <miguel@nuclecu.unam.mx>
24
#	Christian 'Dr. Disk' Hechelmann <drdisk@ds9.au.s.shuttle.de>
25
#	Michael K. Johnson <johnsonm@redhat.com>
26
#	Pierre Habraken <Pierre.Habraken@ujf-grenoble.fr>
27
#	Jakub Jelinek <jakub@redhat.com>
28
#	Carlo Arenas Belon (carenas@chasqui.lared.net.pe>
29
#	Keith Owens <kaos@ocs.com.au>
30
#	Bernhard Rosenkraenzer <bero@redhat.com>
31
#	Matt Wilson <msw@redhat.com>
32
#       Trond Eivind Glomsrød <teg@redhat.com>
33
#       Jeremy Katz <katzj@redhat.com>
34
#       Preston Brown <pbrown@redhat.com>
35
#	Bill Nottingham <notting@redhat.com>
36
#       Guillaume Cottenceau <gc@mandrakesoft.com>
37
#	Peter Jones <pjones@redht.com>
38
 
39
 
40
PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH
41
export PATH
42
 
43
VERSION=4.2.1.8
44
 
45
compress=1
46
allowmissing=""
47
target=""
48
kernel=""
49
force=""
50
verbose=""
51
MODULES=""
52
img_vers=""
53
builtins=""
54
pivot=1
55
initramfs=""
56
modulefile=/etc/modules.conf
57
rc=0
58
 
59
IMAGESIZE=8000
60
PRESCSIMODS="scsi_mod sd_mod unknown"
61
fstab="/etc/fstab"
62
 
63
if [ -f /etc/udev/udev.conf ]; then
64
    USE_UDEV="yes"
65
    UDEV_TMPFS="yes"
66
    UDEV_KEEP_DEV="yes"
67
    . /etc/udev/udev.conf
68
    [ -x /sbin/udev.static ] || USE_UDEV=
69
fi
70
 
71
usage () {
72
    echo "usage: `basename $0` [--version] [-v] [-f] [--preload <module>]" >&2
73
    echo "       [--omit-scsi-modules] [--omit-raid-modules] [--omit-lvm-modules]" >&2
74
    echo "       [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]" >&2
75
    echo "       [--builtin=<module>] [--nopivot] <initrd-image> <kernel-version>" >&2
76
    echo "" >&2
77
    echo "       (ex: `basename $0` /boot/initrd-2.2.5-15.img 2.2.5-15)" >&2
78
    exit 1
79
}
80
 
81
moduledep() {
82
    if [ ! -f "/lib/modules/$kernel/modules.dep" ]; then
83
	echo "No dep file found for kernel $kernel" >&2
84
	exit 1
85
    fi
86
 
87
    [ -n "$verbose" ] && echo -n "Looking for deps of module $1"
88
    deps=$(awk 'BEGIN { searched=ARGV[2]; ARGV[2]=""; rc=1 } \
89
                function modname(filename) { match(filename, /\/([^\/]+)\.k?o:?$/, ret); return ret[1] } \
90
                function show() { if (orig == searched) { print dep; orig=""; rc=0; exit } } \
91
                /^\/lib/ { show(); \
92
                           orig=modname($1); dep=""; \
93
                           if ($2) { for (i = 2; i <= NF; i++) { dep=sprintf("%s %s", dep, modname($i)); } } } \
94
                /^	/ { dep=sprintf("%s %s", dep, modname($1));  } \
95
                END      { show(); exit(rc) }' /lib/modules/$kernel/modules.dep $1)
96
    [ -n "$verbose" ] && echo -e "\t$deps"
97
}
98
 
99
findmodule() {
100
    skiperrors=""
101
 
102
    if [ $1 == "--skiperrors" ]; then
103
	skiperrors=--skiperrors
104
	shift
105
    fi
106
 
107
    local modName=$1
108
 
109
    if [ "$modName" = "off" -o "$modName" = "null" ]; then
110
	return
111
    fi
112
 
113
    if [ $(echo $modName | cut -b1) = "-" ]; then
114
	skiperrors=--skiperrors
115
	modName=$(echo $modName | cut -b2-)
116
    fi
117
 
118
    if echo $builtins | egrep -q '(^| )'$modName'( |$)' ; then
119
	[ -n "$verbose" ] && echo "module $modName assumed to be built in"
120
	set +x
121
	return
122
    fi
123
 
124
    # special cases
125
    if [ "$modName" = "i2o_block" ]; then
126
	findmodule i2o_core
127
	findmodule -i2o_pci
128
	modName="i2o_block"
129
    elif [ "$modName" = "ppa" ]; then
130
	findmodule parport
131
	findmodule parport_pc
132
	modName="ppa"
133
    elif [ "$modName" = "sbp2" ]; then
134
	findmodule ieee1394
135
	findmodule ohci1394
136
	modName="sbp2"
137
    else
138
	moduledep $modName
139
	for i in $deps; do
140
	    findmodule $i
141
	done
142
    fi
143
 
144
    for modExt in o.gz o ko ; do
145
	if [ -d /lib/modules/$kernel/updates ]; then
146
	    fmPath=`(cd /lib/modules/$kernel/updates; echo find . -name $modName.$modExt -type f | /sbin/nash --quiet) | /bin/awk {'print $1; exit;'}`
147
	fi
148
 
149
	if [ -f /lib/modules/$kernel/updates/$fmPath ]; then
150
	    fmPath=updates/$fmPath
151
	    break
152
	fi
153
 
154
	fmPath=`(cd /lib/modules/$kernel; echo find . -name $modName.$modExt -type f | /sbin/nash --quiet) | /bin/awk {'print $1; exit;'}`
155
	if [ -f /lib/modules/$kernel/$fmPath ]; then
156
	    break
157
	fi
158
    done
159
 
160
    if [ ! -f /lib/modules/$kernel/$fmPath ]; then
161
	if [ -n "$skiperrors" ]; then
162
	    return
163
	fi
164
 
165
        # ignore the absence of the scsi modules
166
	for n in $PRESCSIMODS; do
167
	    if [ "$n" = "$modName" ]; then
168
		return;
169
	    fi
170
	done;
171
 
172
	if [ -n "$allowmissing" ]; then
173
	    echo "WARNING: No module $modName found for kernel $kernel, continuing anyway" >&2
174
	    return
175
	fi
176
 
177
	echo "No module $modName found for kernel $kernel, aborting." >&2
178
	exit 1
179
    fi
180
 
181
    # only need to add each module once
182
    if ! echo $MODULES | grep -q "$fmPath" 2>/dev/null ; then
183
	MODULES="$MODULES $fmPath"
184
    fi
185
}
186
 
187
inst() {
188
    if [ "$#" != "2" ];then
189
        echo "usage: inst <file> <destination>"
190
        return
191
    fi 
192
    [ -n "$verbose" ] && echo "$1 -> $2"
193
    cp $1 $2
194
}
195
 
196
while [ $# -gt 0 ]; do
197
    case $1 in
198
	--fstab*)
199
	    if echo $1 | grep -q '=' ; then
200
	    	fstab=`echo $1 | sed 's/^--fstab=//'`
201
	    else
202
		fstab=$2
203
		shift
204
	    fi		    
205
	    ;;
206
 
207
	--with-usb)
208
	    withusb=yes
209
	    ;;
210
 
211
	--with*)
212
	    if echo $1 | grep -q '=' ; then
213
	    	modname=`echo $1 | sed 's/^--with=//'`
214
	    else
215
		modname=$2
216
		shift
217
	    fi		    
218
 
219
	    basicmodules="$basicmodules $modname"
220
	    ;;
221
 
222
	--builtin*)
223
	    if echo $1 | grep -q '=' ; then
224
	    	modname=`echo $1 | sed 's/^--builtin=//'`
225
	    else
226
		modname=$2
227
		shift
228
	    fi		    
229
	    builtins="$builtins $modname"
230
	    ;;
231
 
232
	--version)
233
	    echo "mkinitrd: version $VERSION"
234
	    exit 0
235
	    ;;
236
 
237
	-v)
238
	    verbose=-v
239
	    ;;
240
 
241
	--nocompress)
242
	    compress=""
243
	    ;;
244
 
245
	--nopivot)
246
	    pivot=""
247
	    ;;
248
 
249
	--ifneeded)
250
	    # legacy
251
	    ;;
252
 
253
	-f)
254
	    force=1
255
	    ;;
256
	--preload*)
257
	    if echo $1 | grep -q '=' ; then
258
	    	modname=`echo $1 | sed 's/^--preload=//'`
259
	    else
260
		modname=$2
261
		shift
262
	    fi		    
263
	    PREMODS="$PREMODS $modname"
264
	    ;;
265
	--omit-scsi-modules)
266
	    PRESCSIMODS=""
267
	    noscsi=1;
268
	    ;;
269
	--omit-raid-modules)
270
	    noraid=1;
271
	    ;;
272
	--omit-lvm-modules)
273
	    nolvm=1
274
	    ;;
275
	--image-version)
276
	    img_vers=yes
277
	    ;;
278
	--noudev)
279
	    USE_UDEV=
280
	    ;;
281
	--allow-missing)
282
	    allowmissing=yes
283
	    ;;
284
	*)
285
	    if [ -z "$target" ]; then
286
		target=$1
287
	    elif [ -z "$kernel" ]; then
288
		kernel=$1
289
	    else
290
		usage
291
	    fi
292
	    ;;
293
    esac
294
 
295
    shift
296
done
297
 
298
if [ -z "$target" -o -z "$kernel" ]; then
299
    usage
300
fi
301
 
302
if [ -n "$img_vers" ]; then
303
    target="$target-$kernel"
304
fi
305
 
306
if [ -z "$force" -a -f $target ]; then
307
    echo "$target already exists." >&2
308
    exit 1
309
fi
310
 
311
if [ ! -d /lib/modules/$kernel ]; then
312
    echo "/lib/modules/$kernel is not a directory." >&2
313
    exit 1
314
fi
315
 
316
if [ $UID != 0 ]; then
317
    echo "mkinitrd must be run as root"
318
    exit 1
319
fi
320
 
321
kernelmajor=`echo $kernel | cut -d . -f 1,2`
322
 
323
if [ "$kernelmajor" == "2.4" ]; then
324
    if [ -n "$verbose" ]; then echo "Creating old-style initrd"; fi
325
    USE_UDEV=
326
else
327
    if [ -n "$verbose" ]; then echo "Creating initramfs"; fi
328
    modulefile=/etc/modprobe.conf
329
    initramfs=1
330
    pivot=""
331
fi
332
 
333
# if we're not using udev, don't set any of the other bits
334
[ -z "$USE_UDEV" ] && UDEV_TMPFS= && UDEV_KEEP_DEV=
335
 
336
# find a temporary directory which doesn't use tmpfs
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" 1>&2
486
	echo "for this device. Consult the mkinitrd man page for more information" 2>&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
 
508
    rootdev=$(echo "readlink $rootdev" | /sbin/nash --quiet)
509
    major=`ls -l $rootdev | sed -e "s/.* \\([0-9]\+\\), *[0-9]\+.*/\\1/"`
510
    [ "$major" != "58" ] || root_lvm=1
511
    if echo $rootdev |grep -q /dev/mapper 2>/dev/null ; then root_lvm=1 ; fi
512
fi
513
 
514
rootfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $3; exit }}' $fstab)
515
rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; exit }}' $fstab)
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
    ln -s udev $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 none /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 none /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 5" >> $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 [ "$kernelmajor" != "2.4" ]; then
760
    echo "umount /sys" >> $RCFILE
761
fi
762
 
763
if [ -n "$initramfs" ]; then
764
    echo "echo Mounting root filesystem" >> $RCFILE
765
    echo "mount -o $rootopts --ro -t $rootfs $rootdev /sysroot" >> $RCFILE
766
 
767
    [  -n "$UDEV_KEEP_DEV" ] && echo "mount -t tmpfs --bind /dev /sysroot/dev" >> $RCFILE
768
 
769
    echo "echo Switching to new root" >> $RCFILE
770
    echo "switchroot /sysroot" >> $RCFILE
771
else 
772
  if [ -n "$pivot" ]; then
773
    echo "echo 0x0100 > /proc/sys/kernel/real-root-dev" >> $RCFILE
774
 
775
    echo "echo Mounting root filesystem" >> $RCFILE
776
    echo "mount -o $rootopts --ro -t $rootfs $rootdev /sysroot" >> $RCFILE
777
 
778
    echo "pivot_root /sysroot /sysroot/initrd" >> $RCFILE
779
    echo "umount /initrd/proc" >> $RCFILE
780
  else
781
    echo "umount /proc" >> $RCFILE
782
  fi
783
fi
784
 
785
[ -n "$UDEV_TMPFS" ] && echo "umount /initrd/dev" >> $RCFILE
786
chmod +x $RCFILE
787
 
788
if [ -z "$initramfs" ]; then
789
  (cd $MNTIMAGE; tar cf - .) | (cd $MNTPOINT; tar xf -) || exit 1
790
 
791
  umount $MNTPOINT
792
  losetup -d $LODEV
793
else
794
  (cd $MNTIMAGE; find . | cpio --quiet -c -o) > $IMAGE || exit 1
795
fi
796
 
797
if [ -n "$compress" ]; then
798
    gzip -9 < $IMAGE > $target || rc=1
799
else
800
    cp -a $IMAGE $target || rc=1
801
fi
802
rm -rf $MNTIMAGE $IMAGE
803
if [ -n "$MNTPOINT" ]; then rm -rf $MNTPOINT ; fi
804
 
805
exit $rc