dracut: add --kernel-only and --no-kernel arguments
authorHarald Hoyer <harald@eeepc.(none)>
Wed, 22 Jul 2009 10:43:26 +0000 (12:43 +0200)
committerHarald Hoyer <harald@eeepc.(none)>
Wed, 22 Jul 2009 13:07:11 +0000 (15:07 +0200)
       --kernel-only
              only install kernel drivers and firmware files

       --no-kernel
              do not install kernel drivers and firmware files

All kernel module related install commands moved from "install"
to "installkernel".

For "--kernel-only" all installkernel scripts of the specified
modules are used, regardless of any checks, so that all modules
which might be needed by any dracut generic image are in.

The basic idea is to create two images. One image with the kernel
modules and one without. So if the kernel changes, you only have
to replace one image.

Grub and the kernel can handle multiple images, so grub entry can
look like this:

title Fedora (2.6.29.5-191.fc11.i586)
        root (hd0,0)
        kernel /vmlinuz-2.6.29.5-191.fc11.i586 ro rhgb quiet
        initrd /initrd-20090722.img
        initrd /initrd-kernel-2.6.29.5-191.fc11.i586.img
        initrd /initrd-config.img

initrd-20090722.img
  the image provided by the initrd rpm
  one old backup version is kept like with the kernel

initrd-kernel-2.6.29.5-191.fc11.i586.img
  the image provided by the kernel rpm

initrd-config.img
  optional image with local configuration files

22 files changed:
Makefile
README.kernel [new file with mode: 0644]
dracut
dracut-functions
dracut.8
dracut.spec
modules.d/40network/install
modules.d/40network/installkernel [new file with mode: 0755]
modules.d/50plymouth/install
modules.d/50plymouth/installkernel [new file with mode: 0755]
modules.d/90crypt/install
modules.d/90crypt/installkernel [new file with mode: 0755]
modules.d/90kernel-modules/install
modules.d/90kernel-modules/installkernel [new file with mode: 0755]
modules.d/90mdraid/install
modules.d/90mdraid/installkernel [new file with mode: 0755]
modules.d/95iscsi/install
modules.d/95iscsi/installkernel [new file with mode: 0755]
modules.d/95nbd/install
modules.d/95nbd/installkernel [new file with mode: 0755]
modules.d/95nfs/install
modules.d/95nfs/installkernel [new file with mode: 0755]

index 2b1d003..490c163 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -65,3 +65,12 @@ check: all
 testimage: all
        ./dracut -l -a debug -f test-$(shell uname -r).img $(shell uname -r)
        @echo wrote  test-$(shell uname -r).img 
+
+testimages: all
+       ./dracut -l -a debug --kernel-only -f test-kernel-$(shell uname -r).img $(shell uname -r)
+       @echo wrote  test-$(shell uname -r).img 
+       ./dracut -l -a debug --no-kernel -f test-dracut.img $(shell uname -r)
+       @echo wrote  test-dracut.img 
+       
+       
+
diff --git a/README.kernel b/README.kernel
new file mode 100644 (file)
index 0000000..f477ee5
--- /dev/null
@@ -0,0 +1,6 @@
+dracut-kernel is used to pull in all firmware files to build an initrd with 
+only kernel modules and firmware files.
+
+dracut --kernel-only only executes "installkernel" in the modules 
+subdirectories.
+
diff --git a/dracut b/dracut
index bbc6a5d..44296b8 100755 (executable)
--- a/dracut
+++ b/dracut
@@ -23,8 +23,10 @@ Creates initial ramdisk images for preloading modules
   -d, --drivers [LIST]  Specify a space-separated list of kernel modules to
                          include in the initramfs.
   -k, --kmoddir [DIR]   Specify the directory, where to look for kernel modules
