Magellan Linux

Annotation of /trunk/mkinitrd-magellan/mkinitrd.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 737 - (hide annotations) (download)
Wed Jun 11 22:10:48 2008 UTC (16 years, 4 months ago) by niro
File size: 22084 byte(s)
-fixed a typo

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