]> git.pld-linux.org Git - projects/geninitrd.git/blame - geninitrd
- when comparing pci IDs make sure they will be compared as strings
[projects/geninitrd.git] / geninitrd
CommitLineData
bb529f94
JK
1#!/bin/sh
2
3# geninitrd
4#
5# by Jacek Konieczny <jajcus@pld.org.pl>
6#
413878f8 7# based on mkinitrd from RedHat
c31050f3 8
91e589d6 9RCSID='$Id: geninitrd,v 2.36 2003/08/09 23:42:04 baggins Exp $'
bb529f94
JK
10PATH=/sbin:$PATH
11export PATH
12
2b649ae0 13VERSION="`echo "$RCSID"|awk '{print $3}'`"
bb529f94
JK
14
15. /etc/rc.d/init.d/functions
16
17COMPRESS="yes"
2ad94d8a
AF
18# INITRDFS is set later (catch obsoleted FS option)
19#INITRDFS="rom"
6bd433bc 20USERAIDSTART="yes"
d3fa6ec7 21USEMDADMSTATIC="no"
b2e62ae1 22USEINSMODSTATIC="no"
7c38b114 23uselvm="no"
10c3df06
MM
24# it should be safe to remove scsi_mod from here, but I'm not sure...
25PRESCSIMODS="-scsi_mod unknown -sd_mod"
64497ebb
AM
26PREIDEMODS="-ide-core unknown -ide-detect -ide-disk"
27PREIDEMODSOLD="-ide-probe -ide-probe-mod -ide-disk"
bb529f94
JK
28target=""
29kernel=""
30force=""
31verbose=""
32MODULES=""
33img_vers=""
7c38b114
AF
34modulefile="/etc/modules.conf"
35raidtab="/etc/raidtab"
bb529f94 36fstab="/etc/fstab"
0868f49f
AF
37insmod="insmod"
38modext=".o"
bb529f94
JK
39
40usage () {
a2c2980f 41 echo "usage: `basename $0` [--version] [-v] [-f] [--ifneeded] [--preload <module>]" 1>&2
c31050f3 42 echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]" 1>&2
fd2dc249 43 echo " [--initrdfs=rom|ext2|cram] [--modules-conf=<modules.conf>]" 1>&2
57227e0a 44 echo " [--with-raidstart] [--without-raidstart] [--with-insmod-static]" 1>&2
2190952a 45 echo " [--with-mdadm-static]" 1>&2
a2c2980f
AF
46 echo " <initrd-image> <kernel-version>" 1>&2
47 echo " (ex: `basename $0` /boot/initrd-2.2.5-15.img 2.2.5-15)" 1>&2
7d2fc5eb 48 exit 1
bb529f94
JK
49}
50
aa69da6e 51
10c3df06
MM
52my_dirname() {
53 echo $1|awk -F/ '{print substr($0, 0, length($0) - length($NF));}'
54}
55
56find_depmod () {
57 typeset mods module f level depfile first
58
59 depfile=/lib/modules/$kernel/modules.dep
f6de9380 60
b2e62ae1 61 if [ -f $depfile ] ; then
f6de9380
MM
62 : ok
63 else
c83257bc
AF
64 echo "Error: no $depfile ! Run depmod and rerun geninitrd." 1>&2
65 exit 1
f6de9380
MM
66 fi
67
0868f49f 68 # prepend / if no path given, append $modext.gz if not given,
10c3df06 69 # quote /
3b00e899 70 origmodule="$2"
10c3df06
MM
71 module=$(echo "$2" | \
72 awk '/\// {print;next} {print "/" $0}' | \
0868f49f 73 awk '/\./ {print;next} {print $0 "'$modext'.gz"}' |
10c3df06
MM
74 awk '{gsub("/","\\/");print}')
75 mods=$(awk '
76BEGIN { here = 0 }
77/'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
78/:/ { here = 0 }
79/(.*)/ { gsub(/\\/," "); if (here) print }
4fd11db9
AF
80' $depfile | xargs)
81
0868f49f 82 # fallback to $modext
4fd11db9
AF
83 if [ "$mods" = "" ] ; then
84 module=$(echo "$module" | \
0868f49f 85 awk '{gsub("\'$modext'\.gz$","\'$modext'",$0);print}')
4fd11db9
AF
86 fi
87 mods=$(awk '
88BEGIN { here = 0 }
89/'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
90/:/ { here = 0 }
91/(.*)/ { gsub(/\\/," "); if (here) print }
10c3df06
MM
92' $depfile | xargs)
93
94 if [ "$mods" = "" ] ; then
95 if [ "$1" != silent ] ; then
3b00e899 96 echo "$origmodule: module not found in $depfile" 1>&2
10c3df06 97 fi
fd2dc249
AF
98 if ! is_no "$EXIT_IF_MISSING" ; then
99 exit 1
100 else
3b00e899 101 echo "If $origmodule isn't compiled in kernel then this initrd may not start your system". 1>&2
fd2dc249 102 fi
10c3df06
MM
103 fi
104
105 level=$3
106 if [ "$level" = "" ] ; then
107 level=0
108 fi
109 level=$(awk "BEGIN{print $level + 1}")
110 if [ $level -gt 20 ] ; then
3b00e899 111 echo "$origmodule: cycle in $depfile" 1>&2
10c3df06
MM
112 exit 1
113 fi
114
115 first=
116 for f in $mods ; do
117 if [ "$first" = "" ] ; then
118 first=$f
413878f8 119 else
10c3df06 120 find_depmod $1 $f $level
9c9f7cdb 121 fi
aa69da6e 122 done
10c3df06
MM
123
124 echo $first
aa69da6e 125}
126
10c3df06
MM
127addmodule() {
128 fmPath=$1
129 skiperrors=$2
130
131 if [ ! -f "/lib/modules/$kernel/$fmPath" ]; then
132 if [ -n "$skiperrors" ]; then
133 return
134 fi
135
136 echo "module $fmPath present in modules.dep, but not in filesystem (kernel = $kernel)" 1>&2
137 exit 1
138 fi
139
140 # only need to add each module once
141 # quote /
142 tmpFmPath=$(echo $fmPath | awk '{gsub(/\//,"\\/");print}')
143 if echo "$MODULES" | awk '/'"$tmpFmPath"'/ {exit 1}' ; then
144 MODULES="$MODULES $fmPath"
145 fi
81de8443
AF
146}
147
bb529f94 148findmodule() {
413878f8 149 skiperrors=""
150 modName=$1
10c3df06 151
413878f8 152 if [ "$(echo $modName | awk '{print(substr($0,1,1));}')" = "-" ]; then
153 skiperrors=1
154 modName="$(echo $modName | awk '{print(substr($0,2));}')"
155 fi
bb529f94 156
10c3df06 157 # what's that?
413878f8 158 if [ "$modName" = "pluto" ]; then
159 findmodule fc4
160 findmodule soc
161 fi
162 if [ "$modName" = "fcal" ]; then
163 findmodule fc4
164 findmodule socal
165 fi
bb529f94 166
10c3df06
MM
167 if [ -n "$skiperrors" ]; then
168 allModulesToFind=`find_depmod silent $modName`
169 else
170 allModulesToFind=`find_depmod normal $modName`
171 if [ $? != 0 ] ; then
172 exit 1
413878f8 173 fi
413878f8 174 fi
10c3df06
MM
175
176 for mod in $allModulesToFind ; do
177 mod=$(echo $mod | \
178 awk '{sub(/^\/lib\/modules\/[^\/]*\//,"");print}')
179 addmodule $mod "$skiperrors"
180 done
bb529f94
JK
181}
182
183inst() {
413878f8 184 if [ "$#" != "2" ];then
185 echo "usage: inst <file> <destination>"
186 return
c31050f3 187 fi
413878f8 188 [ -n "$verbose" ] && echo "$1 -> $2"
189 cp "$1" "$2"
bb529f94
JK
190}
191
a2c2980f
AF
192get_label_ext2 () {
193 /sbin/e2label $1 2> /dev/null
194}
195
196get_uuid_ext2 () {
c31050f3 197 /sbin/tune2fs -l $1 2> /dev/null | awk -F: '/UUID:/ {gsub(" ",""); print $2}'
a2c2980f
AF
198}
199
200get_label_xfs () {
3b9c8219 201 /usr/sbin/xfs_db -x -p xfs_admin -c label -r "$1"|awk -F= '{sub("^\"","", $2); sub("\"$", "", $2); print $2}'
c31050f3 202
a2c2980f
AF
203}
204
205get_uuid_xfs () {
3b9c8219 206 /usr/sbin/xfs_db -x -p xfs_admin -c uuid -r "$1"|awk -F= '{print $2}'
a2c2980f
AF
207}
208
c31050f3 209find_root() {
a2c2980f
AF
210 eval `awk '/^[\t ]*#/ {next} {if ( $2 == "/" ) {print "rootdev=\"" $1 "\"\nrootFs=\"" $3 "\""}}' $fstab`
211 case $rootdev in
212 LABEL=*)
4fd11db9
AF
213 if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
214 rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
215 if [ -n "$rootdev2" ] ; then
216 rootdev=$rootdev2
217 rootdev_found=1
a2c2980f 218 fi
4fd11db9
AF
219 fi
220 if [ "$rootdev_found." != "1." ] ; then
221 case $rootFs in
222 ext2|ext3)
223 if [ ! -x /sbin/e2label ] ; then
224 echo "/sbin/e2label is missing" 1>&2
225 exit 1
226 fi
227 get_label="get_label_ext2"
228 ;;
229 xfs)
230 if [ ! -x /usr/sbin/xfs_db ] ; then
231 echo "/usr/sbin/xfs_db is missing" 1>&2
232 exit 1
233 fi
234 get_label="get_label_xfs"
235 ;;
236 *)
237 echo "LABEL on $rootFs in not supported by geninitrd" 1>&2
238 exit 1
239 ;;
240 esac
241 if [ ! -r /proc/partitions ] ; then
242 echo '/proc/partitions is not readable'; 1>&2
3b9c8219
AF
243 exit 1
244 fi
4fd11db9
AF
245 label=${rootdev#"LABEL="}
246 for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
247 if [ -r $dev ] && [ "$label" = "`$get_label $dev`" ] ; then
248 if [ -n "$verbose" ] ; then
249 echo "Using $dev as device for rootfs"
250 fi
251 rootdev=$dev
252 rootdev_found=1
253 break
a2c2980f 254 fi
4fd11db9
AF
255 done
256 if [ "$rootdev_found." != "1." ] ; then
257 echo "geninitrd can't find real device for LABEL=$label" 1>&2
258 exit 1
259 fi
a2c2980f
AF
260 fi
261 ;;
262 UUID=*)
4fd11db9
AF
263 if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
264 rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
265 if [ -n "$rootdev2" ] ; then
266 rootdev=$rootdev2
267 rootdev_found=1
a2c2980f 268 fi
4fd11db9
AF
269 fi
270 if [ "$rootdev_found." != "1." ] ; then
271 case $rootFs in
272 ext2|ext3)
273 if [ ! -x /sbin/tune2fs ] ; then
274 echo "/sbin/tune2fs is missing" 1>&2
275 exit 1
276 fi
277 get_uuid="get_uuid_ext2"
278 ;;
279 xfs)
280 if [ ! -x /usr/sbin/xfs_db ] ; then
281 echo "/usr/sbin/xfs_db is missing" 1>&2
282 exit 1
283 fi
284 get_label="get_uuid_xfs"
285 ;;
286 *)
287 echo "UUID on $rootFs in not supported by geninitrd" 1>&2
288 exit 1
289 ;;
290 esac
291 if [ ! -r /proc/partitions ] ; then
292 echo '/proc/partitions is not readable'; 1>&2
3b9c8219
AF
293 exit 1
294 fi
4fd11db9
AF
295 uuid=${rootdev#"UUID="}
296 for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
297 if [ -r $dev ] && [ "$uuid" = "`$get_uuid $dev`" ] ; then
298 if [ -n "$verbose" ] ; then
299 echo "Using $dev as device for rootfs"
300 fi
301 rootdev=$dev
302 rootdev_found=1
303 break
a2c2980f 304 fi
4fd11db9
AF
305 done
306 if [ "$rootdev_found" != 1 ] ; then
307 echo "geninitrd can't find real device for UUID=$uuid" 1>&2
308 exit 1
309 fi
a2c2980f
AF
310 fi
311 ;;
312 esac
313
314}
bb529f94 315
7c38b114
AF
316find_modules_softraid() {
317 eval `awk -v rootdev="$1" 'BEGIN {
318 found="no";
319 dev_list="";
320}
321
322{
323 gsub("\t"," ");
324 gsub(" +", " ");
325 gsub("^ ","");
326 if (/^[\t ]*#/)
327 next;
328 if (/^raiddev/) {
329 if ($2 == rootdev) {
330 found="yes";
331 } else {
332 if (found == "yes") {
333 exit 0;
334 };
335 };
336 };
337 if (found == "yes") {
338 if ($1 == "device") {
339 dev_list = dev_list " " $2;
340 };
341 if ($1 == "raid-level") {
342 raidlevel=$2;
343 }
344 };
345}
346
347END {
348 print "raidfound=" found "\nraidlevel=" raidlevel "\ndev_list=\"" dev_list "\"\n";
349}' $raidtab `
350 if is_yes "$raidfound" ; then
351 case "$raidlevel" in
352 [0145])
353 findmodule "raid$raidlevel"
354 ;;
355 linear)
356 findmodule "linear"
357 ;;
358 *)
359 echo "raid level $number (in $raidtab) not recognized" 1>&2
360 ;;
361 esac
362 fi
363 for device in $dev_list; do
364 find_modules_for $device
365 done
366}
367
368find_modules_scsi() {
369 for n in $PRESCSIMODS; do
370 if [ "X$n" = "Xunknown" ] ; then
64497ebb
AM
371 if [ "$pack_version" -ge "002005" ]; then
372 modulefile=/etc/modprobe.conf
373 fi
7c38b114
AF
374 if [ ! -f "$modulefile" ]; then
375 modulefile=/etc/conf.modules
376 fi
377 if [ -f "$modulefile" ]; then
d4a15d5f 378 scsimodules="`awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
7c38b114
AF
379 for n in $scsimodules; do
380 # for now allow scsi modules to come from anywhere. There are some
381 # RAID controllers with drivers in block
382 findmodule "$n"
383 done
384 fi
385 else
386 findmodule "$n"
387 fi
388 done
389}
390
391find_modules_ide() {
64497ebb
AM
392 if [ "$pack_version_long" -lt "002004021" ]; then
393 [ -n "$verbose" ] && echo "Finding IDE modules for kernels <= 2.4.20"
394 for n in $PREIDEMODSOLD; do
7c38b114 395 findmodule "$n"
64497ebb
AM
396 done
397 else
398 tryauto=1
399 for n in $PREIDEMODS; do
400 if [ "X$n" = "Xunknown" ] ; then
401 if [ "$pack_version" -ge "002005" ]; then
402 modulefile=/etc/modprobe.conf
403 fi
404 if [ ! -f "$modulefile" ]; then
405 modulefile=/etc/conf.modules
406 fi
407 if [ -f "$modulefile" ]; then
408 [ -n "$verbose" ] && echo "Finding IDE modules using ide_hostadapter"
d4a15d5f 409 idemodules="`awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
64497ebb
AM
410 for n in $idemodules; do
411 tryauto=0;
412 findmodule "$n"
413 done
414 fi
415
416 if [ "$tryauto" -eq 1 ]; then
417 [ -n "$verbose" ] && echo "Finding IDE modules using PCI ID database"
418 idemodules=""
419 for n in $(awk ' { print $2 } ' /proc/bus/pci/devices); do
420 eval `awk -v pciid="$n" 'BEGIN {
421}
422
423{
424 gsub("\t"," ");
425 gsub(" +", " ");
426 gsub("^ ","");
427 if (/^[\t ]*#/)
428 next;
91e589d6
JR
429 compmod = $1 ""; # make sure comparison type will be string
430 # cause pci IDs are hexadecimal numeric
431 if (compmod == pciid) {
64497ebb
AM
432 module=$2;
433 min_kernel=$3;
434 max_kernel=$3;
435 exit 0;
436 }
437}
438
439END {
440 print "module=" module "\nmin_kernel=" min_kernel "\nmax_kernel=\"" max_kernel "\"\n";
92b8ae17 441}' /usr/share/pci-database/ide.pci`
64497ebb
AM
442 if [ -n "$module" ]; then
443 echo "$module"
444 gomin=1
445 gomax=1
446 [ -n "$min_kernel" -a "$pack_version_long" -lt "$min_kernel" ] && gomin=0
447 [ -n "$max_kernel" -a "$pack_version_long" -gt "$max_kernel" ] && gomax=0
448 [ "$gomax" -ne 0 -a "$gomin" -ne 0 ] && idemodules="$idemodules $module"
449 fi
450 done
d4a15d5f 451 idemodules=$(for n in $idemodules; do echo "$n"; done | xargs)
64497ebb
AM
452 for n in $idemodules; do
453 findmodule "$n"
454 done
455 fi
456 fi
7ca93898 457 findmodule "$n"
64497ebb
AM
458 done
459 fi
7c38b114
AF
460}
461
462find_modules_for() {
463 if is_yes "`echo "$1" | awk '/^\/dev\/md/ { print "yes"; }'`"; then
464 find_modules_softraid "$1"
465 elif is_yes "$(echo "$1" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')" ; then
466 find_modules_scsi
467 elif is_yes "`echo "$1" | awk '/^\/dev\/(hd|ide|ataraid)/ { print "yes"; }'`" ; then
468 find_modules_ide
469 elif is_yes "`echo "$1" | awk '/\/dev\/rd\// { print "yes"; }'`" ; then
470 findmodule "DAC960"
471 elif is_yes "`echo "$1" | awk '/\/dev\/ida\// { print "yes"; }'`" ; then
472 findmodule "cpqarray"
473 elif is_yes "`echo "$1" | awk '/\/dev\/cciss\// { print "yes"; }'`" ; then
474 findmodule "cciss"
475 elif is_yes "`echo "$1" | awk '/\/dev\/ataraid\// { print "yes"; }'`"; then
476 findmodule "ataraid"
d4a15d5f 477 ataraidmodules="`awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
7c38b114
AF
478 if -n "$ataraidmodules" ; then
479 # FIXME: think about modules compiled in kernel
480 echo "ERROR: ataraid_hostadapter alias not defined in $modulefile !"
481 echo "Please set it and run $0 again."
482 exit 1
483 fi
484 for n in $ataraidmodules; do
485 findmodule "$n"
486 done
487 # check to see if we need to set up a loopback filesystem
488 elif is_yes "`echo "$1" | awk -F/ '{print($3);}' | awk '/loop/ { print "yes"; }'`" ; then
489 echo "Sorry, root on loop device isn't supported." 1>&2
490 exit 1
491 # TODO: rewrite for bsp and make nfs ready
492 if [ ! -x /sbin/losetup ]; then
493 echo "losetup is missing"
494 exit 1
495 fi
496 key="^# $(echo $1 | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
497 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`" ; then
498 echo "The root filesystem is on a $1, but there is no magic entry in $fstab" 1>&2
499 echo "for this device. Consult the geninitrd man page for more information" 1>&2
500 exit 1
501 fi
502
503 line="`awk '/'$key'/ { print $0; }' $fstab`"
504 loopDev="$(echo $line | awk '{print $3}')"
505 loopFs="$(echo $line | awk '{print $4}')"
506 loopFile="$(echo $line | awk '{print $5}')"
507
508 BASICMODULES="$BASICMODULES -loop"
509 findmodule "-$loopFs"
510 BASICMODULES="$BASICMODULES -${loopFs}"
511 # don't have any clue, how is this supposed to work
512 elif ls -l "$1"|awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}'; then
513 if [ ! -f /sbin/initrd-lvm ] ; then
514 echo "ERROR: root on LVM but /sbin/initrd-lvm not found."
515 echo "Please install lvm-initrd package and rerun $0."
516 exit 1
517 fi
518 if [ -n "$PVDEVICES" ] ; then
519 for device in $PVDEVICES; do
520 find_modules_for $device
521 done
522 else
523 echo "ERROR: Sorry, but searching for PV isn't implemented yet."
524 echo "Use PVDEVICES in /etc/sysconfig/geninitrd to set it."
525 exit 1
526 fi
527 findmodule "-lvm"
528 findmodule "-lvm-mod"
529 uselvm="yes"
530 fi
531}
532
5dc785c7 533if [ -r /etc/sysconfig/geninitrd ] ; then
534 . /etc/sysconfig/geninitrd
535fi
536
2ad94d8a
AF
537if [ "x" = "x$INITRDFS" ] ; then
538 if [ "x" = "x$FS" ] ; then
539 # default value
540 INITRDFS="rom"
541 else
542 echo "Warning: FS configuration options is obsoleted. Use INITRDFS instead" 1>&2
543 INITRDFS="$FS"
544 fi
545fi
546
fd2dc249
AF
547if [ ! -x /sbin/bsp ] ; then
548 echo "/sbin/bsp is missing !"
549 exit 1
5dc785c7 550fi
551if [ "`uname -m`" = "ia64" ]; then
552 IMAGESIZE=3000
553else
554 IMAGESIZE=1500
555fi
bb529f94 556while [ $# -gt 0 ]; do
413878f8 557 case $1 in
6bd433bc
AF
558 --fstab=*)
559 fstab="`echo $1 | awk -F= '{print $2;}'`"
560 ;;
561 --fstab)
562 fstab="$2"
563 shift
413878f8 564 ;;
cd670d83
AF
565 --modules-conf=*)
566 modulefile="`echo $1 | awk -F= '{print $2;}'`"
567 ;;
57188d60 568 --modules-conf)
cd670d83
AF
569 modulefile="$2"
570 shift
571 ;;
611e9e47
AF
572 --raidtab=*)
573 raidtab="`echo $1 | awk -F= '{print $2;}'`"
574 ;;
575 --raidtab)
576 raidtab="$2"
577 shift
578 ;;
6bd433bc
AF
579 --use-raidstart|--with-raidstart)
580 USERAIDSTART="yes"
581 ;;
582 --without-raidstart)
583 USERAIDSTART="no"
584 ;;
d3fa6ec7
AM
585 --use-mdadm-static|--with-mdadm-static)
586 USEMDADMSTATIC="yes"
587 ;;
57227e0a
AF
588 --use-insmod-static|--with-insmod-static)
589 USEINSMODSTATIC="yes"
590 ;;
591 --without-insmod-static)
592 USEINSMODSTATIC="no"
593 ;;
6bd433bc
AF
594 --with=*)
595 BASICMODULES="$BASICMODULES `echo $1 | awk -F= '{print $2;}'`"
596 ;;
597 --with)
598 BASICMODULES="$BASICMODULES $2"
599 shift
413878f8 600 ;;
bb529f94 601 --version)
413878f8 602 echo "geninitrd: version $VERSION"
603 exit 0
604 ;;
bb529f94 605 -v)
413878f8 606 verbose=-v
607 ;;
bb529f94 608 --nocompress)
413878f8 609 COMPRESS="no"
610 ;;
bb529f94 611 --ifneeded)
413878f8 612 ifneeded=1
613 ;;
bb529f94 614 -f)
413878f8 615 force=1
616 ;;
6bd433bc
AF
617 --preload=*)
618 PREMODS="$PREMODS `echo $1 | awk -F= '{print $2;}'`"
619 ;;
620 --preload)
72623c13 621 PREMODS="$PREMODS $2"
6bd433bc 622 shift
413878f8 623 ;;
2ad94d8a
AF
624 --fs=*)
625 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
626 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
627 ;;
2ad94d8a
AF
628 --fs)
629 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
630 INITRDFS="$2"
631 shift
cd670d83 632 ;;
6bd433bc
AF
633 --initrdfs=*)
634 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
635 ;;
fd2dc249 636 --initrdfs)
2ad94d8a 637 INITRDFS="$2"
413878f8 638 shift
639 ;;
bb529f94 640 --image-version)
413878f8 641 img_vers=yes
642 ;;
bb529f94 643 *)
413878f8 644 if [ -z "$target" ]; then
645 target="$1"
646 elif [ -z "$kernel" ]; then
647 kernel="$1"
648 else
649 usage
650 fi
651 ;;
652 esac
653
654 shift
bb529f94
JK
655done
656
06ac05d6 657if [ -z "$target" -o -z "$kernel" ]; then
413878f8 658 usage
06ac05d6
AF
659fi
660
0868f49f 661pack_version="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d",$1,$2)}'`"
64497ebb 662pack_version_long="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}'`"
0868f49f
AF
663
664if [ "$pack_version" -ge "002005" ] ; then
665 modext=".ko"
666 insmod="insmod_ng"
667fi
668
57227e0a
AF
669if is_yes "$USEINSMODSTATIC" ; then
670 insmod="insmod.static"
b2e62ae1 671 INSMOD="/sbin/insmod.static"
f7c18703
AM
672 if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ] ; then
673 INSMOD="/sbin/insmod.static.modutils"
b2e62ae1
AF
674 fi
675 if [ ! -f "$INSMOD" ] ; then
676 echo "insmod.static requested but /sbin/insmod.static not found !" >&2
677 exit 1
678 fi
57227e0a
AF
679fi
680
2ad94d8a 681case "$INITRDFS" in
8b1e4ac7 682 ext2)
f5d71bb2 683 if [ ! -x /sbin/mke2fs ]; then
a2c2980f 684 echo "/sbin/mke2fs is missing" 1>&2
8b1e4ac7
AF
685 exit 1
686 fi
687 ;;
688 rom)
689 if [ ! -x /sbin/genromfs ]; then
a2c2980f 690 echo "/sbin/genromfs is missing" 1>&2
8b1e4ac7
AF
691 exit 1
692 fi
693 ;;
694 cram)
695 if [ ! -x /sbin/mkcramfs ]; then
a2c2980f 696 echo "/sbin/mkcramfs is missing" 1>&2
8b1e4ac7
AF
697 exit 1
698 fi
c31050f3 699 ;;
8b1e4ac7 700 *)
2ad94d8a 701 echo "Filesystem $INITRDFS on initrd is not supported" 1>&2
8b1e4ac7
AF
702 exit 1
703 ;;
704esac
bb529f94 705
bb529f94 706if [ -n "$img_vers" ]; then
413878f8 707 target="$target-$kernel"
bb529f94
JK
708fi
709
35164381 710if [ -z "$force" -a -f "$target" ]; then
a2c2980f 711 echo "$target already exists." 1>&2
413878f8 712 exit 1
bb529f94
JK
713fi
714
35164381 715if [ ! -d "/lib/modules/$kernel" ]; then
a2c2980f 716 echo "/lib/modules/$kernel is not a directory." 1>&2
413878f8 717 exit 1
bb529f94
JK
718fi
719
720for n in $PREMODS; do
35164381 721 findmodule "$n"
bb529f94
JK
722done
723
7c38b114
AF
724# allow forcing loading SCSI and/or IDE modules
725if is_yes "$ADDSCSI" ; then
726 find_modules_scsi
bb529f94
JK
727fi
728
7c38b114
AF
729if is_yes "$ADDIDE" ; then
730 find_modules_ide
cd670d83
AF
731fi
732
7c38b114 733find_root
cd670d83 734
7c38b114 735find_modules_for "$rootdev"
cd670d83 736
7c38b114 737findmodule "-$rootFs"
bb529f94 738
c31050f3 739for n in $BASICMODULES; do
7d2fc5eb 740 findmodule "$n"
bb529f94
JK
741done
742
7c38b114 743
bb529f94 744if [ -n "$ifneeded" -a -z "$MODULES" ]; then
7d2fc5eb 745 if [ -n "$verbose" ]; then
746 echo "No modules are needed -- not building initrd image."
747 fi
748 exit 0
bb529f94
JK
749fi
750
751if [ -n "$verbose" ]; then
7d2fc5eb 752 echo "Using modules: $MODULES"
bb529f94
JK
753fi
754
35164381
SZ
755MNTIMAGE="`mktemp -d /tmp/initrd.XXXXXX`"
756IMAGE="`mktemp -u /tmp/initrd.img-XXXXXX`"
757MNTPOINT="`mktemp -d /tmp/initrd.mnt-XXXXXX`"
758RCFILE="$MNTIMAGE/linuxrc"
bb529f94 759
35164381 760if [ -f "$MNTIMAGE" ]; then
c31050f3 761 echo "$MNTIMAGE already exists. Remove it and try again" 1>&2
7d2fc5eb 762 exit 1
bb529f94
JK
763fi
764
35164381 765if [ -f "$IMAGE" ]; then
a2c2980f 766 echo "$IMAGE already exists. Remove it and try again" 1>&2
7d2fc5eb 767 exit 1
bb529f94
JK
768fi
769
2ad94d8a 770if [ "$INITRDFS" = "ext2" ] ; then
35164381 771 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
bb529f94 772
bb529f94
JK
773 # We have to "echo y |" so that it doesn't complain about $IMAGE not
774 # being a block device
35164381 775 echo y | mke2fs -F "$IMAGE" "$IMAGESIZE" >/dev/null 2>/dev/null
bb529f94 776
35164381
SZ
777 mkdir -p "$MNTPOINT"
778 mount -o loop -t ext2 "$IMAGE" "$MNTPOINT"
bb529f94 779else
35164381 780 mkdir -p "$MNTPOINT"
bb529f94
JK
781fi
782
8b1e4ac7 783
35164381 784mkdir -p "$MNTIMAGE"/{lib,bin,etc,dev,loopfs}
8b1e4ac7 785
bb529f94
JK
786
787# We don't need this directory, so let's save space
35164381 788rm -rf "$MNTPOINT"/lost+found
bb529f94 789
bb529f94 790for MODULE in $MODULES; do
81de8443
AF
791 MODULEDIR="`my_dirname "$MODULE"`"
792 mkdir -p "$MNTIMAGE/lib/modules/$kernel/$MODULEDIR"
793 cp $verbose -a "/lib/modules/$kernel/$MODULE" "$MNTIMAGE/lib/modules/$kernel/$MODULE"
4fd11db9 794 gunzip "$MNTIMAGE/lib/modules/$kernel/$MODULE" 2> /dev/null
bb529f94
JK
795done
796
797# mknod'ing the devices instead of copying them works both with and
798# without devfs...
35164381 799mknod "$MNTIMAGE/dev/console" c 5 1
bb529f94 800
fd2dc249 801s="$MNTIMAGE/etc/startup"
ef66f232 802
b2e62ae1 803if [ -f /sbin/bsp-raidless ] ; then
ef66f232
MM
804 inst /sbin/bsp-raidless "$RCFILE"
805else
806 inst /sbin/bsp "$RCFILE"
807fi
808
b2e62ae1
AF
809if is_yes "$USEINSMODSTATIC" ; then
810 inst "$INSMOD" $MNTIMAGE/bin/insmod.static
57227e0a
AF
811fi
812
fd2dc249
AF
813echo "# autogenerated startup" > "$s"
814echo "" >> "$s"
c31050f3 815
fd2dc249 816for MODULE in $MODULES; do
4fd11db9
AF
817 MODULE2="`my_dirname "$MODULE"`"
818 NAME2=`basename "$MODULE" .gz`
819 MODULE2=$MODULE2/$NAME2
0868f49f 820 module="`echo $MODULE | awk -F/ '{ $0=$NF } /'$modext'$/ { $0=substr($0,1,length($0)-2); } { print $0; }'`"
fd2dc249 821 options="`awk '{ if($1 == "options" && $2 == "'${module}'") { for(i=3;i<=NF;i++) printf("%s ",$i); }}' "$modulefile"`"
c31050f3 822
fd2dc249
AF
823 if [ -n "$verbose" ]; then
824 /bin/echo -n "Loading module $module "
825 if [ -n "$options" ] ; then
826 echo "with options $options."
ea10b6a5 827 else
fd2dc249 828 echo "without options."
7d2fc5eb 829 fi
7d2fc5eb 830 fi
0868f49f 831 echo "$insmod /lib/modules/$kernel/$MODULE2 $options" >> "$s"
fd2dc249
AF
832done
833
834# TODO: rewrite for bsp
835#if [ -n "$loopDev" ]; then
836# if [ ! -d /initrd ]; then
837# mkdir /initrd
838# fi
839#
840# cp -a "$loopDev" "$MNTIMAGE/dev"
841# cp -a "$rootdev" "$MNTIMAGE/dev"
842# echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
843# echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
844# echo "echo Setting up loopback device $rootdev" >> $RCFILE
845# echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
846#fi
bb529f94 847
7c38b114 848if is_yes "$USERAIDSTART" && is_yes "$raidfound" ; then
d3fa6ec7
AM
849 if is_yes "$USEMDADMSTATIC" ; then
850 [ -n "$verbose" ] && echo "Setting up mdadm"
851 inst /sbin/initrd-mdadm "$MNTIMAGE/bin/mdadm"
852 echo "mdadm --assemble $rootdev $dev_list" >> "$s"
853 else
854 [ -n "$verbose" ] && echo "Adding raidstart to initrd"
855 inst "$raidtab" "$MNTIMAGE/etc/raidtab"
856 # don't use raidless version
857 inst /sbin/bsp "$RCFILE"
858 echo "raidstart $rootdev" >> "$s"
859 fi
fef73933 860
ef66f232
MM
861 # needed to determine md-version
862 if [ "$rootdev" != /dev/md0 ] ; then
863 mknod $MNTIMAGE/dev/md0 b 9 0
864 fi
865
866 for f in $dev_list $rootdev ; do
867 # mkdir in case of devfs name
868 mkdir -p `my_dirname $f`
869 [ -n "$verbose" ] && echo "copying $f"
870 # this works fine with and without devfs
871 cp -HR $f $MNTIMAGE/$f
872 done
2968c9dd
AF
873fi
874
7c38b114
AF
875if is_yes "$uselvm" ; then
876 [ -n "$verbose" ] && echo "Adding LVM support to initrd"
877 inst /sbin/initrd-lvm $MNTIMAGE/bin/lvm
878 mkdir $MNTIMAGE/tmp
879 mkdir $MNTIMAGE/proc
880 echo "mount none /proc proc" >> "$s"
881 echo "mount none /tmp tmpfs" >> "$s"
882 echo "mount none /dev devfs" >> "$s"
883 echo "lvm vgscan -T" >> "$s"
78ba9381 884 echo "lvm vgchange -T -a y" >> "$s"
7c38b114
AF
885 echo "umount /tmp" >> "$s"
886 echo "umount /proc" >> "$s"
0868f49f
AF
887 # fail to umount
888 #echo "umount /devfs" >> "$s"
7c38b114
AF
889fi
890
35164381 891chmod +x "$RCFILE"
bb529f94 892
35164381 893(cd "$MNTIMAGE"; tar cf - .) | (cd "$MNTPOINT"; tar xf -)
bb529f94 894
2ad94d8a 895case "$INITRDFS" in
8b1e4ac7 896 ext2)
35164381 897 umount "$IMAGE"
8b1e4ac7
AF
898 ;;
899 rom)
900 genromfs -f "$IMAGE" -d "$MNTPOINT" -V "PLD initrd for kernel $kernel"
901 ;;
902 cram)
903 mkcramfs "$MNTPOINT" "$IMAGE"
8b1e4ac7
AF
904 ;;
905 *)
2ad94d8a 906 echo "Filesystem $INITRDFS not supported by $0";
c31050f3 907esac
bb529f94
JK
908
909if is_yes "$COMPRESS" ; then
7d2fc5eb 910 gzip -9 < "$IMAGE" > "$target"
bb529f94 911else
7d2fc5eb 912 cp -a "$IMAGE" "$target"
bb529f94 913fi
35164381 914rm -rf "$MNTIMAGE" "$MNTPOINT" "$IMAGE"
This page took 0.302522 seconds and 4 git commands to generate.