-  --fwdir [DIR]         Specify additional directory, where to look for 
-                        firmwares
+  --fwdir [DIR]         Specify additional directories, where to look for 
+                        firmwares, separated by :
+  --kernel-only         Only install kernel drivers and firmware files
+  --no-kernel           Do not install kernel drivers and firmware files
   -h, --help            This message
   --debug               Output debug information of the build process
   -v, --verbose         Verbose output during the build process
@@ -53,6 +55,8 @@ while (($# > 0)); do
        -d|--drivers) drivers_l="$2"; shift;;
        -k|--kmoddir) drivers_dir_l="$2"; shift;;
        --fwdir) fw_dir_l="$2"; shift;;
+       --kernel-only) kernel_only="yes"; nokernel="no";;
+       --no-kernel) kernel_only="no"; no_kernel="yes";;
        -h|--help) usage; exit 1 ;;
        --debug) debug="yes";;
        -v|--verbose) beverbose="yes";;
@@ -87,6 +91,7 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH
 [[ $drivers_dir_l ]] && drivers_dir=$drivers_dir_l
 [[ $fw_dir_l ]] && fw_dir=$fw_dir_l
 [[ $dracutbasedir ]] || dracutbasedir=/usr/share/dracut
+[[ $fw_dir ]] || fw_dir=/lib/firmware
 
 [[ $allowlocal && -f "$(dirname $0)/dracut-functions" ]] && dsrc="$(dirname $0)" || dsrc=$dracutbasedir
 
@@ -127,12 +132,14 @@ trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die.
 chmod 755 "$initdir"
 
 export initdir hookdirs dsrc dracutmodules drivers \
-    fw_dir drivers_dir debug beverbose
+    fw_dir drivers_dir debug beverbose no_kernel kernel_only
 
-# Create some directory structure first
-for d in bin sbin usr/bin usr/sbin usr/lib etc proc sys sysroot tmp dev/pts var/run; do 
-    mkdir -p "$initdir/$d"; 
-done
+if [[ "$kernel_only" != "yes" ]]; then
+    # Create some directory structure first
+    for d in bin sbin usr/bin usr/sbin usr/lib etc proc sys sysroot tmp dev/pts var/run; do 
+       mkdir -p "$initdir/$d"; 
+    done
+fi
 
 # check all our modules to see if they should be sourced.
 # This builds a list of modules that we will install next.
