]> git.pld-linux.org Git - projects/geninitrd.git/blob - geninitrd
- revert last commit, udev-initrd works now
[projects/geninitrd.git] / geninitrd
1 #!/bin/sh
2
3 # geninitrd
4 #
5 #       by PLD Linux Team
6 #
7 # based on mkinitrd from RedHat Linux
8 #
9 # TODO:
10 # - make udev start before insmods
11 # - make proper use of USE_UDEV - don't copy rules if USE_UDEV is off no!
12 #
13
14 RCSID='$Id$'
15 R=${RCSID#* * }; VERSION=${R%% *}
16 PROGRAM=${0##*/}
17
18 . /etc/rc.d/init.d/functions
19 . /etc/geninitrd/functions
20 . /etc/sysconfig/system
21
22 COMPRESS=yes
23 USERAIDSTART=yes
24 USEMDADMSTATIC=no
25 USEINSMODSTATIC=no
26 USE_SUSPEND=yes
27 USE_TUXONICE=no
28 # it should be safe to remove scsi_mod from here, but I'm not sure...
29 PRESCSIMODS="-scsi_mod unknown -sd_mod"
30 target=""
31 kernel=""
32 force=""
33 verbose=""
34 MODULES=""
35 img_vers=""
36 fstab=/etc/fstab
37 insmod=insmod
38 modext=.o
39 rootdev_nr=0
40 # device node for rootfs from fstab
41 rootdev=""
42 # requires bootsplash package to operate
43 BOOT_SPLASH=no
44 # requires splashutils package to operate
45 FB_SPLASH=no
46 # requires splashutils package to operate
47 FB_CON_DECOR=no
48
49 # internal variables
50 # is /dev on tmpfs
51 dev_mounted=no
52 # is /proc mounted
53 proc_mounted=no
54 # is /sys mounted
55 sys_mounted=no
56 # is /tmp mounted on tmpfs
57 tmp_mounted=no
58
59 # are /dev nodes already created from /proc/devices info?
60 proc_partitions=no
61
62 # LVM devices that should not be included in vgscan on initrd
63 lvm_ignore_devices=''
64
65 # whether v86d should be installed
66 need_v86d=0
67
68 # LVM volumes that are needed to activate
69 # VG for root dev
70 ROOTVG=""
71 # VG for suspend resume dev
72 SUSPENDVG=""
73
74 # resume device
75 resume_dev=""
76
77 # if we should init NFS at boot
78 have_nfs=no
79 # if we should init LVM at boot
80 have_lvm=no
81 # if we should init md (softraid) at boot
82 have_md=no
83
84 usage() {
85         uname_r=$(uname -r)
86         echo "usage: $PROGRAM [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
87         echo "       [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]"
88         echo "       [--initrdfs=rom|initramfs|ext2|cram] [--modules-conf=<modules.conf>]"
89         echo "       [--with-raidstart] [--without-raidstart] [--with-insmod-static]"
90         echo "       [--with-bootsplash] [--without-bootsplash]"
91         echo "       [--with-fbsplash] [--without-fbsplash]"
92         echo "       [--with-fbcondecor] [--without-fbcondecor]"
93         echo "       [--lvmtoolsversion=1|2] [--with-udev] [--without-udev]"
94         echo "       [--with-suspend] [--without-suspend]"
95         echo "       [--with-tuxonice] [--without-tuxonice]"
96         echo "       [--without-dmraid] [--without-multipath]"
97         echo "       [--without-blkid] [--without-luks]"
98         echo "       <initrd-image> <kernel-version>"
99         echo ""
100         echo "example:"
101         echo "  $PROGRAM -f --initrdfs=rom /boot/initrd-$uname_r.gz $uname_r"
102         exit 0
103 }
104
105 msg() {
106         echo "$PROGRAM: $*"
107 }
108
109 warn() {
110         msg "WARNING: $*" >&2
111 }
112
113 debug() {
114         [ -n "$verbose" ] && msg "$*" >&2
115 }
116
117 # aborts program abnormally
118 die() {
119         local rc=${2:-1}
120         msg "ERROR: $1" 2>&2
121         exit $rc
122 }
123
124 # append text to /linuxrc
125 # takes STDIN as input
126 add_linuxrc() {
127         cat >> "$RCFILE"
128 }
129
130 # generate code to mount /dev on tmpfs and create initial nodes
131 # can be called multiple times. /dev is cleaned up (umounted) automatically at
132 # the end of script.
133 mount_dev() {
134     if [ "$INITRDFS" = "initramfs" ]; then
135                 # initramfs is read-write filesystem, no need for tmpfs
136                 return
137         fi
138
139         # we already generated tmpfs code; return
140         if is_yes "$dev_mounted"; then
141                 return
142         fi
143
144         dev_mounted=yes
145
146         busybox_applet mount mknod mkdir
147         add_linuxrc <<-EOF
148                 : 'Creating /dev'
149                 mount -o mode=0755 -t tmpfs none /dev
150                 mknod /dev/console c 5 1
151                 mknod /dev/null c 1 3
152                 mknod /dev/zero c 1 5
153                 mkdir /dev/pts
154                 mkdir /dev/shm
155         EOF
156 }
157
158 # generate code to mount /proc on initrd
159 # can be called multiple times
160 mount_proc() {
161         if is_yes "$proc_mounted"; then
162                 return
163         fi
164
165         proc_mounted=yes
166     if [ "$INITRDFS" = "initramfs" ]; then
167                 # /proc is mounted with initramfs 2.6.22.14 kernel
168                 # XXX: remove when it is clear why proc was already mounted
169                 echo "[ -f /proc/cmdline ] || mount -t proc none /proc" | add_linuxrc
170         else
171                 echo "mount -t proc none /proc" | add_linuxrc
172         fi
173 }
174
175 # generate code to mount /sys on initrd
176 # can be called multiple times
177 mount_sys() {
178         if is_yes "$sys_mounted"; then
179                 return
180         fi
181
182         sys_mounted=yes
183         echo "mount -t sysfs none /sys" | add_linuxrc
184 }
185
186 # generate code to mount /tmp on initrd
187 # can be called multiple times
188 mount_tmp() {
189     if [ "$INITRDFS" = "initramfs" ]; then
190                 # initramfs is read-write filesystem, no need for tmpfs
191                 return
192         fi
193
194         if is_yes "$tmp_mounted"; then
195                 return
196         fi
197
198         tmp_mounted=yes
199         echo "mount -t tmpfs none /tmp" | add_linuxrc
200 }
201
202 # unmount all mountpoints mounted by geninitrd
203 umount_all() {
204
205         add_linuxrc <<-'EOF'
206         : Last shell before umounting all and giving control over to real init.
207         debugshell
208         EOF
209
210         if is_yes "$dev_mounted"; then
211                 echo 'umount /dev' | add_linuxrc
212                 dev_mounted=no
213         fi
214         if is_yes "$proc_mounted"; then
215                 echo 'umount /proc' | add_linuxrc
216                 proc_mounted=no
217         fi
218         if is_yes "$sys_mounted"; then
219                 echo 'umount /sys' | add_linuxrc
220                 sys_mounted=no
221         fi
222         if is_yes "$tmp_mounted"; then
223                 echo 'umount /tmp' | add_linuxrc
224                 tmp_mounted=no
225         fi
226 }
227
228
229 # Checks if busybox has support for APPLET(s)
230 # Exits from geninitrd if the support is not present.
231 #
232 # NB! XXX do not output to STDOUT, it will appear in initrd images in some cases!
233 busybox_applet() {
234         local err=0
235
236         if [ -z "$busybox_functions" ]; then
237                 local tmp=$(/bin/initrd-busybox 2>&1)
238
239                 # BusyBox v1.1.3 says applet not found if it's not called 'busybox'.
240                 if [[ "$tmp" = *applet\ not\ found* ]]; then
241                         local t=$(mktemp -d)
242                         ln -s /bin/initrd-busybox $t/busybox
243                         local tmp=$($t/busybox 2>&1)
244                         rm -rf $t
245                 fi
246
247                 busybox_functions=$(echo "$tmp" | \
248                         sed -ne '/Currently defined functions:/,$p' | \
249                         xargs | sed -e 's,.*Currently defined functions: ,,'
250                 )
251         fi
252         for applet in $*; do
253                 local have
254                 # try cache
255                 eval have='$'busybox_have_$applet
256                 if [ -z "$have" ]; then
257                         have=$(echo "$busybox_functions" | egrep -c "( |^)$applet(,|$)")
258                         if [ "$have" = 0 ]; then
259                                 warn "This setup requires busybox-initrd compiled with applet '$applet' support"
260                                 err=1
261                         fi
262                         eval busybox_have_$applet=$have
263                 fi
264         done
265         if [ $err = 1 ]; then
266                 die "Aborted"
267         fi
268 }
269
270 # Finds module dependencies
271 #
272 # @param        $module
273 # @param        $mode   [silent]
274 #
275 # Outputs each dependant module full path including the module itself.
276 find_depmod() {
277         local module="$1"
278         local mode="$2"
279
280         # backwards compatible, process $mode
281         local modfile=$(modinfo -k $kernel -n $module 2>/dev/null)
282         if [ ! -f "$modfile" ]; then
283                 # module not found. try aliases!
284                 local alias aliases=$(modprobe_conf | awk -vm="$module" '$1 == "alias" && $2 == m { print $3 }')
285                 if [ "$aliases" ]; then
286                         for alias in $aliases; do
287                                 debug "Try $alias alias for $module"
288                                 find_depmod "$alias"
289                         done
290                         return
291                 fi
292
293                 if [ "$mode" != "silent" ]; then
294                         warn "$module: module not found for $kernel kernel"
295                 fi
296                 if ! is_no "$EXIT_IF_MISSING"; then
297                         exit 1
298                 else
299                         warn "If $module isn't compiled in kernel then this initrd may not start your system."
300                 fi
301         fi
302
303         # This works when user has module-init-tools installed even on 2.4 kernels
304         modprobe --set-version $kernel --show-depends $module --ignore-install | \
305         while read insmod modpath options; do
306                 [ "$insmod" = "insmod" ] && echo $modpath
307         done
308 }
309
310 find_firmware() {
311         local module="$1"
312         echo -n $(modinfo -k $kernel -F firmware $module 2>/dev/null | xargs)
313 }
314
315 findmodule() {
316         local skiperrors=""
317         local modName=$1
318
319         if [ ${modName#-} != $modName ]; then
320                 skiperrors=1
321                 modName=${modName#-}
322         fi
323
324         # what's that?
325         if [ "$modName" = "pluto" ]; then
326                 findmodule fc4
327                 findmodule soc
328         fi
329         if [ "$modName" = "fcal" ]; then
330                 findmodule fc4
331                 findmodule socal
332         fi
333
334         local mod depmod
335         if [ "$skiperrors" = 1 ]; then
336                 depmod=$(find_depmod $modName silent)
337         else
338                 depmod=$(find_depmod $modName)
339                 if [ $? != 0 ]; then
340                         exit 1
341                 fi
342         fi
343
344         for mod in $depmod; do
345                 mod=${mod#/lib/modules/$kernel/}
346
347                 # add each module only once
348                 local m have=0
349                 for m in $MODULES; do
350                         [ $m = $mod ] && have=1
351                 done
352                 if [ $have = 0 ]; then
353                         MODULES="$MODULES $mod" 
354
355                         # if we are adding uvesafb, we need v86d as well
356                         if [ "$modName" = "uvesafb" ]; then
357                                 need_v86d=yes
358                         fi                              
359                 fi
360         done
361 }
362
363 # install a file to temporary mount image.
364 # it will operate recursively (copying directories)
365 # and will symlink destinations if source is symlink.
366 inst() {
367         if [ $# -lt 2 ]; then
368                 die 'Usage: inst <file> [<file>] <destination>'
369         fi
370
371         local src i=0 c=$(($# - 1))
372         while [ $i -lt $c ]; do
373                 src="$src $1"
374                 i=$((i + 1))
375                 shift
376         done
377         local dest=$1
378         set -- $src
379         parentDir=$(dirname $DESTDIR$dest)
380         [ ! -d "$parentDir" ] && (debug "+ mkdir -p $parentDir"; mkdir -p $parentDir)
381         debug "+ cp $* $DESTDIR$dest"
382         cp -HR "$@" "$DESTDIR$dest"
383 }
384
385 inst_d() {
386         if [ $# = 0 ]; then
387                 die 'Usage: inst_d <destination> <destination>'
388         fi
389         for dir in "$@"; do
390                 install -d "$DESTDIR$dir"
391         done
392 }
393
394 # install executable and it's shared libraries
395 inst_exec() {
396         if [ $# -lt 2 ]; then
397                 die 'Usage: inst_exec <file>[, <file>] <destination>'
398         fi
399         local src i=0 c=$(($# - 1))
400         while [ $i -lt $c ]; do
401                 src="$src $1"
402                 i=$((i + 1))
403                 shift
404         done
405         local dest=$1
406         set -- $src
407
408         inst "$@" $dest
409
410         local lib libs=$(ldd "$@" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
411         for lib in $libs; do
412                 if [ ! -f "$DESTDIR/$_lib/${lib##*/}" ]; then
413                         inst_d /$_lib
414                         inst_exec $lib /$_lib
415                 fi
416         done
417
418         # hack for uclibc linked binaries requiring this fixed path
419         # XXX: shouldn't rpath be used here instead so th
420         if [ -f $DESTDIR/$_lib/libc.so.0 ]; then
421                 local lib=$DESTDIR/$_lib/libc.so.0
422                 lib=$(ldd "$lib" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
423                 local libdir=$(cd $(dirname "$lib"); pwd)
424                 if [ ! -e $DESTDIR$libdir ]; then
425                         libdir=$(dirname "$libdir")
426                         inst_d $libdir
427                         debug "+ ln -s /$_lib $DESTDIR$libdir"
428                         ln -s /$_lib $DESTDIR$libdir
429                 fi
430         fi
431 }
432
433 # output modules.conf / modprobe.conf
434 modprobe_conf() {
435         echo "$modprobe_conf_cache"
436 }
437
438 #
439 # defaults to modprobe -c if not told otherwise, this means include statements
440 # work from there.
441 cache_modprobe_conf() {
442         if [ "$pack_version" -lt "002005" ]; then
443                 modulefile=/etc/modules.conf
444                 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
445                         modulefile=/etc/conf.modules
446                 fi
447         fi
448
449         if [ -n "$modulefile" ]; then
450                 debug "Using $modulefile for modules config"
451                 modprobe_conf_cache=$(cat $modulefile)
452         else
453                 debug "Using modprobe -c to get modules config"
454                 modprobe_conf_cache=$(modprobe -c --set-version $kernel)
455         fi
456 }
457
458 find_modules_md() {
459         local found raidlevel
460
461         if [ -f /etc/mdadm.conf ]; then
462                 debug "Finding RAID details using mdadm for rootdev=$1"
463                 eval `/sbin/mdadm -v --examine --scan --config=/etc/mdadm.conf | awk -v rootdev="$1" '
464                 BEGIN {
465                         found = "no";
466                         dev_list = "";
467                         raidlevel = ""
468                         rootdev_devfs = rootdev;
469                         if (rootdev ~ /\/dev\/md\/[0-9]/) {
470                                 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
471                         }
472                 }
473
474                 /^ARRAY/ {
475                         if (($2 == rootdev) || ($2 == rootdev_devfs)) {
476                                 raidlevel=$3;
477                                 gsub(/level=/,NUL,raidlevel);
478                                 if (raidlevel ~ /^raid([0-6]|10)/) {
479                                         gsub(/raid/,NUL,raidlevel);
480                                 };
481                                 found="yes";
482                                 getline x;
483                                 if (x ~ /devices=/) {
484                                         dev_list = x;
485                                         gsub(".*devices=", NUL, dev_list);
486                                         gsub(",", " ", dev_list);
487                                 }
488                         }
489                 }
490
491                 END {
492                         print "have_md=" found;
493                         print "raidlevel=" raidlevel;
494                         print "dev_list=\"" dev_list "\"";
495                 }'`
496         fi
497
498         if [ "$have_md" != "yes" -a -f /etc/raidtab ]; then
499                 die "raidtools are not longer supported. Please migrate to mdadm setup!"
500         fi
501
502         if is_yes "$have_md"; then
503                 case "$raidlevel" in
504                 [01]|10)
505                         findmodule "raid$raidlevel"
506                         ;;
507                 [456])
508                         findmodule "-raid$raidlevel"
509                         findmodule "-raid456"
510                         ;;
511                 linear)
512                         findmodule "linear"
513                         ;;
514                 *)
515                         warn "raid level $number (in mdadm config) not recognized"
516                         ;;
517                 esac
518         else
519                 die "RAID devices not found for \"$1\", check your configuration!"
520         fi
521
522         rootdev_nr=$(( $rootdev_nr + 1 ))
523         eval "rootdev${rootdev_nr}=\"$1\""
524         eval "dev_list${rootdev_nr}=\"${dev_list}\""
525
526         for device in $dev_list; do
527                 find_modules_for_devpath $device
528         done
529 }
530
531 find_modules_scsi() {
532         local n
533         for n in $PRESCSIMODS; do
534                 if [ "X$n" = "Xunknown" ]; then
535                         debug "Finding SCSI modules using scsi_hostadapter"
536                         local mod scsimodules=$(modprobe_conf | awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
537                         for mod in $scsimodules; do
538                                 # for now allow scsi modules to come from anywhere. There are some
539                                 # RAID controllers with drivers in block
540                                 findmodule "$mod"
541                         done
542                 else
543                         findmodule "$n"
544                 fi
545         done
546         findmodule "-scsi_wait_scan"
547 }
548
549 # return true if node is lvm node
550 is_lvm_node() {
551         local node="$1"
552         if [ ! -e "$node" ]; then
553                 warn "check_lvm(): node $node doesn't exist!"
554                 return 1
555         fi
556
557         # block-major-58 is lvm1
558         ls -lL "$node" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}'
559         rc=$?
560
561         if [ $rc = 0 ]; then
562                 debug "LVM check: $node is LVM v1 node"
563                 # is lvm1
564                 return 0
565         fi
566
567         if [ ! -x /sbin/lvm ]; then
568                 debug "LVM check: no lvm2 tools present to check"
569                 return 0
570         fi
571
572         /sbin/lvm lvdisplay "$node" > /dev/null 2>&1
573         rc=$?
574         if [ $rc -gt 127 ]; then
575                 # lvdisplay terminated by signal! most likely it segfaulted.
576                 die "Unexpected exit from 'lvdisplay $node': $rc - are your lvm tools broken?"
577         fi
578
579         if [ $rc = 0 ]; then
580                 debug "LVM check: $node is LVM v2 node"
581         else
582                 debug "LVM check: $node is not any LVM node"
583         fi
584         return $rc
585 }
586
587
588 # return dependencies MAJOR:MINOR [MAJOR:MINOR] for DM_NAME
589 # TODO: patch `dmsetup export`
590 dm_deps() {
591         local dm_name="$1"
592         dmsetup deps $dm_name | sed -e 's/, /:/g;s/^.\+ dependencies[^:]: //;s/[()]//g;'
593 }
594
595 # export info from dmsetup
596 # param can be:
597 # - MAJOR:MINOR
598 # - /dev/dm-MINOR
599 # - /dev/mapper/DM_NAME
600 dm_export() {
601         local arg="$1"
602
603         case "$arg" in
604         *:*)
605                 local maj=${arg%:*} min=${arg#*:}
606                 dmsetup -j $maj -m $min export
607                 ;;
608         /dev/dm-*)
609                 local min=${arg#*dm-}
610                 local maj=$(awk '$2 == "device-mapper" {print $1}' /proc/devices)
611                 dm_export $maj:$min
612                 ;;
613         /dev/mapper/*)
614                 local dm_name=${arg#/dev/mapper/}
615                 dmsetup export $dm_name
616                 ;;
617         *)
618                 die "dm_export: unexpected $arg"
619                 ;;
620         esac
621 }
622
623 # find modules for $devpath
624 find_modules_for_devpath() {
625         local devpath="$1"
626         if [ -z "$devpath" ]; then
627                 die "No argument passed to find_modules_for_devpath() - is your /etc/fstab correct?"
628         fi
629
630         # /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3
631         case "$devpath" in
632         /dev/dm-*)
633                 devpath=$(dm_longname "$devpath")
634                 ;;
635         esac
636         debug "Finding modules for device path $devpath"
637
638         if is_luks "$devpath"; then
639                 find_modules_luks "$devpath"
640                 return
641         fi
642
643         if is_yes "`echo "$devpath" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
644                 if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ]; then
645                         die "root on NFS but /usr/bin/pcidev not found. Please install correct pci-database package and rerun $PROGRAM."
646                 fi
647                 if [ ! -f /proc/bus/pci/devices ]; then
648                         warn "Remember to add network card modules in /etc/sysconfig/geninitrd, example:"
649                         warn "BASICMODULES=\"e1000 ne2k-pci mii 8139too 3c59x\""
650                 else
651                         local m
652                         [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
653                         warn "NOTE: Network card(s) module(s) $NFS_ETH_MODULES is for this machine"
654                         for m in $NFS_ETH_MODULES; do
655                                 findmodule "$m"
656                         done
657                 fi
658                 findmodule "-ipv4"
659                 findmodule "nfs"
660                 have_nfs=yes
661                 warn "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel"
662                 warn "or you will have problems like init(xx) being child process of swapper(1)."
663                 return
664         fi
665
666         if [[ "$devpath" == /dev/md* ]]; then
667                 find_modules_md "$devpath"
668                 return
669         fi
670
671         if is_multipath "$devpath"; then
672                 if find_modules_multipath "$devpath"; then
673                         return
674                 fi
675                 # fallback
676         fi
677
678         if is_dmraid "$devpath"; then
679                 if find_modules_dmraid "$devpath"; then
680                         return
681                 fi
682                 # fallback
683         fi
684
685         if is_yes "$(echo "$devpath" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')"; then
686                 find_modules_scsi
687                 return
688         fi
689
690         if is_ide "$devpath"; then
691                 find_modules_ide "$devpath"
692                 return
693         fi
694
695         if [[ "$devpath" == /dev/rd/* ]]; then
696                 findmodule "DAC960"
697                 rootdev_add="/dev/rd/"
698                 return
699         fi
700
701         if [[ "$devpath" == /dev/ida/* ]]; then
702                 findmodule "cpqarray"
703                 rootdev_add="/dev/ida/"
704                 return
705         fi
706
707         if [[ "$devpath" == /dev/cciss/* ]]; then
708                 findmodule "cciss"
709                 rootdev_add="/dev/cciss/"
710                 return
711         fi
712
713         if [[ "$devpath" == /dev/ataraid/* ]]; then
714                 find_modules_ide
715                 findmodule "ataraid"
716                 ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
717                 if [ -n "$ataraidmodules" ]; then
718                         # FIXME: think about modules compiled in kernel
719                         die "ataraid_hostadapter alias not defined in modprobe.conf! Please set it and run $PROGRAM again."
720                 fi
721                 for n in $ataraidmodules; do
722                         findmodule "$n"
723                 done
724                 rootdev_add="/dev/ataraid/"
725                 return
726         fi
727
728         # check to see if we need to set up a loopback filesystem
729         if [[ "$devpath" == /dev/loop*  ]]; then
730                 die "Sorry, root on loop device isn't supported."
731                 # TODO: rewrite for bsp and make nfs ready
732                 if [ ! -x /sbin/losetup ]; then
733                         die "losetup is missing"
734                 fi
735                 key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
736                 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`"; then
737                         die "The root filesystem is on a $devpath, but there is no magic entry in $fstab for this device. Consult the $PROGRAM man page for more information"
738                 fi
739
740                 line="`awk '/'$key'/ { print $0; }' $fstab`"
741                 loopDev="$(echo $line | awk '{print $3}')"
742                 loopFs="$(echo $line | awk '{print $4}')"
743                 loopFile="$(echo $line | awk '{print $5}')"
744
745                 BASICMODULES="$BASICMODULES -loop"
746                 findmodule "-$loopFs"
747                 BASICMODULES="$BASICMODULES -${loopFs}"
748                 return
749         fi
750
751         if is_lvm_node "$devpath"; then
752                 node="$devpath"
753
754                 if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ]; then
755                         die "root on LVM but /sbin/initrd-lvm, /sbin/lvdisplay and /sbin/pvdisplay not found. Please install lvm(2) and lvm(2)-initrd package and rerun $PROGRAM."
756                 fi
757                 if [ -z "$LVMTOOLSVERSION" ]; then
758                         LVMTOOLSVERSION=$(/sbin/initrd-lvm vgchange --version 2>/dev/null|head -n 1|awk '{gsub("vgchange: Logical Volume Manager ",NIL); gsub("LVM version:     ",NIL); gsub(/\..*/,NIL); print $1}')
759                         if [ -z "$LVMTOOLSVERSION" ]; then
760                                 die "Can't determine LVM tools version. Please set LVMTOOLSVERSION and rerun $PROGRAM."
761                         fi
762                 fi
763
764                 local vg=$(/sbin/lvdisplay -c "$node" 2> /dev/null | awk -F":" ' { print $2 } ')
765                 VGVOLUMES=$(echo $VGVOLUMES $vg | tr ' ' '\n' | sort -u)
766                 local pv=$(/sbin/pvdisplay -c 2>/dev/null | awk -F":" -v vg="$vg" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ')
767                 PVDEVICES=$(echo $PVDEVICES $pv | tr ' ' '\n' | sort -u)
768
769                 if [ -n "$PVDEVICES" ]; then
770                         for device in $PVDEVICES; do
771                                 find_modules_for_devpath $device
772                         done
773                 else
774                         die "I wasn't able to find PV (via lvdisplay and pvdisplay). You can try to set PVDEVICES in /etc/sysconfig/geninitrd."
775                 fi
776                 if [ "$LVMTOOLSVERSION" = "2" ]; then
777                         findmodule "-dm-mod"
778                 elif [ "$LVMTOOLSVERSION" = "1" ]; then
779                         findmodule "-lvm"
780                         findmodule "-lvm-mod"
781                 else
782                         die "LVM version $LVMTOOLSVERSION is not supported yet."
783                 fi
784                 debug "LVM v$LVMTOOLSVERSION enabled"
785                 have_lvm=yes
786                 return
787         fi
788 }
789
790 firmware_install_module() {
791         local module="$1"
792         local firmware_files="$2"
793
794         debug "Adding Firmwares ($firmware_files) to initrd for module $module"
795         # firmware not yet installed
796         if [ ! -f "$DESTDIR/lib/firmware/firmware.sh" ]; then
797                 inst_d /lib/firmware
798 cat << 'EOF' >> "$DESTDIR/lib/firmware/firmware.sh"
799 #!/bin/sh -e
800 echo 1 > /sys$DEVPATH/loading
801 cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data
802 echo 0 > /sys$DEVPATH/loading
803 exit 0
804 EOF
805                 chmod 755 "$DESTDIR/lib/firmware/firmware.sh"
806         fi
807
808         for firmware in $firmware_files; do
809                 if [ ! -f "/lib/firmware/$firmware" ]; then
810                                 die "firmware file /lib/firmware/$firmware doesn't exist."
811                 else
812                         FIRMWAREDIR=${firmware%/*}
813                         [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR
814                         inst /lib/firmware/$firmware /lib/firmware/$firmware
815                 fi
816         done
817
818         mount_sys
819         echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc
820 }
821
822 modules_install() {
823         local modules="$1"
824         local mod
825
826         for mod in $modules; do
827                 MODULEDIR=${mod%/*}
828                 inst_d "/lib/modules/$kernel/$MODULEDIR"
829                 cp -a "/lib/modules/$kernel/$mod" "$DESTDIR/lib/modules/$kernel/$mod"
830                 gunzip "$DESTDIR/lib/modules/$kernel/$mod" 2> /dev/null
831         done
832 }
833
834 modules_add_linuxrc() {
835         local mod modpath
836
837         for mod in "$@"; do
838                 # module path without optional compression
839                 modpath=${mod%.gz}
840
841                 # name of the module
842                 module=${modpath##*/}
843                 module=${module%$modext}
844
845                 options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}' | xargs)
846
847                 generic_module=$(echo $module | tr - _)
848                 sleep_var=$(eval echo \$MODULE_${generic_module}_USLEEP)
849                 firmware_var=$(eval echo \$MODULE_${generic_module}_FIRMWARE)
850
851                 if [ -n "$verbose" ]; then
852                         s=""
853                         if [ "$options" ]; then
854                                 s="$s with options [$options]"
855                         fi
856                         if [ "$sleep_var" ]; then
857                                 s="$s and $sleep_var usleep"
858                         fi
859                         debug "Loading module [$module]$s"
860                 fi
861
862                 if [ -n "$firmware_var" ]; then
863                         firmware_install_module "$module" "$firmware_var"
864                 else
865                         firmware_files=$(find_firmware "$module")
866                         if [ -n "$firmware_files" ]; then
867                                 for file in $firmware_files; do
868                                         firmware_install_module "$module" "$file"
869                                 done
870                         fi
871                 fi
872
873                 echo "$insmod /lib/modules/$kernel/$modpath $options" | add_linuxrc
874                 if [ -n "$sleep_var" ]; then
875                         echo "usleep $sleep_var" | add_linuxrc
876                 fi
877         done
878 }
879
880 find_modules_suspend() {
881         if [ ! -x /usr/${_lib}/suspend/resume -a ! -x /usr/sbin/resume ]; then
882                 die "/usr/${_lib}/suspend/resume is missing!"
883         fi
884         resume_dev="$(awk '/^resume device =/ { print $4 } ' /etc/suspend.conf)"
885
886         local vgvolumes=$VGVOLUMES
887         find_modules_for_devpath $resume_dev
888
889         if [ "$VGVOLUMES" != "$vgvolumes" ]; then
890                 # save our VG to be able to differenciate between rootfs VG
891                 SUSPENDVG=$VGVOLUMES
892                 VGVOLUMES=$vgvolumes
893                 debug "suspend device is on LVM"
894         fi
895 }
896
897 initrd_gen_suspend() {
898         mknod $DESTDIR/dev/snapshot c 10 231
899         mkdir -p $DESTDIR${resume_dev%/*}
900         inst $resume_dev $resume_dev
901
902         inst /etc/suspend.conf /etc/suspend.conf
903         if [ -x /usr/${_lib}/suspend/resume ]; then
904                 inst_exec /usr/${_lib}/suspend/resume /bin/resume
905         else
906                 inst_exec /usr/sbin/resume /bin/resume
907         fi
908
909         add_linuxrc <<-'EOF'
910         resume=no
911         for arg in $CMDLINE; do
912                 if [ "${arg##resume=}" != "${arg}" ]; then
913                         resume=yes
914                 fi
915         done
916         if [ "$resume" = "yes" ]; then
917                 resume
918         fi
919         EOF
920 }
921
922 initrd_gen_tuxonice() {
923         mount_sys
924         add_linuxrc <<-'EOF'
925                 resume=no
926                 for arg in $CMDLINE; do
927                         if [ "${arg##resume=}" != "${arg}" -o "${arg##resume2=}" != "${arg}" ]; then
928                                 resume=yes
929                         fi
930                 done
931                 if [ "$resume" = "yes" ]; then
932                         [ -e /proc/suspend2/do_resume ] && echo > /proc/suspend2/do_resume
933                         [ -e /sys/power/suspend2/do_resume ] && echo > /sys/power/suspend2/do_resume
934                         [ -e /sys/power/tuxonice/do_resume ] && echo > /sys/power/tuxonice/do_resume
935                 fi
936         EOF
937 }
938
939 initrd_gen_v86d() {
940         debug "initrd_gen_v86d"
941         mknod $DESTDIR/dev/mem c 1 1
942         mknod $DESTDIR/dev/tty1 c 4 1
943         inst_d /sbin
944         inst_exec /sbin/v86d /sbin
945 }
946
947 initrd_gen_udev() {
948         debug "Setting up udev..."
949         inst_d /sbin /etc/udev
950
951         if [ ! -x /sbin/initrd-udevd ]; then
952                 die "/sbin/initrd-udevd not present"
953         fi
954
955         inst_exec /sbin/initrd-udevd /sbin/udevd
956         inst /etc/udev/udev.conf /etc/udev/udev.conf
957
958         mount_dev
959         mount_sys
960         add_linuxrc <<-'EOF'
961                 : 'Starting udev'
962                 /sbin/udevd --daemon
963         EOF
964
965         inst_exec /sbin/initrd-udevadm /sbin/udevadm
966         add_linuxrc <<-'EOF'
967                 /sbin/udevadm trigger
968                 /sbin/udevadm settle
969         EOF
970
971 }
972
973 initrd_gen_stop_udevd() {
974         busybox_applet killall
975         add_linuxrc     <<-'EOF'
976                 killall udevd
977         EOF
978 }
979
980
981
982 initrd_gen_bootsplash() {
983         local target="$1"
984
985         debug "Generating bootsplash"
986
987         if [ ! -x /bin/splash.bin ]; then
988                 warn "Failed to execute /bin/splash.bin. Is bootsplash package installed?"
989                 return
990         fi
991
992         if [ -r /etc/sysconfig/bootsplash ]; then
993                 . /etc/sysconfig/bootsplash
994         fi
995
996         if [ -z "$THEME" ]; then
997                 warn "Please configure your /etc/sysconfig/bootsplash first."
998                 warn "Generating bootsplashes skipped."
999                 return
1000         fi
1001
1002         if [ -z "$BOOT_SPLASH_RESOLUTIONS" ]; then
1003                 warn "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash."
1004                 warn "Not adding bootsplash to initrd."
1005         fi
1006
1007         for res in $BOOT_SPLASH_RESOLUTIONS; do
1008                 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
1009                         /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
1010                         debug "Added $res $THEME theme to initrd."
1011                 else
1012                         warn "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped"
1013                 fi
1014         done
1015 }
1016
1017 initrd_gen_fbsplash() {
1018         debug "Generating fbsplash"
1019
1020         if [ ! -x /usr/bin/splash_geninitramfs -a ! -x /usr/sbin/splash_geninitramfs ]; then
1021                 warn "Failed to find splash_geninitramfs. Is splashutils package installed?"
1022                 return
1023         fi
1024         splash_geninitramfs_bin=/usr/sbin/splash_geninitramfs
1025         [ -f /usr/bin/splash_geninitramfs ] && splash_geninitramfs_bin=/usr/bin/splash_geninitramfs
1026
1027         if [ -r /etc/sysconfig/fbsplash ]; then
1028                 . /etc/sysconfig/fbsplash
1029         fi
1030
1031         if [ -z "$SPLASH_THEME" ]; then
1032                 warn "Please configure your /etc/sysconfig/fbsplash first."
1033                 warn "Generating fbsplashes skipped."
1034                 return
1035         fi
1036
1037         if [ -z "$FB_SPLASH_RESOLUTIONS" ]; then
1038                 warn "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/fbsplash."
1039                 warn "Not adding fbsplash to initramfs."
1040                 return
1041         fi
1042
1043         for res in $FB_SPLASH_RESOLUTIONS; do
1044                 if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then
1045                         $splash_geninitramfs_bin -c $DESTDIR -r $res $SPLASH_THEME && \
1046                         debug "Added $res $SPLASH_THEME theme to initramfs."
1047                 else
1048                         warn "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped"
1049                 fi
1050         done
1051 }
1052
1053 initrd_gen_fbcondecor() {
1054         debug "Generating fbcondecor"
1055
1056         if [ ! -x /usr/bin/splash_geninitramfs -a ! -x /usr/sbin/splash_geninitramfs ]; then
1057                 warn "Failed to find splash_geninitramfs. Is splashutils package installed?"
1058                 return
1059         fi
1060         splash_geninitramfs_bin=/usr/sbin/splash_geninitramfs
1061         [ -f /usr/bin/splash_geninitramfs ] && splash_geninitramfs_bin=/usr/bin/splash_geninitramfs
1062
1063         if [ -r /etc/sysconfig/splash ]; then
1064                 . /etc/sysconfig/splash
1065         fi
1066
1067         if [ -z "$SPLASH_THEME" ]; then
1068                 warn "Please configure your /etc/sysconfig/splash first."
1069                 warn "Generating of splashes skipped."
1070                 return
1071         fi
1072
1073         if [ -z "$FB_SPLASH_RESOLUTIONS" ]; then
1074                 warn "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/splash."
1075                 warn "Not adding fbcondecor to initramfs."
1076                 return
1077         fi
1078
1079         for res in $FB_SPLASH_RESOLUTIONS; do
1080                 if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then
1081                         $splash_geninitramfs_bin -c $DESTDIR -r $res $SPLASH_THEME && \
1082                         debug "Added $res $SPLASH_THEME theme to initramfs."
1083                 else
1084                         warn "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped"
1085                 fi
1086         done
1087 }
1088
1089 # Generates /dev nodes based on /proc/partitions information.
1090 # Needs /proc mounted.
1091 # Can be called multiple times.
1092 initrd_gen_devices() {
1093         if is_yes "$proc_partitions"; then
1094                 return
1095         fi
1096         proc_partitions=yes
1097
1098         mount_dev
1099         add_linuxrc <<-'EOF'
1100                 : 'Making device nodes'
1101                 cat /proc/partitions | (
1102                         # ignore first two lines: header, empty line
1103                         read b; read b
1104
1105                         while read major minor blocks dev rest; do
1106                                 node=/dev/$dev
1107                                 mkdir -p ${node%/*}
1108                                 [ -e $node ] || mknod $node b $major $minor
1109                         done
1110                 )
1111         EOF
1112 }
1113
1114 initrd_gen_md() {
1115         debug "Setting up mdadm..."
1116
1117         if [ ! -x /sbin/mdadm -o ! -x /sbin/initrd-mdassemble ]; then
1118                 die "/sbin/mdadm or /sbin/initrd-mdassemble is missing!"
1119         fi
1120
1121         inst_exec /sbin/initrd-mdassemble /bin/mdassemble
1122
1123         # LVM on RAID case
1124         dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf | xargs)
1125         if [ "$dev_list_extra" = "partitions" ]; then
1126                 # FIXME: handle this case (see man mdadm.conf)
1127                 echo "DEVICE partitions" >> "$DESTDIR/etc/mdadm.conf"
1128                 dev_list_extra=""
1129         else
1130                 for ex_dev in $dev_list_extra; do
1131                         echo "DEVICE $ex_dev" >> "$DESTDIR/etc/mdadm.conf"
1132                 done
1133         fi
1134         do_md0=1
1135         for nr in `seq 1 $rootdev_nr`; do
1136                 eval cr_rootdev="\$rootdev${nr}"
1137                 eval cr_dev_list="\$dev_list${nr}"
1138                 debug echo "Setting up array ($cr_rootdev = $cr_dev_list)"
1139
1140                 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
1141
1142                 echo "DEVICE $cr_dev_list" >> "$DESTDIR/etc/mdadm.conf"
1143                 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
1144                 cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev | awk ' { gsub(/spares=[0-9]+/, "", $0); print $0; }')
1145                 if [ -n "$cr_md_conf" ]; then
1146                         echo "$cr_md_conf" >> "$DESTDIR/etc/mdadm.conf"
1147                 else
1148                         echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$DESTDIR/etc/mdadm.conf"
1149                 fi
1150
1151                 for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
1152                         # mkdir in case of devfs name
1153                         inst_d $(dirname $f)
1154                         [ -e "$DESTDIR/$f" ] && continue
1155                         # this works fine with and without devfs
1156                         inst $f $f
1157                 done
1158         done
1159
1160         echo "mdassemble" | add_linuxrc
1161
1162         # needed to determine md-version
1163         if [ "$do_md0" -eq 1 ]; then
1164                 mknod $DESTDIR/dev/md0 b 9 0
1165         fi
1166 }
1167
1168 initrd_gen_nfs() {
1169         # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
1170         # have problems like init(XX) being child process of swapper(1).
1171         debug "Adding rootfs on NFS support to initrd (dhcp)"
1172         mknod "$DESTDIR/dev/urandom" c 1 9
1173         mkdir "$DESTDIR/newroot"
1174         add_linuxrc <<-'EOF'
1175                 ifconfig lo 127.0.0.1 up
1176                 route add -net 127.0.0.0 mask 255.0.0.0 lo
1177                 ifconfig eth0 up
1178                 udhcpc -i eth0 -f -q -s /bin/setdhcp
1179
1180                 cd /newroot
1181                 pivot_root . initrd
1182                 [ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
1183                 exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
1184         EOF
1185
1186         cat <<-'EOF' > "$DESTDIR/bin/setdhcp"
1187                 #!/bin/sh
1188                 [ "$1" != "bound" ] && exit
1189                 [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
1190                 [ -n "$subnet" ] && NETMASK="netmask $subnet"
1191                 ifconfig $interface $ip $BROADCAST $NETMASK up
1192                 if [ -n "$router" ]; then
1193                         for r in $router; do
1194                                 route add default gw $r dev $interface
1195                         done
1196                 fi
1197
1198                 for o in $CMDLINE; do
1199                         case $o in
1200                         nfsroot=*)
1201                                 rootpath=${o#nfsroot=}
1202                                 ;;
1203                         esac
1204                 done
1205
1206                 if [ -n "$rootpath" ]; then
1207                         mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot
1208                 else
1209                         echo "Missing rootpath in what DHCP server sent to us. Failing..."
1210                         echo "All seen variables are listed below:"
1211                         set
1212                 fi
1213         EOF
1214
1215         chmod 755 "$DESTDIR/bin/setdhcp"
1216 }
1217
1218 initrd_gen_lvm() {
1219         debug "Adding LVM support to initrd"
1220         inst_d /tmp /newroot
1221         inst_exec /sbin/initrd-lvm /bin/lvm.static
1222
1223         # always make /dev on tmpfs for LVM2
1224         if [ "$LVMTOOLSVERSION" = "2" ]; then
1225                 mount_dev
1226         fi
1227
1228         if ! is_yes "$dev_mounted"; then
1229                 inst_d /dev/mapper
1230                 mknod $DESTDIR/dev/mapper/control c 10 63
1231                 for device in $PVDEVICES; do
1232                         # if LVM on RAID then device might be copied already in gen_md
1233                         [ -e "$DESTDIR/dev/$(basename $device)" ] && continue
1234                         inst $device /dev
1235                 done
1236         fi
1237
1238         mount_tmp
1239         if [ "$LVMTOOLSVERSION" = "1" ]; then
1240                 add_linuxrc <<-EOF
1241                         lvm vgscan -T
1242                         for vg in $VGVOLUMES; do
1243                                 lvm vgchange -T -a y $vg
1244                         done
1245                 EOF
1246         else
1247                 echo "cat /etc/lvm.conf > /tmp/lvm.conf" | add_linuxrc
1248                 echo "global {" > "$DESTDIR/etc/lvm.conf"
1249                 echo "  locking_type = 0" >> "$DESTDIR/etc/lvm.conf"
1250                 echo "  locking_dir = \"/tmp\"" >> "$DESTDIR/etc/lvm.conf"
1251                 echo "}" >> "$DESTDIR/etc/lvm.conf"
1252                 echo "devices {" >> "$DESTDIR/etc/lvm.conf"
1253                 echo "  sysfs_scan=0" >> "$DESTDIR/etc/lvm.conf"
1254                 if is_yes "$have_md"; then
1255                         echo "  md_component_detection = 1" >> "$DESTDIR/etc/lvm.conf"
1256                 fi
1257                 if is_yes "$have_dmraid" || is_yes "$have_multipath"; then
1258                         echo '  types = [ "device-mapper", 254 ]' >> "$DESTDIR/etc/lvm.conf"
1259                 fi
1260                 if [ "$lvm_ignore_devices" ]; then
1261                         # TODO: think of merging with lvm dumpconfig output
1262                         echo '  filter = [' >> "$DESTDIR/etc/lvm.conf"
1263                         local dev
1264                         for dev in $lvm_ignore_devices; do
1265                                 debug "LVM v2: ignore device $dev"
1266                                 printf '  "r|^%s.*|",\n' $dev
1267                         done >> "$DESTDIR/etc/lvm.conf"
1268                         echo ']' >> "$DESTDIR/etc/lvm.conf"
1269                 fi
1270                 # XXX filter= must be on one line!
1271                 lvm dumpconfig | awk '/filter=/' >> "$DESTDIR/etc/lvm.conf"
1272                 echo "}" >> "$DESTDIR/etc/lvm.conf"
1273
1274                 initrd_gen_devices
1275
1276                 add_linuxrc <<-EOF
1277                         export ROOTDEV=$rootdev
1278                         export ROOTVG="$VGVOLUMES"
1279                         export SUSPENDVG=$SUSPENDVG
1280                 EOF
1281                 add_linuxrc <<-'EOF'
1282                         # parse rootdev from kernel commandline if it begins with /
1283                         case "$ROOT" in
1284                                 /*)
1285                                 if [ "$ROOT" != "$ROOTDEV" ]; then
1286                                         ROOTDEV=$ROOT
1287                                         echo "LVM: Using 'root=$ROOTDEV' from kernel commandline"
1288                                         local tmp=${ROOTDEV#/dev/}
1289                                         if [ "$tmp" != "$ROOTDEV" ]; then
1290                                                 ROOTVG=${tmp%/*}
1291                                                 echo "LVM: Using Volume Group '$ROOTVG' for rootfs"
1292                                         fi
1293                                 fi
1294                                 ;;
1295                         esac
1296
1297                         # skip duplicate VG
1298                         if [ "$SUSPENDVG" = "$ROOTVG" ]; then
1299                                 export VGVOLUMES="$ROOTVG"
1300                         else
1301                                 export VGVOLUMES="$SUSPENDVG $ROOTVG"
1302                         fi
1303
1304                         # disable noise from LVM accessing devices that aren't ready.
1305                         read printk < /proc/sys/kernel/printk
1306                         if [ ! "$DEBUGINITRD" ]; then
1307                                 echo 0 > /proc/sys/kernel/printk
1308                         fi
1309
1310                         export LVM_SYSTEM_DIR=/tmp
1311                         : 'Scanning for Volume Groups'
1312                         lvm.static vgscan --mknodes --ignorelockingfailure 2>/dev/null
1313
1314                         : 'Activating Volume Groups'
1315                         for vol in $VGVOLUMES; do
1316                                 lvm.static vgchange --ignorelockingfailure -a y $vol 2>/dev/null
1317                         done
1318
1319                         echo "$printk" > /proc/sys/kernel/printk
1320
1321                         # Find out major/minor
1322                         attrs="$(lvm.static lvdisplay --ignorelockingfailure -c $ROOTDEV 2>/dev/null)"
1323                         if [ "$attrs" ]; then
1324                                 majmin="${attrs#*$ROOTDEV*:*:*:*:*:*:*:*:*:*:*:*}"
1325                                 if [ "$majmin" != "$attrs" ]; then
1326                                         major="${majmin%:*}"
1327                                         minor="${majmin#*:}"
1328                                 fi
1329                         fi
1330
1331                         if [ "$major" -a "$minor" ]; then
1332                                 # Pass it to kernel
1333                                 echo $((256 * $major + $minor)) > /proc/sys/kernel/real-root-dev
1334                         else
1335                                 echo 2>&1 "Error figuring out real root device for $ROOTDEV!"
1336                                 echo 2>&1 "System will not most likely boot up! So dropping you to a shell!"
1337                                 echo 2>&1 ""
1338                                 sh
1339                         fi
1340                 EOF
1341         fi
1342 }
1343
1344 initrd_gen_blkid()
1345 {
1346         debug "Adding BLKID support to initrd"
1347         inst_exec /sbin/initrd-blkid /bin/blkid
1348         initrd_gen_devices
1349         add_linuxrc <<-'EOF'
1350                 # if built with blkid change ROOT=LABEL=something into ROOT=/dev/somethingelse -
1351                 # parsed by blkid
1352                 if [ "${ROOT##LABEL=}" != "${ROOT}" -o "${ROOT##UUID=}" != "${ROOT}" ]; then
1353                         ROOT="$(/bin/blkid -t $ROOT -o device -l)"
1354                 fi
1355         EOF
1356 }
1357
1358 initrd_gen_setrootdev() {
1359         debug "Adding rootfs finding based on kernel cmdline root= option support."
1360         add_linuxrc <<-'EOF'
1361                 if [ "${ROOT##/dev/}" != "${ROOT}" ]; then
1362                         rootnr="$(busybox awk -v rootnode="${ROOT##/dev/}" '$4 == rootnode { print 256 * $1 + $2 }' /proc/partitions)"
1363                         if [ -n "$rootnr" ]; then
1364                                 echo "$rootnr" > /proc/sys/kernel/real-root-dev
1365                         fi
1366                 fi
1367         EOF
1368 }
1369
1370 initrd_gen_initramfs_switchroot() {
1371         inst_d /newroot
1372         if [ "$rootdev" = "/dev/nfs" ]; then
1373                 echo "rootfs on NFS root=/dev/nfs"
1374         else
1375                 [ ! -e "$DESTDIR/$rootdev" ] && inst $rootdev $rootdev
1376         fi
1377
1378         # parse 'root=xxx' kernel commandline
1379         # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
1380         add_linuxrc <<-'EOF'
1381                 device=/dev/no_partition_found
1382                 eval "$(busybox awk -v c="$ROOT" '
1383                         BEGIN {
1384                                 num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
1385                                 num_pattern = "[0-9a-f]" num_pattern_short;
1386                                 dev_pattern = "[hms][a-z][a-z]([0-9])+";
1387                                 partition = "no_partition_found";
1388                                 min = -1; maj = -1;
1389
1390                                 sub("^0x", "", c);
1391                                 if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
1392                                 if (c ~ "^" num_pattern  "$") {
1393                                         maj = sprintf("%s",substr(c,1,2));
1394                                         min = sprintf("%s",substr(c,3));
1395                                 }
1396                                 if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
1397                                 if (c ~ "^" dev_pattern "$") partition = c;
1398                         }
1399
1400                         $4 ~ partition { maj = $1; min = $2; }
1401                         $1 ~ maj && $2 ~ min { partition = $4; }
1402
1403                         END {
1404                                 if (maj >= 0 && min >= 0) {
1405                                         printf("device=/dev/%s; maj=%s; min=%s;\n", partition, maj, min);
1406                                 }
1407                         }
1408                         ' /proc/partitions)"
1409                 if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
1410                         mknod $device b $maj $min
1411                 fi
1412         EOF
1413
1414         add_linuxrc <<-EOF
1415                 rootdev=$rootdev
1416                 rootfs=$rootFs
1417         EOF
1418
1419         add_linuxrc <<-'EOF'
1420                 if [ "$device" = '/dev/no_partition_found' ]; then
1421                         device=$rootdev
1422                 fi
1423
1424                 mount -t $rootfs -r $device /newroot
1425                 init="$(echo "$CMDLINE" | busybox awk '/init=\// { gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')"
1426                 if [ -z "$init" -o ! -x "/newroot$init" ]; then
1427                         init=/sbin/init
1428                 fi
1429         EOF
1430
1431         umount_all
1432         busybox_applet switch_root
1433         add_linuxrc <<-'EOF'
1434                 exec switch_root /newroot $init
1435
1436                 echo "Error! initramfs should not reach this place."
1437                 echo "It probably means you've got old version of busybox, with broken"
1438                 echo "initramfs support. Trying to boot anyway, but won't promise anything."
1439
1440                 exec chroot /newroot $init
1441
1442                 echo "Failed to chroot!"
1443         EOF
1444         # we need /init being real file, not symlink, otherwise the initramfs will
1445         # not be ran by pid 1 which is required for switch_root
1446         mv $DESTDIR/linuxrc $DESTDIR/init
1447         ln -s init $DESTDIR/linuxrc
1448 }
1449
1450 # main()
1451 if [ "$(id -u)" != 0 ]; then
1452         die "You need to be root to generate initrd"
1453 fi
1454
1455 if [ -f /etc/udev/udev.conf -a -x /sbin/initrd-udevd ]; then
1456         USE_UDEV=yes
1457         . /etc/udev/udev.conf
1458 fi
1459
1460 # ide addon
1461 . /etc/geninitrd/mod-ide.sh
1462 # cryptsetup luks addon
1463 . /etc/geninitrd/mod-luks.sh
1464 # dm-multipath addon
1465 . /etc/geninitrd/mod-multipath.sh
1466 # dmraid addon
1467 . /etc/geninitrd/mod-dmraid.sh
1468
1469 if [ -x /sbin/initrd-blkid ]; then
1470         USE_BLKID=yes
1471 fi
1472
1473 if [ -r /etc/sysconfig/geninitrd ]; then
1474         . /etc/sysconfig/geninitrd
1475 fi
1476
1477 if [ ! -x /bin/initrd-busybox ]; then
1478         die "/bin/initrd-busybox is missing!"
1479 fi
1480
1481 # backwards compatible
1482 if [ "$USE_SUSPEND2" ]; then
1483         USE_TUXONICE=$USE_SUSPEND2
1484         warn "USE_SUSPEND2 is deprecated, use USE_TUXONICE now instead."
1485 fi
1486
1487 while [ $# -gt 0 ]; do
1488         case $1 in
1489         --fstab=*)
1490                 fstab=${1#--fstab=}
1491                 ;;
1492         --fstab)
1493                 fstab=$2
1494                 shift
1495                 ;;
1496         --modules-conf=*)
1497                 modulefile=${1#--modules-conf=}
1498                 ;;
1499         --modules-conf)
1500                 modulefile=$2
1501                 shift
1502                 ;;
1503         --use-raidstart|--with-raidstart)
1504                 USERAIDSTART=yes
1505                 ;;
1506         --without-raidstart)
1507                 USERAIDSTART=no
1508                 ;;
1509         --use-insmod-static|--with-insmod-static)
1510                 USEINSMODSTATIC=yes
1511                 ;;
1512         --without-insmod-static)
1513                 USEINSMODSTATIC=no
1514                 ;;
1515         --with-bootsplash)
1516                 BOOT_SPLASH=yes
1517                 ;;
1518         --without-bootsplash)
1519                 BOOT_SPLASH=no
1520                 ;;
1521         --with-fbsplash)
1522                 FB_SPLASH=yes
1523                 ;;
1524         --without-fbsplash)
1525                 FB_SPLASH=no
1526                 ;;
1527         --with-fbcondecor)
1528                 FB_CON_DECOR=yes
1529                 ;;
1530         --without-fbcondecor)
1531                 FB_CON_DECOR=no
1532                 ;;
1533         --with-suspend)
1534                 USE_SUSPEND=yes
1535                 ;;
1536         --without-suspend)
1537                 USE_SUSPEND=no
1538                 ;;
1539         --with-suspend2 | --with-tuxonice)
1540                 USE_TUXONICE=yes
1541                 ;;
1542         --without-suspend2 | --without-tuxonice)
1543                 USE_TUXONICE=no
1544                 ;;
1545         --lvmversion=*)
1546                 LVMTOOLSVERSION=${1#--lvmversion=}
1547                 ;;
1548         --lvmtoolsversion=*)
1549                 LVMTOOLSVERSION=${1#--lvmtoolsversion=}
1550                 ;;
1551         --lvmtoolsversion|--lvmversion)
1552                 LVMTOOLSVERSION=$2
1553                 shift
1554                 ;;
1555         --without-udev)
1556                 USE_UDEV=no
1557                 ;;
1558         --with-udev)
1559                 USE_UDEV=yes
1560                 ;;
1561         --without-dmraid)
1562                 USE_DMRAID=no
1563                 ;;
1564         --without-multipath)
1565                 USE_MULTPATH=no
1566                 ;;
1567         --without-blkid)
1568                 USE_BLKID=no
1569                 ;;
1570         --without-luks)
1571                 USE_LUKS=no
1572                 ;;
1573         --with=*)
1574                 BASICMODULES="$BASICMODULES ${1#--with=}"
1575                 ;;
1576         --with)
1577                 BASICMODULES="$BASICMODULES $2"
1578                 shift
1579                 ;;
1580         --version)
1581                 echo "$PROGRAM: version $VERSION"
1582                 exit 0
1583                 ;;
1584         -v)
1585                 verbose=-v
1586                 ;;
1587         --nocompress)
1588                 COMPRESS=no
1589                 ;;
1590         --ifneeded)
1591                 ifneeded=1
1592                 ;;
1593         -f)
1594                 force=1
1595                 ;;
1596         --preload=*)
1597                 PREMODS="$PREMODS ${1#--preload=}"
1598                 ;;
1599         --preload)
1600                 PREMODS="$PREMODS $2"
1601                 shift
1602                 ;;
1603         --fs=*)
1604                 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
1605                 INITRDFS=${1#--fs=}
1606                 ;;
1607         --fs)
1608                 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
1609                 INITRDFS=$2
1610                 shift
1611                 ;;
1612         --initrdfs=*)
1613                 INITRDFS=${1#--initrdfs=}
1614                 ;;
1615         --initrdfs)
1616                 INITRDFS=$2
1617                 shift
1618                 ;;
1619         --image-version)
1620                 img_vers=yes
1621                 ;;
1622         --ide-only-root)
1623                 ide_only_root="yes"
1624                 ;;
1625         *)
1626                 if [ -z "$target" ]; then
1627                         target="$1"
1628                 elif [ -z "$kernel" ]; then
1629                         kernel="$1"
1630                 else
1631                         usage >&2
1632                         exit 1
1633                 fi
1634                 ;;
1635         esac
1636
1637         shift
1638 done
1639
1640 if [ -z "$target" -o -z "$kernel" ]; then
1641         usage >&2
1642         exit 1
1643 fi
1644
1645 if [ ! -f /boot/vmlinuz-"$kernel" ]; then
1646         warn "/boot/vmlinuz-$kernel doesn't exist, is your /boot mounted?"
1647 fi
1648
1649 pack_version=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d",$1,$2)}')
1650 pack_version_long=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}')
1651
1652 if [ -z "$INITRDFS" ]; then
1653         if [ -z "$FS" ]; then
1654                 # default value
1655                 if [ "$pack_version" -ge "002005" ]; then
1656                         INITRDFS="initramfs"
1657                 else
1658                         INITRDFS="rom"
1659                 fi
1660         else
1661                 warn "Warning: FS configuration options is obsoleted. Use INITRDFS instead"
1662                 INITRDFS="$FS"
1663         fi
1664 fi
1665
1666 if [ "$pack_version" -lt "002006" ]; then
1667         USE_UDEV=no
1668         USE_DMRAID=no
1669 fi
1670
1671 if [ "$pack_version" -ge "002005" ]; then
1672         modext=".ko"
1673         insmod="insmod"
1674 fi
1675
1676 if is_yes "$USEINSMODSTATIC"; then
1677         insmod="insmod.static"
1678         INSMOD="/sbin/insmod.static"
1679         if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ]; then
1680                 INSMOD="/sbin/insmod.static.modutils"
1681         fi
1682         if [ ! -f "$INSMOD" ]; then
1683                 die "insmod.static requested but /sbin/insmod.static not found!"
1684         fi
1685 fi
1686
1687 case "$INITRDFS" in
1688         ext2)
1689                 if [ ! -x /sbin/mke2fs ]; then
1690                         die "/sbin/mke2fs is missing"
1691                 fi
1692                 ;;
1693         rom|romfs)
1694                 if [ ! -x /sbin/genromfs ]; then
1695                         die "/sbin/genromfs is missing"
1696                 fi
1697                 ;;
1698         cram|cramfs)
1699                 if [ ! -x /sbin/mkcramfs ]; then
1700                         die "/sbin/mkcramfs is missing"
1701                 fi
1702                 ;;
1703         initramfs)
1704                 if [ ! -x /bin/cpio ]; then
1705                         die "/bin/cpio is missing"
1706                 fi
1707                 if [ ! -x /usr/bin/find ]; then
1708                         die "/usr/bin/find is missing"
1709                 fi
1710                 ;;
1711         *)
1712                 die "Filesystem $INITRDFS on initrd is not supported"
1713                 ;;
1714 esac
1715
1716 if [ -L "$target" ]; then
1717         target=$(readlink -f "$target")
1718 fi
1719
1720 if [ -n "$img_vers" ]; then
1721         target="$target-$kernel"
1722 fi
1723
1724 if [ -z "$force" -a -f "$target" ]; then
1725         die "$target already exists."
1726 fi
1727
1728 if [ ! -d "/lib/modules/$kernel" ]; then
1729         die "/lib/modules/$kernel is not a directory."
1730 fi
1731
1732 if [ "$INITRDFS" != "initramfs" ]; then
1733         if is_yes "$FB_SPLASH"; then
1734                 warn "Using fbsplash requires INITRDFS=initramfs; skipping fbsplash generation"
1735                 FB_SPLASH=no
1736         fi
1737         if is_yes "$FB_CON_DECOR"; then
1738                 warn "Using fbcondecor requires INITRDFS=initramfs; skipping fbcondecor generation"
1739                 FB_CON_DECOR=no
1740         fi
1741 fi
1742
1743 if is_yes "$USE_SUSPEND" && is_yes "$USE_TUXONICE"; then
1744         warn "Tuxonice and mainline suspend are exclusive!"
1745 fi
1746
1747 if is_yes "$FB_SPLASH"  && is_yes "$BOOT_SPLASH"; then
1748         warn "bootsplash and fbsplash are exclusive!"
1749 fi
1750
1751 if [ ! -f /proc/mounts ]; then
1752         warn "/proc filesystem not mounted, may cause wrong results or failure."
1753 fi
1754
1755 if [ -d /usr/lib64 ]; then
1756         _lib=lib64
1757 else
1758         _lib=lib
1759 fi
1760 debug "Using libdir: $_lib"
1761
1762 cache_modprobe_conf
1763
1764 for n in $PREMODS; do
1765         findmodule "$n"
1766 done
1767
1768 if [ "$FBMODULE" ]; then
1769         findmodule "$FBMODULE"
1770 fi
1771
1772 # allow forcing loading SCSI and/or IDE modules
1773 if is_yes "$ADDSCSI"; then
1774         find_modules_scsi
1775 fi
1776
1777 if is_yes "$ADDIDE"; then
1778         find_modules_ide
1779 fi
1780
1781 if is_yes "$USE_SUSPEND"; then
1782         find_modules_suspend
1783 fi
1784
1785 find_root "$fstab" || exit
1786 debug "Using $rootdev as device for rootfs"
1787
1788 find_modules_for_devpath "$rootdev"
1789 [ -n "$rootdev_add" ] && find_modules_for_devpath "$rootdev_add"
1790
1791 findmodule "-$rootFs"
1792
1793 for n in $BASICMODULES; do
1794         findmodule "$n"
1795 done
1796
1797 if is_yes "$USE_TUXONICE"; then
1798         findmodule "-lzf"
1799 fi
1800
1801 if is_yes "$FB_SPLASH"; then
1802         findmodule "-evdev"
1803 fi
1804
1805 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
1806         debug "No modules are needed -- not building initrd image."
1807         exit 0
1808 fi
1809
1810 DESTDIR=$(mktemp -d -t initrd.XXXXXX) || die "mktemp failed"
1811 RCFILE="$DESTDIR/linuxrc"
1812 > "$RCFILE"
1813 chmod a+rx "$RCFILE"
1814 ln -s linuxrc $DESTDIR/init
1815
1816 # create dirs that we really need
1817 inst_d /{lib,bin,etc,dev{,/pts,/shm},loopfs,var,proc,sys}
1818
1819 modules_install "$MODULES"
1820
1821 # mknod'ing the devices instead of copying them works both with and
1822 # without devfs...
1823 mknod "$DESTDIR/dev/console" c 5 1
1824 mknod "$DESTDIR/dev/null" c 1 3
1825 mknod "$DESTDIR/dev/zero" c 1 5
1826
1827 inst_exec /bin/initrd-busybox /bin/initrd-busybox
1828 ln -s initrd-busybox $DESTDIR/bin/sh
1829 ln -s initrd-busybox $DESTDIR/bin/busybox # for older busyboxes who had /bin/busybox as EXEPATH
1830
1831 if is_yes "$USEINSMODSTATIC"; then
1832         inst_exec "$INSMOD" /bin/insmod.static
1833 fi
1834
1835 add_linuxrc <<EOF
1836 #!/bin/sh
1837 # initrd generated by:
1838 # $RCSID
1839
1840 EOF
1841 mount_proc
1842 add_linuxrc <<-'EOF'
1843         read CMDLINE < /proc/cmdline; export CMDLINE
1844
1845         for arg in $CMDLINE; do
1846                 if [ "${arg}" = "debuginitrd" ]; then
1847                         DEBUGINITRD=yes
1848                 fi
1849                 if [ "${arg##debuginitrd=}" != "${arg}" ]; then
1850                         DEBUGINITRD=${arg##debuginitrd=}
1851                 fi
1852                 if [ "${arg##root=}" != "${arg}" ]; then
1853                         ROOT=${arg##root=}
1854                 fi
1855         done
1856
1857         # make debugshell() invoke subshell if $DEBUGINITRD=sh
1858         if [ "$DEBUGINITRD" = "sh" ]; then
1859                 debugshell() {
1860 EOF
1861 if is_yes "$RUN_SULOGIN_ON_ERR"; then
1862 add_linuxrc <<-'EOF'
1863         echo "debug shell disabled by /etc/sysconfig/system:RUN_SULOGIN_ON_ERR setting"
1864 EOF
1865 else
1866 add_linuxrc <<-'EOF'
1867         sh
1868 EOF
1869 fi
1870 add_linuxrc <<-'EOF'
1871                 }
1872         else
1873                 debugshell() {
1874                         :
1875                 }
1876         fi
1877
1878         if [ "$DEBUGINITRD" ]; then
1879                 set -x
1880         fi
1881 EOF
1882
1883 modules_add_linuxrc $MODULES
1884
1885 # TODO: rewrite for busybox
1886 #if [ -n "$loopDev" ]; then
1887 #       if [ ! -d /initrd ]; then
1888 #               mkdir /initrd
1889 #       fi
1890 #
1891 #       cp -a "$loopDev" "$DESTDIR/dev"
1892 #       cp -a "$rootdev" "$DESTDIR/dev"
1893 #       echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1894 #       echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1895 #       echo "echo Setting up loopback device $rootdev" >> $RCFILE
1896 #       echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
1897 #fi
1898
1899 if is_yes "$USE_UDEV"; then
1900         initrd_gen_udev
1901 fi
1902
1903 if is_yes "$USE_TUXONICE"; then
1904         initrd_gen_tuxonice
1905 fi
1906
1907 if is_yes "$need_v86d"; then
1908         initrd_gen_v86d
1909 fi
1910
1911 if is_yes "$have_luks"; then
1912         initrd_gen_luks
1913 fi
1914
1915 if is_yes "$have_dmraid"; then
1916         initrd_gen_dmraid
1917 fi
1918
1919 if is_yes "$have_multipath"; then
1920         initrd_gen_multipath
1921 fi
1922
1923 if is_yes "$USE_BLKID"; then
1924         initrd_gen_blkid
1925 fi
1926
1927 if is_yes "$have_nfs"; then
1928         initrd_gen_nfs
1929 elif is_yes "$USERAIDSTART" && is_yes "$have_md"; then
1930         initrd_gen_md
1931         if is_yes "$have_lvm"; then
1932                 initrd_gen_lvm
1933         else
1934                 initrd_gen_setrootdev
1935         fi
1936 elif is_yes "$have_lvm"; then
1937         initrd_gen_lvm
1938 else
1939         initrd_gen_setrootdev
1940 fi
1941
1942 if is_yes "$USE_SUSPEND"; then
1943         initrd_gen_suspend
1944 fi
1945
1946 # additional devs always needed
1947 [ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev
1948
1949 if is_yes "$USE_UDEV"; then
1950         initrd_gen_stop_udevd
1951 fi
1952
1953 if [ "$INITRDFS" = "initramfs" ]; then
1954         initrd_gen_initramfs_switchroot
1955 else
1956         umount_all
1957 fi
1958
1959 if is_yes "$FB_SPLASH"; then
1960         initrd_gen_fbsplash
1961 fi
1962
1963 if is_yes "$FB_CON_DECOR"; then
1964         initrd_gen_fbcondecor
1965 fi
1966
1967 IMAGE=$(mktemp -t initrd.img-XXXXXX) || die "mktemp failed"
1968
1969 debug "Creating $INITRDFS image $IMAGE"
1970 case "$INITRDFS" in
1971         ext2)
1972                 IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}')
1973                 debug   "ext2 image size: $IMAGESIZE ($DESTDIR)"
1974                 if [ "$IMAGESIZE" -gt 4096 ]; then
1975                         warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
1976                 fi
1977
1978                 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
1979                 mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
1980                 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
1981
1982                 local tmpmnt=$(mktemp -d -t initrd.mnt-XXXXXX)
1983                 debug "Mounting ext2 image $IMAGE to $tmpmnt"
1984                 mount -o loop -t ext2 "$IMAGE" "$tmpmnt"
1985                 # We don't need this directory, so let's save space
1986                 rm -rf "$tmpmnt"/lost+found
1987
1988                 debug "Copy recursively $DESTDIR -> $tmpmnt"
1989                 cp -a $DESTDIR/* $tmpmnt
1990                 umount "$IMAGE"
1991                 rmdir "$tmpmnt"
1992
1993                 ;;
1994         rom|romfs)
1995                 genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD initrd for kernel $kernel"
1996                 IMAGESIZE=$(stat -c %s $IMAGE | awk '{print int((($1/1024)+1023)/1024)*1024}')
1997                 debug "Image size for romfs: ${IMAGESIZE}KiB ($IMAGE)"
1998                 if [ "$IMAGESIZE" -gt 4096 ]; then
1999                         warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
2000                 fi
2001                 ;;
2002         cram|cramfs)
2003                 mkcramfs "$DESTDIR" "$IMAGE"
2004                 ;;
2005         initramfs)
2006                 (cd $DESTDIR; find . | cpio --quiet -H newc -o > "$IMAGE")
2007                 ;;
2008         *)
2009                 echo "Filesystem $INITRDFS not supported by $PROGRAM";
2010 esac
2011
2012 if is_yes "$COMPRESS"; then
2013         tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
2014         debug "Compressing $target"
2015         gzip -9 < "$IMAGE" > "$tmp"
2016         mv -f "$tmp" "$target"
2017 else
2018         cp -a "$IMAGE" "$target"
2019 fi
2020
2021 size=$(stat -c %s $target | awk '{print int((($1/1024)+1023)/1024)*1024}')
2022 debug "Minimum RAM size that could be used for $target is: ramdisk_size=$size"
2023
2024 # XXX. check if bootsplash can output data to tmp dir not directly to initramfs image.
2025 if is_yes "$BOOT_SPLASH"; then
2026         initrd_gen_bootsplash "$target"
2027 fi
2028
2029 rm -rf "$DESTDIR" "$IMAGE"
2030
2031 # vim:ts=4:sw=4:noet:fdm=marker
This page took 0.234062 seconds and 4 git commands to generate.