Subversion Repositories livecd

Rev

Rev 20 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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