Magellan Linux

Contents of /trunk/mkinitrd/mkinitrd.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 292 - (show annotations) (download) (as text)
Sat Dec 3 18:36:28 2005 UTC (18 years, 4 months ago) by niro
File MIME type: application/x-sh
File size: 20649 byte(s)
fixed module loading handling in init and now echoing ${target} when creating the initramfs

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