7 # based on mkinitrd from RedHat Linux
10 # - make udev start before insmods
11 # - make proper use of USE_UDEV - don't copy rules if USE_UDEV is off no!
15 R=${RCSID#* * }; VERSION=${R%% *}
18 . /etc/rc.d/init.d/functions
19 . /etc/geninitrd/functions
20 . /etc/sysconfig/system
28 # it should be safe to remove scsi_mod from here, but I'm not sure...
29 PRESCSIMODS="-scsi_mod unknown -sd_mod"
30 PREIDEMODS="-ide-core unknown -ide-detect -ide-disk"
31 PREIDEMODSOLD="-ide-probe -ide-probe-mod -ide-disk"
42 # device node for rootfs from fstab
44 # requires bootsplash package to operate
46 # requires splashutils package to operate
48 # requires splashutils package to operate
58 # is /tmp mounted on tmpfs
61 # are /dev nodes already created from /proc/devices info?
64 # LVM devices that should not be included in vgscan on initrd
67 # whether v86d should be installed
70 # LVM volumes that are needed to activate
73 # VG for suspend resume dev
76 # DM name for cryptsetup luks
82 # if we should init NFS at boot
84 # if we should init LVM at boot
86 # if we should init md (softraid) at boot
88 # if we should init dmraid at boot
90 # if we should init cryptsetup luks at boot
92 # if we should init dm-multipath at boot
94 # dm-multipath wwid which is used for rootfs
99 echo "usage: $PROGRAM [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
100 echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]"
101 echo " [--initrdfs=rom|initramfs|ext2|cram] [--modules-conf=<modules.conf>]"
102 echo " [--with-raidstart] [--without-raidstart] [--with-insmod-static]"
103 echo " [--with-bootsplash] [--without-bootsplash]"
104 echo " [--with-fbsplash] [--without-fbsplash]"
105 echo " [--with-fbcondecor] [--without-fbcondecor]"
106 echo " [--lvmtoolsversion=1|2] [--with-udev] [--without-udev]"
107 echo " [--with-suspend] [--without-suspend]"
108 echo " [--with-tuxonice] [--without-tuxonice]"
109 echo " [--without-dmraid] [--without-multipath]"
110 echo " [--without-blkid] [--without-luks]"
111 echo " <initrd-image> <kernel-version>"
114 echo " $PROGRAM -f --initrdfs=rom /boot/initrd-$uname_r.gz $uname_r"
123 msg "WARNING: $*" >&2
127 [ -n "$verbose" ] && msg "$*" >&2
130 # aborts program abnormally
137 # append text to /linuxrc
138 # takes STDIN as input
143 # generate code to mount /dev on tmpfs and create initial nodes
144 # can be called multiple times. /dev is cleaned up (umounted) automatically at
147 if [ "$INITRDFS" = "initramfs" ]; then
148 # initramfs is read-write filesystem, no need for tmpfs
152 # we already generated tmpfs code; return
153 if is_yes "$dev_mounted"; then
159 busybox_applet mount mknod mkdir
162 mount -o mode=0755 -t tmpfs none /dev
163 mknod /dev/console c 5 1
164 mknod /dev/null c 1 3
165 mknod /dev/zero c 1 5
171 # generate code to mount /proc on initrd
172 # can be called multiple times
174 if is_yes "$proc_mounted"; then
179 if [ "$INITRDFS" = "initramfs" ]; then
180 # /proc is mounted with initramfs 2.6.22.14 kernel
181 # XXX: remove when it is clear why proc was already mounted
182 echo "[ -f /proc/cmdline ] || mount -t proc none /proc" | add_linuxrc
184 echo "mount -t proc none /proc" | add_linuxrc
188 # generate code to mount /sys on initrd
189 # can be called multiple times
191 if is_yes "$sys_mounted"; then
196 echo "mount -t sysfs none /sys" | add_linuxrc
199 # generate code to mount /tmp on initrd
200 # can be called multiple times
202 if [ "$INITRDFS" = "initramfs" ]; then
203 # initramfs is read-write filesystem, no need for tmpfs
207 if is_yes "$tmp_mounted"; then
212 echo "mount -t tmpfs none /tmp" | add_linuxrc
215 # unmount all mountpoints mounted by geninitrd
219 : Last shell before umounting all and giving control over to real init.
223 if is_yes "$dev_mounted"; then
224 echo 'umount /dev' | add_linuxrc
227 if is_yes "$proc_mounted"; then
228 echo 'umount /proc' | add_linuxrc
231 if is_yes "$sys_mounted"; then
232 echo 'umount /sys' | add_linuxrc
235 if is_yes "$tmp_mounted"; then
236 echo 'umount /tmp' | add_linuxrc
242 # Checks if busybox has support for APPLET(s)
243 # Exits from geninitrd if the support is not present.
245 # NB! XXX do not output to STDOUT, it will appear in initrd images in some cases!
249 if [ -z "$busybox_functions" ]; then
250 local tmp=$(/bin/initrd-busybox 2>&1)
252 # BusyBox v1.1.3 says applet not found if it's not called 'busybox'.
253 if [[ "$tmp" = *applet\ not\ found* ]]; then
255 ln -s /bin/initrd-busybox $t/busybox
256 local tmp=$($t/busybox 2>&1)
260 busybox_functions=$(echo "$tmp" | \
261 sed -ne '/Currently defined functions:/,$p' | \
262 xargs | sed -e 's,.*Currently defined functions: ,,'
268 eval have='$'busybox_have_$applet
269 if [ -z "$have" ]; then
270 have=$(echo "$busybox_functions" | egrep -c "( |^)$applet(,|$)")
271 if [ "$have" = 0 ]; then
272 warn "This setup requires busybox-initrd compiled with applet '$applet' support"
275 eval busybox_have_$applet=$have
278 if [ $err = 1 ]; then
283 # Finds module dependencies
286 # @param $mode [silent]
288 # Outputs each dependant module full path including the module itself.
293 # backwards compatible, process $mode
295 if [ "$mode" = "silent" ]; then
296 modfile=$(modinfo -k $kernel -n $module 2>/dev/null)
298 modfile=$(modinfo -k $kernel -n $module)
300 if [ ! -f "$modfile" ]; then
301 # module not found. try aliases!
302 local alias aliases=$(modprobe_conf | awk -vm="$module" '$1 == "alias" && $2 == m { print $3 }')
303 if [ "$aliases" ]; then
304 for alias in $aliases; do
305 debug "Try $alias alias for $module"
311 if [ "$mode" != "silent" ]; then
312 warn "$module: module not found for $kernel kernel"
314 if ! is_no "$EXIT_IF_MISSING"; then
317 warn "If $module isn't compiled in kernel then this initrd may not start your system."
321 # This works when user has module-init-tools installed even on 2.4 kernels
322 modprobe --set-version $kernel --show-depends $module | \
323 while read insmod modpath options; do
330 echo -n $(modinfo -k $kernel -F firmware $module 2>/dev/null | xargs)
337 if [ ${modName#-} != $modName ]; then
343 if [ "$modName" = "pluto" ]; then
347 if [ "$modName" = "fcal" ]; then
353 if [ "$skiperrors" = 1 ]; then
354 depmod=$(find_depmod $modName silent)
356 depmod=$(find_depmod $modName)
362 for mod in $depmod; do
363 mod=${mod#/lib/modules/$kernel/}
365 # add each module only once
367 for m in $MODULES; do
368 [ $m = $mod ] && have=1
370 if [ $have = 0 ]; then
371 MODULES="$MODULES $mod"
373 # if we are adding uvesafb, we need v86d as well
374 if [ "$modName" = "uvesafb" ]; then
381 # install a file to temporary mount image.
382 # it will operate recursively (copying directories)
383 # and will symlink destinations if source is symlink.
385 if [ $# -lt 2 ]; then
386 die 'Usage: inst <file> [<file>] <destination>'
389 local src i=0 c=$(($# - 1))
390 while [ $i -lt $c ]; do
397 parentDir=$(dirname $DESTDIR$dest)
398 [ ! -d "$parentDir" ] && (debug "+ mkdir -p $parentDir"; mkdir -p $parentDir)
399 debug "+ cp $* $DESTDIR$dest"
400 cp -HR "$@" "$DESTDIR$dest"
405 die 'Usage: inst_d <destination> <destination>'
408 install -d "$DESTDIR$dir"
412 # install executable and it's shared libraries
414 if [ $# -lt 2 ]; then
415 die 'Usage: inst_exec <file>[, <file>] <destination>'
417 local src i=0 c=$(($# - 1))
418 while [ $i -lt $c ]; do
428 local lib libs=$(ldd "$@" | awk '/statically|linux-gate\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
430 if [ ! -f "$DESTDIR/$_lib/${lib##*/}" ]; then
432 inst_exec $lib /$_lib
437 # output modules.conf / modprobe.conf
439 echo "$modprobe_conf_cache"
443 # defaults to modprobe -c if not told otherwise, this means include statements
445 cache_modprobe_conf() {
446 if [ "$pack_version" -lt "002005" ]; then
447 modulefile=/etc/modules.conf
448 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
449 modulefile=/etc/conf.modules
453 if [ -n "$modulefile" ]; then
454 debug "Using $modulefile for modules config"
455 modprobe_conf_cache=$(cat $modulefile)
457 debug "Using modprobe -c to get modules config"
458 modprobe_conf_cache=$(modprobe -c --set-version $kernel)
463 local found raidlevel
465 if [ -f /etc/mdadm.conf ]; then
466 debug "Finding RAID details using mdadm for rootdev=$1"
467 eval `/sbin/mdadm -v --examine --scan --config=/etc/mdadm.conf | awk -v rootdev="$1" '
472 rootdev_devfs = rootdev;
473 if (rootdev ~ /\/dev\/md\/[0-9]/) {
474 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
479 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
481 gsub(/level=/,NUL,raidlevel);
482 if (raidlevel ~ /^raid([0-6]|10)/) {
483 gsub(/raid/,NUL,raidlevel);
487 if (x ~ /devices=/) {
489 gsub(".*devices=", NUL, dev_list);
490 gsub(",", " ", dev_list);
496 print "have_md=" found;
497 print "raidlevel=" raidlevel;
498 print "dev_list=\"" dev_list "\"";
502 if [ "$have_md" != "yes" -a -f /etc/raidtab ]; then
503 die "raidtools are not longer supported. Please migrate to mdadm setup!"
506 if is_yes "$have_md"; then
509 findmodule "raid$raidlevel"
512 findmodule "-raid$raidlevel"
513 findmodule "-raid456"
519 warn "raid level $number (in mdadm config) not recognized"
523 die "RAID devices not found for \"$1\", check your configuration!"
526 rootdev_nr=$(( $rootdev_nr + 1 ))
527 eval "rootdev${rootdev_nr}=\"$1\""
528 eval "dev_list${rootdev_nr}=\"${dev_list}\""
530 for device in $dev_list; do
531 find_modules_for_devpath $device
535 find_modules_scsi() {
537 for n in $PRESCSIMODS; do
538 if [ "X$n" = "Xunknown" ]; then
539 debug "Finding SCSI modules using scsi_hostadapter"
540 local mod scsimodules=$(modprobe_conf | awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
541 for mod in $scsimodules; do
542 # for now allow scsi modules to come from anywhere. There are some
543 # RAID controllers with drivers in block
550 findmodule "-scsi_wait_scan"
555 # remove partition, if any
556 local disk=${devpath%[0-9]*}
557 # set blockdev for rootfs (hda, sdc, ...)
558 local rootblkdev=${disk#/dev/}
561 if [ "$pack_version_long" -lt "002004021" ]; then
562 debug "Finding IDE modules for kernels <= 2.4.20"
563 for n in $PREIDEMODSOLD; do
568 for n in $PREIDEMODS; do
569 if [ "X$n" = "Xunknown" ]; then
570 debug "Finding IDE modules using ide_hostadapter"
571 local mod idemodules=$(modprobe_conf | awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
572 for mod in $idemodules; do
577 if [ "$tryauto" -eq 1 ]; then
579 if [ -r /usr/share/pci-database/ide.pci -a -r /proc/bus/pci/devices ]; then
580 debug "Finding IDE modules using PCI ID database"
581 # Finding IDE modules using PCI ID database {{{
582 if is_yes "${ide_only_root}"; then
583 if [ -f /sys/block/${rootblkdev}/device/../../vendor -a -f /sys/block/${rootblkdev}/device/../../device ]; then
584 vendorid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../vendor)"
585 deviceid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../device)"
586 searchpciid="${vendorid}${deviceid}"
587 elif [ -f /proc/ide/${rootblkdev}/../config ]; then
588 searchpciid="$(awk ' /pci bus/ { print $7$9 } ' /proc/ide/${rootblkdev}/../config)"
592 if [ -z "${searchpciid}" ]; then
593 searchpciid="$(awk ' { print $2 } ' /proc/bus/pci/devices)"
598 for nb in $searchpciid; do
599 eval `awk -v pciid="$nb" '{
605 compmod = $1 ""; # make sure comparison type will be string
606 # cause pci IDs are hexadecimal numeric
607 if (compmod == pciid) {
609 # min_kernel=$3; # now in ide.pci $3,$4 = vendor and device name
616 print "module=" module "\nmin_kernel=" min_kernel "\nmax_kernel=\"" max_kernel "\"\n";
617 }' /usr/share/pci-database/ide.pci`
618 [ -n "$module" ] && idemodules="$idemodules $module"
620 if is_yes "$(awk ' /ide=reverse/ { print "yes" } ' /proc/cmdline)"; then
622 for nc in idemodules; do
623 new_idemodules="$nc $new_idemodules"
625 idemodules="${new_idemodules}"
628 if [ -z "$idemodules" ]; then
629 warn "rootfs on IDE device but no related modules found, loading ide-generic."
630 idemodules="ide-generic"
634 for nd in $idemodules; do
640 [ -r /usr/share/pci-database/ide.pci ] || warn "/usr/share/pci-database/ide.pci missing."
641 [ -r /proc/bus/pci/devices ] || warn "/proc/bus/pci/devices missing."
642 warn "Automatic IDE modules finding not available."
653 # return true if node is lvm node
656 if [ ! -e "$node" ]; then
657 warn "check_lvm(): node $node doesn't exist!"
661 # block-major-58 is lvm1
662 ls -lL "$node" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}'
666 debug "LVM check: $node is LVM v1 node"
671 if [ ! -x /sbin/lvm ]; then
672 debug "LVM check: no lvm2 tools present to check"
676 /sbin/lvm lvdisplay "$node" > /dev/null 2>&1
678 if [ $rc -gt 127 ]; then
679 # lvdisplay terminated by signal! most likely it segfaulted.
680 die "Unexpected exit from 'lvdisplay $node': $rc - are your lvm tools broken?"
684 debug "LVM check: $node is LVM v2 node"
686 debug "LVM check: $node is not any LVM node"
691 # return true if node is cryptsetup luks encrypted
694 if [ ! -e "$node" ]; then
695 warn "is_luks(): node $node doesn't exist!"
699 local dev dm_name=${node#/dev/mapper/}
700 if [ "$node" = "$dm_name" ]; then
701 debug "is_luks: $node is not device mapper name"
705 dev=$(cryptsetup status $dm_name 2>/dev/null | awk '/device:/{print $2}')
706 cryptsetup isLuks $dev
710 debug "is_luks: $node is cryptsetup luks"
712 debug "is_luks: $node is not cryptsetup luks"
717 # return dependencies MAJOR:MINOR [MAJOR:MINOR] for DM_NAME
718 # TODO: patch `dmsetup export`
721 dmsetup deps $dm_name | sed -e 's/, /:/g;s/^.\+ dependencies[^:]: //;s/[()]//g;'
724 # export info from dmsetup
728 # - /dev/mapper/DM_NAME
734 local maj=${arg%:*} min=${arg#*:}
735 dmsetup -j $maj -m $min export
738 local min=${arg#*dm-}
739 local maj=$(awk '$2 == "device-mapper" {print $1}' /proc/devices)
743 local dm_name=${arg#/dev/mapper/}
744 dmsetup export $dm_name
747 die "dm_export: unexpected $arg"
752 # find dm-multipath modules for $devpath
753 # returns false if $devpath is not dm-multipath
754 find_modules_multipath() {
758 eval $(dm_export "$devpath")
759 if [ -z "$DM_NAME" ]; then
760 die "dm_export failed unexpectedly"
765 # DM_UUID=part1-mpath-36006016002c11800a0aa05fbfae0db11
768 # DM_UUID=mpath-36006016002c11800a0aa05fbfae0db11
769 MPATH_WWID=${DM_UUID##*-}
771 local info=$(multipath -l $MPATH_WWID)
772 if [ -z "$info" ]; then
776 debug "Finding modules for dm-multipath (WWID=$MPATH_WWID)"
778 local dev phydevs=$(echo "$info" | awk '$2 ~ /^[0-9]+:[0-9]+:[0-9]+:[0-9]+$/{printf("/dev/%s\n", $3)}')
779 for dev in $phydevs; do
780 find_modules_for_devpath $dev
781 lvm_ignore_devices="$lvm_ignore_devices $dev"
784 local hw hwhandlers=$(echo "$info" | awk '/hwhandler=1/{sub(/.*hwhandler=1 /, ""); sub(/\]$/, ""); print}')
785 for hw in $hwhandlers; do
789 local target targets=$(echo "$info" | awk '/prio=/{print $2}' | sort -u)
790 for target in $targets; do
791 findmodule "dm-$target"
798 # find dmraid modules for $devpath
799 # returns false if $devpath is not on dmraid
800 find_modules_dmraid() {
803 # get blockdev itself (without partition)
804 # /dev/mapper/sil_ahbgadcbchfc3 -> /dev/mapper/sil_ahbgadcbchfc
805 local blockdev=${devpath%%[0-9]*}
806 local raidname=${blockdev#/dev/mapper/}
809 local dev phydevs=$(dmraid -r -cdevpath,raidname | awk -F, -vv="$raidname" '{if ($2 == v) print $1}')
810 for dev in $phydevs; do
811 find_modules_for_devpath $dev
812 lvm_ignore_devices="$lvm_ignore_devices $dev"
816 if [ $found = 0 ]; then
820 findmodule "dm-mirror"
825 # find modules for $devpath
826 find_modules_luks() {
830 LUKSNAME=${devpath#/dev/mapper/}
831 LUKSDEV=$(cryptsetup status $LUKSNAME 2>/dev/null | awk '/device:/{print $2}')
832 if [ -z "$LUKSDEV" ]; then
833 die "Lost cryptsetup device meanwhile?"
836 findmodule "dm-crypt"
841 find_modules_for_devpath $LUKSDEV
845 # find modules for $devpath
846 find_modules_for_devpath() {
848 if [ -z "$devpath" ]; then
849 die "No argument passed to find_modules_for_devpath() - is your /etc/fstab correct?"
852 # /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3
855 devpath=$(dm_longname "$devpath")
858 debug "Finding modules for device path $devpath"
860 if is_luks "$devpath"; then
861 find_modules_luks "$devpath"
865 if is_yes "`echo "$devpath" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
866 if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ]; then
867 die "root on NFS but /usr/bin/pcidev not found. Please install correct pci-database package and rerun $PROGRAM."
869 if [ ! -f /proc/bus/pci/devices ]; then
870 warn "Remember to add network card modules in /etc/sysconfig/geninitrd, example:"
871 warn "BASICMODULES=\"e1000 ne2k-pci mii 8139too 3c59x\""
874 [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
875 warn "NOTE: Network card(s) module(s) $NFS_ETH_MODULES is for this machine"
876 for m in $NFS_ETH_MODULES; do
883 warn "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel"
884 warn "or you will have problems like init(xx) being child process of swapper(1)."
888 if [[ "$devpath" == /dev/md* ]]; then
889 find_modules_md "$devpath"
893 if is_yes "$USE_MULTIPATH" && [[ "$devpath" == /dev/mapper/* ]]; then
894 if find_modules_multipath "$devpath"; then
900 if is_yes "$USE_DMRAID" && is_yes "$(echo "$devpath" | awk '/^\/dev\/mapper\/(sil|hpt37x|hpt45x|isw|lsi|nvidia|pdc|sil|via|dos)_/ { print "yes"; }')"; then
901 if find_modules_dmraid "$devpath"; then
907 if is_yes "$(echo "$devpath" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')"; then
912 if is_yes "$(echo "$devpath" | awk '/^\/dev\/(hd|ide)/ { print "yes"; }')"; then
913 find_modules_ide "$devpath"
917 if [[ "$devpath" == /dev/rd/* ]]; then
919 rootdev_add="/dev/rd/"
923 if [[ "$devpath" == /dev/ida/* ]]; then
924 findmodule "cpqarray"
925 rootdev_add="/dev/ida/"
929 if [[ "$devpath" == /dev/cciss/* ]]; then
931 rootdev_add="/dev/cciss/"
935 if [[ "$devpath" == /dev/ataraid/* ]]; then
938 ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
939 if [ -n "$ataraidmodules" ]; then
940 # FIXME: think about modules compiled in kernel
941 die "ataraid_hostadapter alias not defined in modprobe.conf! Please set it and run $PROGRAM again."
943 for n in $ataraidmodules; do
946 rootdev_add="/dev/ataraid/"
950 # check to see if we need to set up a loopback filesystem
951 if [[ "$devpath" == /dev/loop* ]]; then
952 die "Sorry, root on loop device isn't supported."
953 # TODO: rewrite for bsp and make nfs ready
954 if [ ! -x /sbin/losetup ]; then
955 die "losetup is missing"
957 key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
958 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`"; then
959 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"
962 line="`awk '/'$key'/ { print $0; }' $fstab`"
963 loopDev="$(echo $line | awk '{print $3}')"
964 loopFs="$(echo $line | awk '{print $4}')"
965 loopFile="$(echo $line | awk '{print $5}')"
967 BASICMODULES="$BASICMODULES -loop"
968 findmodule "-$loopFs"
969 BASICMODULES="$BASICMODULES -${loopFs}"
973 if is_lvm_node "$devpath"; then
976 if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ]; then
977 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."
979 if [ -z "$LVMTOOLSVERSION" ]; then
980 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}')
981 if [ -z "$LVMTOOLSVERSION" ]; then
982 die "Can't determine LVM tools version. Please set LVMTOOLSVERSION and rerun $PROGRAM."
986 local vg=$(/sbin/lvdisplay -c "$node" 2> /dev/null | awk -F":" ' { print $2 } ')
987 VGVOLUMES=$(echo $VGVOLUMES $vg | tr ' ' '\n' | sort -u)
988 local pv=$(/sbin/pvdisplay -c 2>/dev/null | awk -F":" -v vg="$vg" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ')
989 PVDEVICES=$(echo $PVDEVICES $pv | tr ' ' '\n' | sort -u)
991 if [ -n "$PVDEVICES" ]; then
992 for device in $PVDEVICES; do
993 find_modules_for_devpath $device
996 die "I wasn't able to find PV (via lvdisplay and pvdisplay). You can try to set PVDEVICES in /etc/sysconfig/geninitrd."
998 if [ "$LVMTOOLSVERSION" = "2" ]; then
1000 elif [ "$LVMTOOLSVERSION" = "1" ]; then
1002 findmodule "-lvm-mod"
1004 die "LVM version $LVMTOOLSVERSION is not supported yet."
1006 debug "LVM v$LVMTOOLSVERSION enabled"
1012 firmware_install_module() {
1014 local firmware_files="$2"
1016 debug "Adding Firmwares ($firmware_files) to initrd for module $module"
1017 # firmware not yet installed
1018 if [ ! -f "$DESTDIR/lib/firmware/firmware.sh" ]; then
1019 inst_d /lib/firmware
1020 cat << 'EOF' >> "$DESTDIR/lib/firmware/firmware.sh"
1022 echo 1 > /sys$DEVPATH/loading
1023 cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data
1024 echo 0 > /sys$DEVPATH/loading
1027 chmod 755 "$DESTDIR/lib/firmware/firmware.sh"
1030 for firmware in $firmware_files; do
1031 if [ ! -f "/lib/firmware/$firmware" ]; then
1032 die "firmware file /lib/firmware/$firmware doesn't exist."
1034 FIRMWAREDIR=${firmware%/*}
1035 [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR
1036 inst /lib/firmware/$firmware /lib/firmware/$firmware
1041 echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc
1048 for mod in $modules; do
1050 inst_d "/lib/modules/$kernel/$MODULEDIR"
1051 cp -a "/lib/modules/$kernel/$mod" "$DESTDIR/lib/modules/$kernel/$mod"
1052 gunzip "$DESTDIR/lib/modules/$kernel/$mod" 2> /dev/null
1056 modules_add_linuxrc() {
1060 # module path without optional compression
1063 # name of the module
1064 module=${modpath##*/}
1065 module=${module%$modext}
1067 options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}' | xargs)
1069 generic_module=$(echo $module | tr - _)
1070 sleep_var=$(eval echo \$MODULE_${generic_module}_USLEEP)
1071 firmware_var=$(eval echo \$MODULE_${generic_module}_FIRMWARE)
1073 if [ -n "$verbose" ]; then
1075 if [ "$options" ]; then
1076 s="$s with options [$options]"
1078 if [ "$sleep_var" ]; then
1079 s="$s and $sleep_var usleep"
1081 debug "Loading module [$module]$s"
1084 if [ -n "$firmware_var" ]; then
1085 firmware_install_module "$module" "$firmware_var"
1087 firmware_files=$(find_firmware "$module")
1088 if [ -n "$firmware_files" ]; then
1089 for file in $firmware_files; do
1090 firmware_install_module "$module" "$file"
1095 echo "$insmod /lib/modules/$kernel/$modpath $options" | add_linuxrc
1096 if [ -n "$sleep_var" ]; then
1097 echo "usleep $sleep_var" | add_linuxrc
1102 find_modules_suspend() {
1103 if [ ! -x /usr/${_lib}/suspend/resume -a ! -x /usr/sbin/resume ]; then
1104 die "/usr/${_lib}/suspend/resume is missing!"
1106 resume_dev="$(awk '/^resume device =/ { print $4 } ' /etc/suspend.conf)"
1108 local vgvolumes=$VGVOLUMES
1109 find_modules_for_devpath $resume_dev
1111 if [ "$VGVOLUMES" != "$vgvolumes" ]; then
1112 # save our VG to be able to differenciate between rootfs VG
1113 SUSPENDVG=$VGVOLUMES
1114 VGVOLUMES=$vgvolumes
1115 debug "suspend device is on LVM"
1119 initrd_gen_suspend() {
1120 mknod $DESTDIR/dev/snapshot c 10 231
1121 mkdir -p $DESTDIR${resume_dev%/*}
1122 inst $resume_dev $resume_dev
1124 inst /etc/suspend.conf /etc/suspend.conf
1125 if [ -x /usr/${_lib}/suspend/resume ]; then
1126 inst_exec /usr/${_lib}/suspend/resume /bin/resume
1128 inst_exec /usr/sbin/resume /bin/resume
1131 add_linuxrc <<-'EOF'
1133 for arg in $CMDLINE; do
1134 if [ "${arg##resume=}" != "${arg}" ]; then
1138 if [ "$resume" = "yes" ]; then
1144 initrd_gen_tuxonice() {
1146 add_linuxrc <<-'EOF'
1148 for arg in $CMDLINE; do
1149 if [ "${arg##resume=}" != "${arg}" -o "${arg##resume2=}" != "${arg}" ]; then
1153 if [ "$resume" = "yes" ]; then
1154 [ -e /proc/suspend2/do_resume ] && echo > /proc/suspend2/do_resume
1155 [ -e /sys/power/suspend2/do_resume ] && echo > /sys/power/suspend2/do_resume
1156 [ -e /sys/power/tuxonice/do_resume ] && echo > /sys/power/tuxonice/do_resume
1162 debug "initrd_gen_v86d"
1163 mknod $DESTDIR/dev/mem c 1 1
1164 mknod $DESTDIR/dev/tty1 c 4 1
1166 inst_exec /sbin/v86d /sbin
1170 debug "Setting up udev..."
1171 inst_d /sbin /etc/udev
1173 if [ ! -x /sbin/initrd-udevd ]; then
1174 die "/sbin/initrd-udevd not present"
1177 inst_exec /sbin/initrd-udevd /sbin/udevd
1178 inst /etc/udev/udev.conf /etc/udev/udev.conf
1182 add_linuxrc <<-'EOF'
1184 /sbin/udevd --daemon
1187 inst_exec /sbin/initrd-udevadm /sbin/udevadm
1188 ln -s udevadm $DESTDIR/sbin/udevsettle
1189 ln -s udevadm $DESTDIR/sbin/udevtrigger
1190 add_linuxrc <<-'EOF'
1195 busybox_applet killall
1196 add_linuxrc <<-'EOF'
1201 initrd_gen_multipath() {
1202 inst_d /sbin /lib/udev /etc/multipath
1203 inst_exec /sbin/kpartx /sbin
1204 inst_exec /sbin/multipath /sbin
1206 inst_exec /sbin/scsi_id /lib/udev
1207 inst_exec /sbin/mpath* /sbin
1208 egrep -v '^([ ]*$|#)' /etc/multipath.conf > $DESTDIR/etc/multipath.conf
1210 if [ -f /etc/multipath/bindings ]; then
1211 egrep -v '^([ ]*$|#)' /etc/multipath/bindings > $DESTDIR/etc/multipath/bindings
1213 touch $DESTDIR/etc/multipath/bindings
1220 echo "export MPATH_WWID=$MPATH_WWID" | add_linuxrc
1221 add_linuxrc <<-'EOF'
1222 # parse mpath_wwid= from kernel commandline
1223 for arg in $CMDLINE; do
1224 if [ "${arg##mpath_wwid=}" != "${arg}" ]; then
1225 MPATH_WWID=${arg##mpath_wwid=}
1226 if [ "$MPATH_WWID" = "*" ]; then
1227 # '*' would mean activate all WWID-s
1229 echo "multipath: Activating all WWID-s"
1231 echo "multipath: Activating WWID=$WWID"
1237 /sbin/multipath -v 0 $MPATH_WWID
1239 for a in /dev/mapper/*; do
1240 [ $a = /dev/mapper/control ] && continue
1241 /sbin/kpartx -a -p p $a
1247 initrd_gen_dmraid() {
1248 if [ ! -x /sbin/dmraid-initrd ]; then
1249 die "/sbin/dmraid-initrd is missing!"
1253 inst_exec /sbin/dmraid-initrd /sbin/dmraid
1259 # 2 secs was enough for my system to initialize. but really this is udev issue?
1261 : 'Activating Device-Mapper RAID(s)'
1269 [ "$1" = "/dev/urandom" -o "$1" = "/dev/hw_random" -o "$1" = "/dev/random" ]
1272 # produce cryptsetup from $name from /etc/crypttab
1277 # copy from /etc/rc.d/init.d/cryptsetup
1278 local dst src key opt mode owner
1280 while read dst src key opt; do
1281 [ -z "$dst" -o "${dst#\#}" != "$dst" ] && continue
1282 [ "$dst" != "$LUKSNAME" ] && continue
1284 if [ -n "$key" -a "x$key" != "xnone" ]; then
1285 if test -e "$key" ; then
1286 mode=$(LC_ALL=C ls -l "$key" | cut -c 5-10)
1287 owner=$(LC_ALL=C ls -l $key | awk '{ print $3 }')
1288 if [ "$mode" != "------" ] && ! key_is_random "$key"; then
1289 die "INSECURE MODE FOR $key"
1291 if [ "$owner" != root ]; then
1292 die "INSECURE OWNER FOR $key"
1295 die "Key file for $dst not found"
1301 if /sbin/cryptsetup isLuks "$src" 2>/dev/null; then
1302 if key_is_random "$key"; then
1303 die "$dst: LUKS requires non-random key, skipping"
1305 if [ -n "$opt" ]; then
1306 warn "$dst: options are invalid for LUKS partitions, ignoring them"
1308 echo "/sbin/cryptsetup ${key:+-d $key} luksOpen '$src' '$dst' <&1" | add_linuxrc
1310 die "$dst: only LUKS encryption supported"
1312 done < /etc/crypttab
1316 if [ ! -x /sbin/cryptsetup-initrd ]; then
1317 die "/sbin/cryptsetup-initrd is missing!"
1321 inst_exec /sbin/cryptsetup-initrd /sbin/cryptsetup
1327 luks_crypttab $LUKSNAME $LUKSDEV
1330 initrd_gen_bootsplash() {
1333 debug "Generating bootsplash"
1335 if [ ! -x /bin/splash.bin ]; then
1336 warn "Failed to execute /bin/splash.bin. Is bootsplash package installed?"
1340 if [ -r /etc/sysconfig/bootsplash ]; then
1341 . /etc/sysconfig/bootsplash
1344 if [ -z "$THEME" ]; then
1345 warn "Please configure your /etc/sysconfig/bootsplash first."
1346 warn "Generating bootsplashes skipped."
1350 if [ -z "$BOOT_SPLASH_RESOLUTIONS" ]; then
1351 warn "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash."
1352 warn "Not adding bootsplash to initrd."
1355 for res in $BOOT_SPLASH_RESOLUTIONS; do
1356 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
1357 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
1358 debug "Added $res $THEME theme to initrd."
1360 warn "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped"
1365 initrd_gen_fbsplash() {
1366 debug "Generating fbsplash"
1368 if [ ! -x /usr/bin/splash_geninitramfs -a ! -x /usr/sbin/splash_geninitramfs ]; then
1369 warn "Failed to find splash_geninitramfs. Is splashutils package installed?"
1372 splash_geninitramfs_bin=/usr/sbin/splash_geninitramfs
1373 [ -f /usr/bin/splash_geninitramfs ] && splash_geninitramfs_bin=/usr/bin/splash_geninitramfs
1375 if [ -r /etc/sysconfig/fbsplash ]; then
1376 . /etc/sysconfig/fbsplash
1379 if [ -z "$SPLASH_THEME" ]; then
1380 warn "Please configure your /etc/sysconfig/fbsplash first."
1381 warn "Generating fbsplashes skipped."
1385 if [ -z "$FB_SPLASH_RESOLUTIONS" ]; then
1386 warn "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/fbsplash."
1387 warn "Not adding fbsplash to initramfs."
1391 for res in $FB_SPLASH_RESOLUTIONS; do
1392 if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then
1393 $splash_geninitramfs_bin -c $DESTDIR -r $res $SPLASH_THEME && \
1394 debug "Added $res $SPLASH_THEME theme to initramfs."
1396 warn "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped"
1401 initrd_gen_fbcondecor() {
1402 debug "Generating fbcondecor"
1404 if [ ! -x /usr/bin/splash_geninitramfs -a ! -x /usr/sbin/splash_geninitramfs ]; then
1405 warn "Failed to find splash_geninitramfs. Is splashutils package installed?"
1408 splash_geninitramfs_bin=/usr/sbin/splash_geninitramfs
1409 [ -f /usr/bin/splash_geninitramfs ] && splash_geninitramfs_bin=/usr/bin/splash_geninitramfs
1411 if [ -r /etc/sysconfig/splash ]; then
1412 . /etc/sysconfig/splash
1415 if [ -z "$SPLASH_THEME" ]; then
1416 warn "Please configure your /etc/sysconfig/splash first."
1417 warn "Generating of splashes skipped."
1421 if [ -z "$FB_SPLASH_RESOLUTIONS" ]; then
1422 warn "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/splash."
1423 warn "Not adding fbcondecor to initramfs."
1427 for res in $FB_SPLASH_RESOLUTIONS; do
1428 if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then
1429 $splash_geninitramfs_bin -c $DESTDIR -r $res $SPLASH_THEME && \
1430 debug "Added $res $SPLASH_THEME theme to initramfs."
1432 warn "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped"
1437 # Generates /dev nodes based on /proc/partitions information.
1438 # Needs /proc mounted.
1439 # Can be called multiple times.
1440 initrd_gen_devices() {
1441 if is_yes "$proc_partitions"; then
1447 add_linuxrc <<-'EOF'
1448 : 'Making device nodes'
1449 cat /proc/partitions | (
1450 # ignore first two lines: header, empty line
1453 while read major minor blocks dev rest; do
1456 [ -e $node ] || mknod $node b $major $minor
1463 debug "Setting up mdadm..."
1465 if [ ! -x /sbin/mdadm -o ! -x /sbin/initrd-mdassemble ]; then
1466 die "/sbin/mdadm or /sbin/initrd-mdassemble is missing!"
1469 inst_exec /sbin/initrd-mdassemble /bin/mdassemble
1472 dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf | xargs)
1473 if [ "$dev_list_extra" = "partitions" ]; then
1474 # FIXME: handle this case (see man mdadm.conf)
1475 echo "DEVICE partitions" >> "$DESTDIR/etc/mdadm.conf"
1478 for ex_dev in $dev_list_extra; do
1479 echo "DEVICE $ex_dev" >> "$DESTDIR/etc/mdadm.conf"
1483 for nr in `seq 1 $rootdev_nr`; do
1484 eval cr_rootdev="\$rootdev${nr}"
1485 eval cr_dev_list="\$dev_list${nr}"
1486 debug echo "Setting up array ($cr_rootdev = $cr_dev_list)"
1488 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
1490 echo "DEVICE $cr_dev_list" >> "$DESTDIR/etc/mdadm.conf"
1491 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
1492 cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev | awk ' { gsub(/spares=[0-9]+/, "", $0); print $0; }')
1493 if [ -n "$cr_md_conf" ]; then
1494 echo "$cr_md_conf" >> "$DESTDIR/etc/mdadm.conf"
1496 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$DESTDIR/etc/mdadm.conf"
1499 for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
1500 # mkdir in case of devfs name
1501 inst_d $(dirname $f)
1502 [ -e "$DESTDIR/$f" ] && continue
1503 # this works fine with and without devfs
1508 echo "mdassemble" | add_linuxrc
1510 # needed to determine md-version
1511 if [ "$do_md0" -eq 1 ]; then
1512 mknod $DESTDIR/dev/md0 b 9 0
1517 # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
1518 # have problems like init(XX) being child process of swapper(1).
1519 debug "Adding rootfs on NFS support to initrd (dhcp)"
1520 mknod "$DESTDIR/dev/urandom" c 1 9
1521 mkdir "$DESTDIR/newroot"
1522 add_linuxrc <<-'EOF'
1523 ifconfig lo 127.0.0.1 up
1524 route add -net 127.0.0.0 mask 255.0.0.0 lo
1526 udhcpc -i eth0 -f -q -s /bin/setdhcp
1530 [ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
1531 exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
1534 cat <<-'EOF' > "$DESTDIR/bin/setdhcp"
1536 [ "$1" != "bound" ] && exit
1537 [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
1538 [ -n "$subnet" ] && NETMASK="netmask $subnet"
1539 ifconfig $interface $ip $BROADCAST $NETMASK up
1540 if [ -n "$router" ]; then
1541 for r in $router; do
1542 route add default gw $r dev $interface
1546 for o in $CMDLINE; do
1549 rootpath=${o#nfsroot=}
1554 if [ -n "$rootpath" ]; then
1555 mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot
1557 echo "Missing rootpath in what DHCP server sent to us. Failing..."
1558 echo "All seen variables are listed below:"
1563 chmod 755 "$DESTDIR/bin/setdhcp"
1567 debug "Adding LVM support to initrd"
1568 inst_d /tmp /newroot
1569 inst_exec /sbin/initrd-lvm /bin/lvm.static
1571 # always make /dev on tmpfs for LVM2
1572 if [ "$LVMTOOLSVERSION" = "2" ]; then
1576 if ! is_yes "$dev_mounted"; then
1578 mknod $DESTDIR/dev/mapper/control c 10 63
1579 for device in $PVDEVICES; do
1580 # if LVM on RAID then device might be copied already in gen_md
1581 [ -e "$DESTDIR/dev/$(basename $device)" ] && continue
1587 if [ "$LVMTOOLSVERSION" = "1" ]; then
1590 for vg in $VGVOLUMES; do
1591 lvm vgchange -T -a y $vg
1595 echo "cat /etc/lvm.conf > /tmp/lvm.conf" | add_linuxrc
1596 echo "global {" > "$DESTDIR/etc/lvm.conf"
1597 echo " locking_type = 0" >> "$DESTDIR/etc/lvm.conf"
1598 echo " locking_dir = \"/tmp\"" >> "$DESTDIR/etc/lvm.conf"
1599 echo "}" >> "$DESTDIR/etc/lvm.conf"
1600 echo "devices {" >> "$DESTDIR/etc/lvm.conf"
1601 echo " sysfs_scan=0" >> "$DESTDIR/etc/lvm.conf"
1602 if is_yes "$have_md"; then
1603 echo " md_component_detection = 1" >> "$DESTDIR/etc/lvm.conf"
1605 if is_yes "$have_dmraid" || is_yes "$have_multipath"; then
1606 echo ' types = [ "device-mapper", 254 ]' >> "$DESTDIR/etc/lvm.conf"
1608 if [ "$lvm_ignore_devices" ]; then
1609 # TODO: think of merging with lvm dumpconfig output
1610 echo ' filter = [' >> "$DESTDIR/etc/lvm.conf"
1612 for dev in $lvm_ignore_devices; do
1613 debug "LVM v2: ignore device $dev"
1614 printf ' "r|^%s.*|",\n' $dev
1615 done >> "$DESTDIR/etc/lvm.conf"
1616 echo ']' >> "$DESTDIR/etc/lvm.conf"
1618 # XXX filter= must be on one line!
1619 lvm dumpconfig | awk '/filter=/' >> "$DESTDIR/etc/lvm.conf"
1620 echo "}" >> "$DESTDIR/etc/lvm.conf"
1625 export ROOTDEV=$rootdev
1626 export ROOTVG="$VGVOLUMES"
1627 export SUSPENDVG=$SUSPENDVG
1629 add_linuxrc <<-'EOF'
1630 # parse rootdev from kernel commandline if it begins with /
1633 if [ "$ROOT" != "$ROOTDEV" ]; then
1635 echo "LVM: Using 'root=$ROOTDEV' from kernel commandline"
1636 local tmp=${ROOTDEV#/dev/}
1637 if [ "$tmp" != "$ROOTDEV" ]; then
1639 echo "LVM: Using Volume Group '$ROOTVG' for rootfs"
1646 if [ "$SUSPENDVG" = "$ROOTVG" ]; then
1647 export VGVOLUMES="$ROOTVG"
1649 export VGVOLUMES="$SUSPENDVG $ROOTVG"
1652 # disable noise from LVM accessing devices that aren't ready.
1653 read printk < /proc/sys/kernel/printk
1654 if [ ! "$DEBUGINITRD" ]; then
1655 echo 0 > /proc/sys/kernel/printk
1658 export LVM_SYSTEM_DIR=/tmp
1659 : 'Scanning for Volume Groups'
1660 lvm.static vgscan --mknodes --ignorelockingfailure 2>/dev/null
1662 : 'Activating Volume Groups'
1663 for vol in $VGVOLUMES; do
1664 lvm.static vgchange --ignorelockingfailure -a y $vol 2>/dev/null
1667 echo "$printk" > /proc/sys/kernel/printk
1669 # Find out major/minor
1670 attrs="$(lvm.static lvdisplay --ignorelockingfailure -c $ROOTDEV 2>/dev/null)"
1671 if [ "$attrs" ]; then
1672 majmin="${attrs#*$ROOTDEV*:*:*:*:*:*:*:*:*:*:*:*}"
1673 if [ "$majmin" != "$attrs" ]; then
1674 major="${majmin%:*}"
1675 minor="${majmin#*:}"
1679 if [ "$major" -a "$minor" ]; then
1681 echo $((256 * $major + $minor)) > /proc/sys/kernel/real-root-dev
1683 echo 2>&1 "Error figuring out real root device for $ROOTDEV!"
1684 echo 2>&1 "System will not most likely boot up! So dropping you to a shell!"
1694 debug "Adding BLKID support to initrd"
1695 inst_exec /sbin/initrd-blkid /bin/blkid
1697 add_linuxrc <<-'EOF'
1698 # if built with blkid change ROOT=LABEL=something into ROOT=/dev/somethingelse -
1700 if [ "${ROOT##LABEL=}" != "${ROOT}" -o "${ROOT##UUID=}" != "${ROOT}" ]; then
1701 ROOT="$(/bin/blkid -t $ROOT -o device -l)"
1706 initrd_gen_setrootdev() {
1707 debug "Adding rootfs finding based on kernel cmdline root= option support."
1708 add_linuxrc <<-'EOF'
1709 if [ "${ROOT##/dev/}" != "${ROOT}" ]; then
1710 rootnr="$(busybox awk -v rootnode="${ROOT##/dev/}" '$4 == rootnode { print 256 * $1 + $2 }' /proc/partitions)"
1711 if [ -n "$rootnr" ]; then
1712 echo "$rootnr" > /proc/sys/kernel/real-root-dev
1719 if [ "$(id -u)" != 0 ]; then
1720 die "You need to be root to generate initrd"
1723 if [ -f /etc/udev/udev.conf -a -x /sbin/initrd-udevd ]; then
1725 . /etc/udev/udev.conf
1728 if [ -x /sbin/dmraid-initrd ]; then
1732 if [ -x /sbin/cryptsetup ]; then
1736 if [ -x /sbin/multipath ]; then
1740 if [ -x /sbin/initrd-blkid ]; then
1744 if [ -r /etc/sysconfig/geninitrd ]; then
1745 . /etc/sysconfig/geninitrd
1748 if [ ! -x /bin/initrd-busybox ]; then
1749 die "/bin/initrd-busybox is missing!"
1752 # backwards compatible
1753 if [ "$USE_SUSPEND2" ]; then
1754 USE_TUXONICE=$USE_SUSPEND2
1755 warn "USE_SUSPEND2 is deprecated, use USE_TUXONICE now instead."
1758 while [ $# -gt 0 ]; do
1768 modulefile=${1#--modules-conf=}
1774 --use-raidstart|--with-raidstart)
1777 --without-raidstart)
1780 --use-insmod-static|--with-insmod-static)
1783 --without-insmod-static)
1789 --without-bootsplash)
1801 --without-fbcondecor)
1810 --with-suspend2 | --with-tuxonice)
1813 --without-suspend2 | --without-tuxonice)
1816 --lvmtoolsversion=|--lvmversion=)
1817 LVMTOOLSVERSION=${1#--lvmtoolsversion=}
1818 LVMTOOLSVERSION=${1#--lvmversion=}
1820 --lvmtoolsversion|--lvmversion)
1833 --without-multipath)
1843 BASICMODULES="$BASICMODULES ${1#--with=}"
1846 BASICMODULES="$BASICMODULES $2"
1850 echo "$PROGRAM: version $VERSION"
1866 PREMODS="$PREMODS ${1#--preload=}"
1869 PREMODS="$PREMODS $2"
1873 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
1877 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
1882 INITRDFS=${1#--initrdfs=}
1895 if [ -z "$target" ]; then
1897 elif [ -z "$kernel" ]; then
1908 if [ -z "$target" -o -z "$kernel" ]; then
1912 if [ ! -f /boot/vmlinuz-"$kernel" ]; then
1913 warn "/boot/vmlinuz-$kernel doesn't exist, is your /boot mounted?"
1916 pack_version=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d",$1,$2)}')
1917 pack_version_long=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}')
1919 if [ -z "$INITRDFS" ]; then
1920 if [ -z "$FS" ]; then
1922 if [ "$pack_version" -ge "002005" ]; then
1923 INITRDFS="initramfs"
1928 warn "Warning: FS configuration options is obsoleted. Use INITRDFS instead"
1933 if [ "$pack_version" -lt "002006" ]; then
1938 if [ "$pack_version" -ge "002005" ]; then
1943 if is_yes "$USEINSMODSTATIC"; then
1944 insmod="insmod.static"
1945 INSMOD="/sbin/insmod.static"
1946 if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ]; then
1947 INSMOD="/sbin/insmod.static.modutils"
1949 if [ ! -f "$INSMOD" ]; then
1950 die "insmod.static requested but /sbin/insmod.static not found!"
1956 if [ ! -x /sbin/mke2fs ]; then
1957 die "/sbin/mke2fs is missing"
1961 if [ ! -x /sbin/genromfs ]; then
1962 die "/sbin/genromfs is missing"
1966 if [ ! -x /sbin/mkcramfs ]; then
1967 die "/sbin/mkcramfs is missing"
1971 if [ ! -x /bin/cpio ]; then
1972 die "/bin/cpio is missing"
1974 if [ ! -x /usr/bin/find ]; then
1975 die "/usr/bin/find is missing"
1979 die "Filesystem $INITRDFS on initrd is not supported"
1983 if [ -L "$target" ]; then
1984 target=$(readlink -f "$target")
1987 if [ -n "$img_vers" ]; then
1988 target="$target-$kernel"
1991 if [ -z "$force" -a -f "$target" ]; then
1992 die "$target already exists."
1995 if [ ! -d "/lib/modules/$kernel" ]; then
1996 die "/lib/modules/$kernel is not a directory."
1999 if [ "$INITRDFS" != "initramfs" ]; then
2000 if is_yes "$FB_SPLASH"; then
2001 warn "Using fbsplash requires INITRDFS=initramfs; skipping fbsplash generation"
2004 if is_yes "$FB_CON_DECOR"; then
2005 warn "Using fbcondecor requires INITRDFS=initramfs; skipping fbcondecor generation"
2010 if is_yes "$USE_SUSPEND" && is_yes "$USE_TUXONICE"; then
2011 warn "Tuxonice and mainline suspend are exclusive!"
2014 if is_yes "$FB_SPLASH" && is_yes "$BOOT_SPLASH"; then
2015 warn "bootsplash and fbsplash are exclusive!"
2018 if [ ! -f /proc/mounts ]; then
2019 warn "/proc filesystem not mounted, may cause wrong results or failure."
2022 if [ -d /usr/lib64 ]; then
2027 debug "Using libdir: $_lib"
2031 for n in $PREMODS; do
2035 if [ "$FBMODULE" ]; then
2036 findmodule "$FBMODULE"
2039 # allow forcing loading SCSI and/or IDE modules
2040 if is_yes "$ADDSCSI"; then
2044 if is_yes "$ADDIDE"; then
2048 if is_yes "$USE_SUSPEND"; then
2049 find_modules_suspend
2052 find_root "$fstab" || exit
2053 debug "Using $rootdev as device for rootfs"
2055 find_modules_for_devpath "$rootdev"
2056 [ -n "$rootdev_add" ] && find_modules_for_devpath "$rootdev_add"
2058 findmodule "-$rootFs"
2060 for n in $BASICMODULES; do
2064 if is_yes "$USE_TUXONICE"; then
2068 if is_yes "$FB_SPLASH"; then
2072 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
2073 debug "No modules are needed -- not building initrd image."
2077 DESTDIR=$(mktemp -d -t initrd.XXXXXX) || die "mktemp failed"
2078 RCFILE="$DESTDIR/linuxrc"
2080 chmod a+rx "$RCFILE"
2081 ln -s linuxrc $DESTDIR/init
2083 # create dirs that we really need
2084 inst_d /{lib,bin,etc,dev{,/pts,/shm},loopfs,var,proc,sys}
2086 modules_install "$MODULES"
2088 # mknod'ing the devices instead of copying them works both with and
2090 mknod "$DESTDIR/dev/console" c 5 1
2091 mknod "$DESTDIR/dev/null" c 1 3
2092 mknod "$DESTDIR/dev/zero" c 1 5
2094 inst_exec /bin/initrd-busybox /bin/initrd-busybox
2095 ln -s initrd-busybox $DESTDIR/bin/sh
2096 ln -s initrd-busybox $DESTDIR/bin/busybox # for older busyboxes who had /bin/busybox as EXEPATH
2098 if is_yes "$USEINSMODSTATIC"; then
2099 inst_exec "$INSMOD" /bin/insmod.static
2104 # initrd generated by:
2109 add_linuxrc <<-'EOF'
2110 read CMDLINE < /proc/cmdline; export CMDLINE
2112 for arg in $CMDLINE; do
2113 if [ "${arg}" = "debuginitrd" ]; then
2116 if [ "${arg##debuginitrd=}" != "${arg}" ]; then
2117 DEBUGINITRD=${arg##debuginitrd=}
2119 if [ "${arg##root=}" != "${arg}" ]; then
2124 # make debugshell() invoke subshell if $DEBUGINITRD=sh
2125 if [ "$DEBUGINITRD" = "sh" ]; then
2128 if is_yes "$RUN_SULOGIN_ON_ERR"; then
2129 add_linuxrc <<-'EOF'
2130 echo "debug shell disabled by /etc/sysconfig/system:RUN_SULOGIN_ON_ERR setting"
2133 add_linuxrc <<-'EOF'
2137 add_linuxrc <<-'EOF'
2145 if [ "$DEBUGINITRD" ]; then
2150 modules_add_linuxrc $MODULES
2152 # TODO: rewrite for busybox
2153 #if [ -n "$loopDev" ]; then
2154 # if [ ! -d /initrd ]; then
2158 # cp -a "$loopDev" "$DESTDIR/dev"
2159 # cp -a "$rootdev" "$DESTDIR/dev"
2160 # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
2161 # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
2162 # echo "echo Setting up loopback device $rootdev" >> $RCFILE
2163 # echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
2166 if is_yes "$USE_UDEV"; then
2170 if is_yes "$USE_TUXONICE"; then
2174 if is_yes "$need_v86d"; then
2178 if is_yes "$have_luks"; then
2182 if is_yes "$have_dmraid"; then
2186 if is_yes "$have_multipath"; then
2187 initrd_gen_multipath
2190 if is_yes "$USE_BLKID"; then
2194 if is_yes "$have_nfs"; then
2196 elif is_yes "$USERAIDSTART" && is_yes "$have_md"; then
2198 if is_yes "$have_lvm"; then
2201 initrd_gen_setrootdev
2203 elif is_yes "$have_lvm"; then
2206 initrd_gen_setrootdev
2209 if is_yes "$USE_SUSPEND"; then
2213 # additional devs always needed
2214 [ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev
2216 if [ "$INITRDFS" = "initramfs" ]; then
2218 if [ "$rootdev" = "/dev/nfs" ]; then
2219 echo "rootfs on NFS root=/dev/nfs"
2221 [ ! -e "$DESTDIR/$rootdev" ] && inst $rootdev $rootdev
2223 # Parsing root parameter
2224 # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
2225 add_linuxrc <<-'EOF'
2226 device=/dev/no_partition_found
2227 eval "$(busybox awk -v c="$ROOT" '
2229 num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
2230 num_pattern = "[0-9a-f]" num_pattern_short;
2231 dev_pattern = "[hms][a-z][a-z]([0-9])+";
2232 partition = "no_partition_found";
2236 if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
2237 if (c ~ "^" num_pattern "$") {
2238 maj = sprintf("%s",substr(c,1,2));
2239 min = sprintf("%s",substr(c,3));
2241 if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
2242 if (c ~ "^" dev_pattern "$") partition = c;
2245 $4 ~ partition { maj = $1; min = $2; }
2246 $1 ~ maj && $2 ~ min { partition = $4; }
2249 print sprintf("device=/dev/%s\nmaj=%s\nmin=%s",
2250 partition, maj, min);
2252 ' /proc/partitions)"
2253 if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
2254 mknod $device b $maj $min
2263 add_linuxrc <<-'EOF'
2264 if [ "$device" = '/dev/no_partition_found' ]; then
2268 mount -t $rootfs -r $device /newroot
2269 init="$(echo "$CMDLINE" | busybox awk '/init=\// { gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')"
2270 if [ -z "$init" -o ! -x "/newroot$init" ]; then
2276 busybox_applet switch_root
2277 add_linuxrc <<-'EOF'
2278 exec switch_root /newroot $init
2280 echo "Error! initramfs should not reach this place."
2281 echo "It probably means you've got old version of busybox, with broken"
2282 echo "initramfs support. Trying to boot anyway, but won't promise anything."
2284 exec chroot /newroot $init
2286 echo "Failed to chroot!"
2288 # we need /init being real file, not symlink, otherwise the initramfs will
2289 # not be ran by pid 1 which is required for switch_root
2290 mv $DESTDIR/linuxrc $DESTDIR/init
2291 ln -s init $DESTDIR/linuxrc
2293 # other than initramfs
2297 if is_yes "$FB_SPLASH"; then
2301 if is_yes "$FB_CON_DECOR"; then
2302 initrd_gen_fbcondecor
2305 IMAGE=$(mktemp -t initrd.img-XXXXXX) || die "mktemp failed"
2307 debug "Creating $INITRDFS image $IMAGE"
2310 IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}')
2311 debug "ext2 image size: $IMAGESIZE ($DESTDIR)"
2312 if [ "$IMAGESIZE" -gt 4096 ]; then
2313 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
2316 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
2317 mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
2318 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
2320 local tmpmnt=$(mktemp -d -t initrd.mnt-XXXXXX)
2321 debug "Mounting ext2 image $IMAGE to $tmpmnt"
2322 mount -o loop -t ext2 "$IMAGE" "$tmpmnt"
2323 # We don't need this directory, so let's save space
2324 rm -rf "$tmpmnt"/lost+found
2326 debug "Copy recursively $DESTDIR -> $tmpmnt"
2327 cp -a $DESTDIR/* $tmpmnt
2333 genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD initrd for kernel $kernel"
2334 IMAGESIZE=$(stat -c %s $IMAGE | awk '{print int((($1/1024)+1023)/1024)*1024}')
2335 debug "Image size for romfs: ${IMAGESIZE}KiB ($IMAGE)"
2336 if [ "$IMAGESIZE" -gt 4096 ]; then
2337 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
2341 mkcramfs "$DESTDIR" "$IMAGE"
2344 (cd $DESTDIR; find . | cpio --quiet -H newc -o > "$IMAGE")
2347 echo "Filesystem $INITRDFS not supported by $PROGRAM";
2350 if is_yes "$COMPRESS"; then
2351 tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
2352 debug "Compressing $target"
2353 gzip -9 < "$IMAGE" > "$tmp"
2354 mv -f "$tmp" "$target"
2356 cp -a "$IMAGE" "$target"
2359 # XXX. check if bootsplash can output data to tmp dir not directly to initramfs image.
2360 if is_yes "$BOOT_SPLASH"; then
2361 initrd_gen_bootsplash "$target"
2364 rm -rf "$DESTDIR" "$IMAGE"
2366 # vim:ts=4:sw=4:noet:fdm=marker