@@ -142,7 +149,14 @@ check_modules
 for moddir in "$dsrc/modules.d"/[0-9][0-9]*; do
     mod=${moddir##*/}; mod=${mod#[0-9][0-9]}
     if strstr "$mods_to_load" " $mod "; then
-       . "$moddir/install"
+       if [[ "$kernel_only" = "yes" ]]; then
+           [[ -x "$moddir/installkernel" ]] && . "$moddir/installkernel"
+       else
+           . "$moddir/install"
+           if [[ "$no_kernel" != "yes" && -x "$moddir/installkernel" ]]; then
+               . "$moddir/installkernel"
+           fi
+       fi
        mods_to_load=${mods_to_load// $mod /}
     fi
 done
index 2178dd7..6fef83a 100755 (executable)
@@ -1,8 +1,8 @@
 #!/bin/bash
 #
-# functions used by mkinitrd and other tools.
+# functions used by dracut and other tools.
 #
-# Copyright 2005-2008 Red Hat, Inc.  All rights reserved.
+# Copyright 2005-2009 Red Hat, Inc.  All rights reserved.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
-# Authors:
-#       Peter Jones <pjones@redhat.com>
-#       Jeremy Katz <katzj@redhat.com>
-#       Jakub Jelinek <jakub@redhat.com>
 
 IF_RTLD=""
 IF_dynamic=""
@@ -238,6 +234,10 @@ check_module_deps() {
 should_source_module() {
     local dep
     [[ -x $1/install ]] || return 1
+    if [[ "$kernel_only" = "yes" ]]; then
+        [[ -x $1/installkernel ]] && return 0
+        return 1
+    fi
     [[ -x $1/check ]] || return 0
     "$1/check" $hostonly || return 1
     for dep in $("$1/check" -d); do
@@ -266,6 +266,7 @@ check_modules() {
 
 # install kernel modules, and handle installing all their dependencies as well.
 instmods() {
+    [[ "$no_kernel" = "yes" ]] && return
     local mod mpargs modpath modname cmd
     while (($# > 0)); do
        mod=${1%.ko}
@@ -294,7 +295,7 @@ instmods() {
                [[ $hostonly ]] && ! grep -q "$mod" /proc/modules && { 
                    shift; continue; 
                }
-                modprobe $mpargs --ignore-install --set-version $kernel \
+                modprobe $mpargs --ignore-install --set-version $kernel -d ${srcmods%%/lib/modules/*}/ \
                    --show-depends $mod 2>/dev/null | \
                    while read cmd modpath options; do
                    [[ $cmd = insmod ]] || continue
@@ -304,16 +305,20 @@ instmods() {
                        dinfo "Installing dependencies for $mod ($modpath)"
                        instmods $mpargs $modname
                    fi
-                   inst_simple "$modpath"
-               done
-               for fw in $(modinfo -F firmware $mod 2>/dev/null); do
-                   if [[ -n "$fw_dir" && -f $fw_dir/$fw ]]; then
-                       inst_simple "$fw_dir/$fw"
-                   elif [[ -f /lib/firmware/$fw ]]; then
-                       inst_simple "/lib/firmware/$fw"
-                   else
-                       dwarning "Possible missing firmware ${fw} for module ${mod}.ko"
-                   fi
+                   inst_simple "$modpath" "/lib/modules/$kernel/${modpath##*/lib/modules/$kernel/}"
+                   for fw in $(modinfo -k $kernel -F firmware $modpath 2>/dev/null); do
+                       unset found
+                       IFS=: 
+                       for fwdir in $fw_dir; do                    
+                           if [ -d "$fwdir" -a -f $fwdir/$fw ]; then
+                               inst_simple "$fwdir/$fw" "/lib/firmware/$fw"
+                               found=yes
+                           fi
+                       done
+                       if [ "$found" != "yes" ]; then
+                           dwarning "Possible missing firmware ${fw} for module ${mod}.ko"
+                       fi
+                   done
                done
                ;;
        esac      
index 23bea5e..55a4037 100644 (file)
--- a/dracut.8
+++ b/dracut.8
@@ -36,6 +36,12 @@ specify the directory, where to look for kernel modules
 .BR " \-\-fwdir " \fI[DIR]\fR   
 specify additional directory, where to look for firmwares
 .TP
+.BR \-\-kernel-only
+only install kernel drivers and firmware files
+.TP
+.BR \-\-no-kernel
+do not install kernel drivers and firmware files
+.TP
 .BR \-h ", " \-\-help
 display help text and exit. 
 .TP
index d74a521..afd940b 100644 (file)
@@ -51,7 +51,6 @@ BuildArch: noarch
 %description
 dracut is a new, event-driven initramfs infrastructure based around udev.
 
-
 %package generic
 Summary: Metapackage to build a generic initramfs
 Requires: %{name} = %{version}-%{release}
@@ -60,16 +59,24 @@ Requires: iscsi-initiator-utils
 Requires: nbd
 Requires: bridge-utils
 Requires: net-tools iproute
+Requires: plymouth-system-theme plymouth-theme-charge plymouth-theme-solar
+
+%description generic
+This package requires everything which is needed to build a generic
+all purpose initramfs.
+
+%package kernel
+Summary: Metapackage to build generic initramfs with only kernel modules
+Requires: %{name} = %{version}-%{release}
 Requires: ql2100-firmware
 Requires: ql2200-firmware
 Requires: ql23xx-firmware
 Requires: ql2400-firmware
 Requires: ql2500-firmware
-Requires: plymouth-system-theme plymouth-theme-charge plymouth-theme-solar
 
-%description generic
-This package requires everything which is needed to build a generic
-all purpose initramfs.
+%description kernel
+This package requires everything which is needed to build a initramfs with all
+kernel modules and firmware files needed by dracut modules.
 
 %prep
 %setup -q -n %{name}-%{version}%{?dashgittag}
@@ -107,6 +114,10 @@ rm -rf $RPM_BUILD_ROOT
 %defattr(-,root,root,0755)
 %doc README.generic
 
+%files kernel 
+%defattr(-,root,root,0755)
+%doc README.kernel
+
 %changelog
 * Fri Jul 17 2009 Harald Hoyer <harald@redhat.com> 0.5-1
 - version 0.5
index 79fbf57..e66c72f 100755 (executable)
@@ -1,22 +1,9 @@
 #!/bin/bash
 dracut_install ip dhclient hostname brctl
-# Include wired net drivers, excluding wireless
-for modname in $(find "$srcmods/kernel/drivers" -name '*.ko'); do
-  if nm -uPA $modname | grep -q eth_type_trans; then
-    if echo "$modname" | grep -q wireless; then
-      continue
-    else
-      instmods $modname 
-    fi
-  fi
-done
 inst "$moddir/ifup" "/sbin/ifup"
 inst "$moddir/netroot" "/sbin/netroot"
 inst "$moddir/dhclient-script" "/sbin/dhclient-script"
 inst "$moddir/dhclient.conf" "/etc/dhclient.conf" 
-instmods ecb arc4
-# bridge modules
-instmods bridge stp llc
 inst_hook pre-udev 60 "$moddir/net-genrules.sh"
 inst_hook cmdline 91 "$moddir/dhcp-root.sh"
 inst_hook cmdline 99 "$moddir/parse-ip-opts.sh"
diff --git a/modules.d/40network/installkernel b/modules.d/40network/installkernel
new file mode 100755 (executable)
index 0000000..96e87b1
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/bash
+# Include wired net drivers, excluding wireless
+for modname in $(find "$srcmods/kernel/drivers" -name '*.ko'); do
+  if nm -uPA $modname | grep -q eth_type_trans; then
+    if echo "$modname" | grep -q wireless; then
+      continue
+    else
+      instmods $modname 
+    fi
+  fi
+done
+instmods ecb arc4
+# bridge modules
+instmods bridge stp llc
index 89a0a09..eedf4f6 100755 (executable)
@@ -5,7 +5,3 @@ inst_hook pre-pivot 90 "$moddir"/plymouth-newroot.sh
 inst_hook pre-trigger 10 "$moddir"/plymouth-pretrigger.sh
 inst_hook emergency 50 "$moddir"/plymouth-emergency.sh
 inst "$moddir"/cryptroot-ask.sh /sbin/cryptroot-ask
-# Include KMS capable drm drivers
-for modname in $(find "$srcmods/kernel/drivers/gpu/drm" -name '*.ko'); do
-    nm -uPA $modname | grep -q drm_crtc_init && instmods $modname
-done
diff --git a/modules.d/50plymouth/installkernel b/modules.d/50plymouth/installkernel
new file mode 100755 (executable)
index 0000000..4b281e8
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/bash
+# Include KMS capable drm drivers
+for modname in $(find "$srcmods/kernel/drivers/gpu/drm" -name '*.ko'); do
+    nm -uPA $modname | grep -q drm_crtc_init && instmods $modname
+done
index 9ffe90e..1319503 100755 (executable)
@@ -1,6 +1,5 @@
 #!/bin/bash
 inst cryptsetup
-instmods dm_crypt cbc aes sha256 xts
 inst_rules "$moddir/70-luks.rules"
 inst "$moddir"/cryptroot-ask.sh /sbin/cryptroot-ask
 inst_hook cmdline 30 "$moddir/parse-crypt.sh"
diff --git a/modules.d/90crypt/installkernel b/modules.d/90crypt/installkernel
new file mode 100755 (executable)
index 0000000..7a58ea3
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/bash
+instmods dm_crypt cbc aes sha256 xts
index e6db3e1..b3fb0df 100755 (executable)
@@ -1,13 +1,3 @@
 #!/bin/bash
-if [ -z "$drivers" ]; then
-  drivers="sd_mod =fs"
-  # Include block controller drivers
-  for modname in $(find "$srcmods/kernel/drivers" -name '*.ko'); do
-    if nm -uPA $modname | egrep -q 'ata_scsi_ioctl|scsi_add_host|blk_init_queue|register_mtd_blktrans|scsi_esp_register'; then
-      drivers="${drivers} $modname"
-    fi
-  done
-fi
-instmods $drivers
 [ -f /etc/modprobe.conf ] && dracut_install /etc/modprobe.conf
 dracut_install $(find /etc/modprobe.d/ -type f -name '*.conf')
diff --git a/modules.d/90kernel-modules/installkernel b/modules.d/90kernel-modules/installkernel
new file mode 100755 (executable)
index 0000000..d86f3fb
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/bash
+if [ -z "$drivers" ]; then
+  drivers="sd_mod =fs"
+  # Include block controller drivers
+  for modname in $(find "$srcmods/kernel/drivers" -name '*.ko'); do
+    if nm -uPA $modname | egrep -q 'ata_scsi_ioctl|scsi_add_host|blk_init_queue|register_mtd_blktrans|scsi_esp_register'; then
+      drivers="${drivers} $modname"
+    fi
+  done
+fi
+instmods $drivers
index 2303f5d..07ca96c 100755 (executable)
@@ -11,8 +11,6 @@ dracut_install mdadm partx
 # inst /etc/passwd
 # inst /etc/group
 
-instmods =drivers/md
-
 if [ -x /lib/udev/vol_id ]; then
     inst_rules "$moddir/61-mdadm.rules"
 else
diff --git a/modules.d/90mdraid/installkernel b/modules.d/90mdraid/installkernel
new file mode 100755 (executable)
index 0000000..d26bafa
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/bash
+instmods =drivers/md
+
index 7f8c2e2..6386410 100755 (executable)
@@ -6,4 +6,3 @@ inst iscsi-iname
 inst_hook cmdline 90 "$moddir/parse-iscsiroot.sh"
 inst "$moddir/iscsiroot" "/sbin/iscsiroot"
 inst "$moddir/mount-lun.sh" "/bin/mount-lun.sh"
-instmods iscsi_tcp crc32c
diff --git a/modules.d/95iscsi/installkernel b/modules.d/95iscsi/installkernel
new file mode 100755 (executable)
index 0000000..1dcf19a
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/bash
+instmods iscsi_tcp crc32c
index 0b87def..195c27e 100755 (executable)
@@ -9,4 +9,3 @@ else
 fi
 
 inst "$moddir/nbdroot" "/sbin/nbdroot"
-instmods nbd
diff --git a/modules.d/95nbd/installkernel b/modules.d/95nbd/installkernel
new file mode 100755 (executable)
index 0000000..c8eea5e
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/bash
+instmods nbd
index 2e96e5d..7f96cc7 100755 (executable)
@@ -16,7 +16,6 @@ fi
 dracut_install $(ls {/usr,}$LIBDIR/libnfsidmap*.so* 2>/dev/null )
 dracut_install $(ls {/usr,}$LIBDIR/libnss*.so 2>/dev/null)
 
-instmods nfs sunrpc ipv6
 inst_hook cmdline 90 "$moddir/parse-nfsroot.sh"
 inst_hook pre-pivot 70 "$moddir/nfsroot-cleanup.sh"
 inst "$moddir/nfsroot" "/sbin/nfsroot"
diff --git a/modules.d/95nfs/installkernel b/modules.d/95nfs/installkernel
new file mode 100755 (executable)
index 0000000..fa31aa2
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/bash
+instmods nfs sunrpc ipv6