]> git.pld-linux.org Git - projects/geninitrd.git/commitdiff
- setup modules _after_ parsing command-line args
authorElan Ruusamäe <glen@pld-linux.org>
Thu, 2 Apr 2009 22:18:29 +0000 (22:18 +0000)
committerElan Ruusamäe <glen@pld-linux.org>
Thu, 2 Apr 2009 22:18:29 +0000 (22:18 +0000)
svn-id: @10280

geninitrd
mod-blkid.sh
mod-dmraid.sh
mod-luks.sh
mod-lvm.sh
mod-md.sh
mod-multipath.sh
mod-udev.sh

index 1d1f314dac90976f775a3db8d72c70488b5c83fe..a33787911571100180a742eedf4987320fef965f 100755 (executable)
--- a/geninitrd
+++ b/geninitrd
@@ -15,6 +15,8 @@ PROGRAM=${0##*/}
 . /lib/geninitrd/functions
 . /etc/sysconfig/system
 
+# list of geninitrd modules which need setup routine after commandline args parsing
+GENINITRD_MODS=""
 COMPRESS=yes
 USE_SUSPEND=yes
 USE_TUXONICE=no
@@ -114,6 +116,31 @@ find_tool() {
        return 1
 }
 
+# loads geninitrd modules
+geninitrd_load_mods() {
+       local mod
+       for mod in "$@"; do
+               if [ ! -f /lib/geninitrd/mod-$mod.sh ]; then
+                       die "$mod geninitrd module can't be loaded"
+               fi
+               . /lib/geninitrd/mod-$mod.sh
+
+               if type setup_mod_$mod > /dev/null; then
+                       # add to list which need init
+                       GENINITRD_MODS="$GENINITRD_MODS $mod"
+               fi
+       done
+}
+
+# setup geninitrd modules
+geninitrd_setup_mods() {
+       local mod
+
+       for mod in $GENINITRD_MODS; do
+               eval setup_mod_$mod
+       done
+}
+
 # append text to /linuxrc
 # takes STDIN as input
 add_linuxrc() {
@@ -1022,27 +1049,12 @@ if [ "$(id -u)" != 0 ]; then
        die "You need to be root to generate initrd"
 fi
 
-# IDE addon
-. /lib/geninitrd/mod-ide.sh
-# cryptsetup luks addon
-. /lib/geninitrd/mod-luks.sh
-# dm-multipath addon
-. /lib/geninitrd/mod-multipath.sh
-# dmraid addon
-. /lib/geninitrd/mod-dmraid.sh
-# LVM addon
-. /lib/geninitrd/mod-lvm.sh
-# md addon
-. /lib/geninitrd/mod-md.sh
-# blkid addon
-. /lib/geninitrd/mod-blkid.sh
-# udev addon
-. /lib/geninitrd/mod-udev.sh
-
 if [ -r /etc/sysconfig/geninitrd ]; then
        . /etc/sysconfig/geninitrd
 fi
 
+geninitrd_load_mods ide luks multipath dmraid lvm md blkid udev
+
 # backwards compatible
 if [ "$USE_SUSPEND2" ]; then
        USE_TUXONICE=$USE_SUSPEND2
@@ -1160,11 +1172,11 @@ while [ $# -gt 0 ]; do
                shift
                ;;
        --fs=*)
-               warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
+               warn "--fs option is obsoleted. Use --initrdfs instead"
                INITRDFS=${1#--fs=}
                ;;
        --fs)
-               warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
+               warn "--fs option is obsoleted. Use --initrdfs instead"
                INITRDFS=$2
                shift
                ;;
@@ -1201,13 +1213,29 @@ if [ -z "$target" -o -z "$kernel" ]; then
        exit 1
 fi
 
-if [ ! -f /boot/vmlinuz-"$kernel" ]; then
-       warn "/boot/vmlinuz-$kernel doesn't exist, is your /boot mounted?"
+if [ -d /usr/lib64 ]; then
+       _lib=lib64
+else
+       _lib=lib
 fi
 
+initrd_dir=/usr/$_lib/initrd
 kernel_version=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d",$1,$2)}')
 kernel_version_long=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}')
 
+debug "# $RCSID"
+debug "Using _lib: $_lib"
+debug "Using initrd_dir: $initrd_dir"
+
+busybox=$(find_tool $initrd_dir/initrd-busybox /bin/initrd-busybox) || die "Couldn't find busybox suitable for initrd"
+
+# we setup mods after parsing command line args
+geninitrd_setup_mods
+
+if [ ! -f /boot/vmlinuz-"$kernel" ]; then
+       warn "/boot/vmlinuz-$kernel doesn't exist, is your /boot mounted?"
+fi
+
 if [ -z "$INITRDFS" ]; then
        if [ -z "$FS" ]; then
                # default value
@@ -1294,17 +1322,6 @@ if [ ! -f /proc/mounts ]; then
        warn "/proc filesystem not mounted, may cause wrong results or failure."
 fi
 
-if [ -d /usr/lib64 ]; then
-       _lib=lib64
-else
-       _lib=lib
-fi
-
-initrd_dir=/usr/$_lib/initrd
-debug "# $RCSID"
-debug "Using _lib: $_lib"
-debug "Using initrd_dir: $initrd_dir"
-
 cache_modprobe_conf
 
 for n in $PREMODS; do
@@ -1369,7 +1386,6 @@ mknod "$DESTDIR/dev/console" c 5 1
 mknod "$DESTDIR/dev/null" c 1 3
 mknod "$DESTDIR/dev/zero" c 1 5
 
-busybox=$(find_tool $initrd_dir/initrd-busybox /bin/initrd-busybox) || die "Couldn't find busybox suitable for initrd"
 inst_exec $busybox /bin/initrd-busybox
 ln -s initrd-busybox $DESTDIR/bin/sh
 # for older busyboxes who had /bin/busybox as EXEPATH
index e362976e8813079f6ea346a5ed4b0d1fa95ea25d..c808e70b1901b62a00db3070164d1557002600fd 100644 (file)
@@ -5,12 +5,16 @@
 # true if we should parse UUID= or LABEL= for root parameter
 have_blkid=no
 
-blkid=$(find_tool $initrd_dir/blkid /sbin/initrd-blkid)
-if [ -x "$blkid" ]; then
-       USE_BLKID=yes
-else
-       USE_BLKID=no
-fi
+# setup geninitrd module
+# @access      public
+setup_mod_blkid() {
+       blkid=$(find_tool $initrd_dir/blkid /sbin/initrd-blkid)
+       if [ -x "$blkid" ]; then
+               USE_BLKID=yes
+       else
+               USE_BLKID=no
+       fi
+}
 
 # generate initrd fragment
 # @access      public
index de7d569cb4edab92dd11e6da6466e36bae60fb88..be0b47a8179691c1021fcab7bf4ff0344eb2e6d2 100644 (file)
@@ -5,16 +5,20 @@
 # if we should init dmraid at boot
 have_dmraid=no
 
-dmraid=$(find_tool $initrd_dir/dmraid /sbin/dmraid-initrd)
-if [ -x /sbin/dmraid -a -x "$dmraid" ]; then
-       USE_DMRAID=yes
-else
-       USE_DMRAID=no
-fi
+# setup geninitrd module
+# @access      public
+setup_mod_dmraid() {
+       dmraid=$(find_tool $initrd_dir/dmraid /sbin/dmraid-initrd)
+       if [ -x /sbin/dmraid -a -x "$dmraid" ]; then
+               USE_DMRAID=yes
+       else
+               USE_DMRAID=no
+       fi
 
-if [ "$kernel_version" -lt "002006" ]; then
-       USE_DMRAID=no
-fi
+       if [ "$kernel_version" -lt "002006" ]; then
+               USE_DMRAID=no
+       fi
+}
 
 # return true if dmraid is set on $devpath
 # @param       string $devpath device node to be examined
index 1cfda62e637443f35ceab67286dcc230a3e11ddc..5a4b9d4107cb8499b295babc65039dfea43e2fdd 100644 (file)
@@ -6,16 +6,20 @@
 # and we should init cryptsetup luks at boot
 have_luks=no
 
-cryptsetup=$(find_tool $initrd_dir/cryptsetup /sbin/cryptsetup-initrd)
-if [ -x /sbin/cryptsetup -a -x "$cryptsetup" ]; then
-       USE_LUKS=yes
-else
-       USE_LUKS=no
-fi
-
 # device to use for name for cryptsetup luks
 LUKSDEV=""
 
+# setup geninitrd module
+# @access      public
+setup_mod_luks() {
+       cryptsetup=$(find_tool $initrd_dir/cryptsetup /sbin/cryptsetup-initrd)
+       if [ -x /sbin/cryptsetup -a -x "$cryptsetup" ]; then
+               USE_LUKS=yes
+       else
+               USE_LUKS=no
+       fi
+}
+
 # return true if node is cryptsetup luks encrypted
 # @param       string $node device node to be examined
 # @access      public
index 3fef638179a89844e52d9ce8dca2df5ffd6a59a3..d3999b3a21b9608d3bc9e5cfc0ff00a68ce19352 100644 (file)
@@ -19,17 +19,28 @@ VGVOLUMES=""
 # Values: 1|2
 LVMTOOLSVERSION=
 
-lvm=$(find_tool $initrd_dir/lvm /sbin/initrd-lvm)
-if [ -x /sbin/lvm -a -x "$lvm" ]; then
-       USE_LVM=yes
-else
-       USE_LVM=no
-fi
-
 # LVM devices that should not be included in vgscan on initrd.
 # @internal
 lvm_ignore_devices=''
 
+# setup geninitrd module
+# @access      public
+setup_mod_lvm() {
+       lvm=$(find_tool $initrd_dir/lvm /sbin/initrd-lvm)
+       if [ -x /sbin/lvm -a -x "$lvm" ]; then
+               USE_LVM=yes
+       else
+               USE_LVM=no
+       fi
+
+       if [ -z "$LVMTOOLSVERSION" ]; then
+               LVMTOOLSVERSION=$(LC_ALL=C $lvm vgchange --version 2>/dev/null | awk '/LVM version:/{if ($3 >= 2) print "2"}')
+               if [ -z "$LVMTOOLSVERSION" ]; then
+                       die "Can't determine LVM tools version. Please set LVMTOOLSVERSION and rerun $PROGRAM."
+               fi
+       fi
+}
+
 # return true if node is lvm node
 # @param       string $node device node to be examined
 # @access      public
@@ -77,13 +88,6 @@ find_modules_lvm() {
                die "root on LVM but /sbin/lvdisplay or /sbin/pvdisplay not found. Please install lvm(2) and lvm(2)-initrd package and rerun $PROGRAM."
        fi
 
-       if [ -z "$LVMTOOLSVERSION" ]; then
-               LVMTOOLSVERSION=$(LC_ALL=C $lvm vgchange --version 2>/dev/null | awk '/LVM version:/{if ($3 >= 2) print "2"}')
-               if [ -z "$LVMTOOLSVERSION" ]; then
-                       die "Can't determine LVM tools version. Please set LVMTOOLSVERSION and rerun $PROGRAM."
-               fi
-       fi
-
        local vg=$(find_lvm_vg "$devpath")
        debug "LVM VG for $devpath: $vg"
        VGVOLUMES=$(echo $VGVOLUMES $vg | tr ' ' '\n' | sort -u)
index 079d7875e19a49df41909949798c34e9113a81c6..7639c427eb4c69880a1d006bcf610614d563869a 100644 (file)
--- a/mod-md.sh
+++ b/mod-md.sh
@@ -5,16 +5,20 @@
 # if we should init md (softraid) at boot
 have_md=no
 
-mdassemble=$(find_tool $initrd_dir/mdassemble /sbin/initrd-mdassemble)
-if [ -x /sbin/mdadm -a -x "$mdassemble" ]; then
-       USE_MD=yes
-else
-       USE_MD=no
-fi
-
 # XXX wtf is this for?
 USERAIDSTART=yes
 
+# setup geninitrd module
+# @access      public
+setup_mod_md() {
+       mdassemble=$(find_tool $initrd_dir/mdassemble /sbin/initrd-mdassemble)
+       if [ -x /sbin/mdadm -a -x "$mdassemble" ]; then
+               USE_MD=yes
+       else
+               USE_MD=no
+       fi
+}
+
 # return true if mdadm is set on $devpath
 # @param       string $devpath device node to be examined
 # @access      public
index 9af9b6e781e4be3f2d8e8fee50de2d2bb9ccd806..c202281e8027852db37eb6cfc6a93977dd939905 100644 (file)
@@ -5,15 +5,19 @@
 # if we should init dm-multipath at boot
 have_multipath=no
 
-if [ -x /sbin/multipath ]; then
-       USE_MULTIPATH=yes
-else
-       USE_MULTIPATH=no
-fi
-
 # dm-multipath wwid which is used for rootfs
 MPATH_WWID=
 
+# setup geninitrd module
+# @access      public
+setup_mod_multipath() {
+       if [ -x /sbin/multipath ]; then
+               USE_MULTIPATH=yes
+       else
+               USE_MULTIPATH=no
+       fi
+}
+
 # return true if node is multipath controlled
 # @param       string $node device node to be examined
 # @access      public
index 4b5c1882f4055750865f9765ca5b928b6abbb910..7296866a227bd3d0706b2c2efa644e6716075599 100644 (file)
@@ -7,15 +7,19 @@
 # - make udev start before insmods
 # - make proper use of USE_UDEV - don't copy rules if USE_UDEV is off no!
 
-udevd=$(find_tool $initrd_dir/udevd /sbin/initrd-udevd)
-udevadm=$(find_tool $initrd_dir/initrd-udevadm /sbin/initrd-udevadm)
+# setup geninitrd module
+# @access      public
+setup_mod_udev() {
+       udevd=$(find_tool $initrd_dir/udevd /sbin/initrd-udevd)
+       udevadm=$(find_tool $initrd_dir/initrd-udevadm /sbin/initrd-udevadm)
 
-if [ "$kernel_version" -ge "002006" -a -x "$udevd" -a -a -x "$udevadm" -f /etc/udev/udev.conf ]; then
-       USE_UDEV=yes
-       . /etc/udev/udev.conf
-else
-       USE_UDEV=no
-fi
+       if [ "$kernel_version" -ge "002006" -a -x "$udevd" -a -x "$udevadm" -a -f /etc/udev/udev.conf ]; then
+               USE_UDEV=yes
+               . /etc/udev/udev.conf
+       else
+               USE_UDEV=no
+       fi
+}
 
 # generate initrd fragment
 # @access      public
This page took 0.34014 seconds and 4 git commands to generate.