]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
Speed up loading block drivers when running with --hostonly
authorVictor Lowther <victor.lowther@gmail.com>
Thu, 20 Aug 2009 03:20:12 +0000 (22:20 -0500)
committerVictor Lowther <victor.lowther@gmail.com>
Thu, 20 Aug 2009 03:21:29 +0000 (22:21 -0500)
Instead of grovelling through all the modules available for the
kernel looking for block devices, only look at the modules that are
actually loaded. This speeds things up by a rather large amount
when generating the initramfs with --hostonly.

While we are at it, only load the filesystem module that will actually
be used for the root filesystem when running in --hostonly instead
of all the filesystem modules that happen to be loaded at the time.

dracut-functions
modules.d/90kernel-modules/installkernel

index 655d311f60360c8bf9ee6d1e4c1381e82b626e00..f2a92027592bca3866237b980fabbcceda4735be 100755 (executable)
@@ -22,7 +22,7 @@ IF_RTLD=""
 IF_dynamic=""
 
 # Generic substring function.  If $2 is in $1, return 0.
-strstr() { [[ ! ${1#*$2*} = $1 ]]; }
+strstr() { [[ $1 =~ $2 ]]; }
 
 # Log initrd creation.
 if ! [[ $dracutlogfile ]]; then
@@ -60,11 +60,11 @@ get_fs_type() (
 )
 
 # finds the major:minor of the block device backing the root filesystem.
-find_root_block_device() {
+find_block_device() {
     local rootdev blkdev fs type opts misc
     while read blkdev fs type opts misc; do
        [[ $blkdev = rootfs ]] && continue # skip rootfs entry
-       [[ $fs = / ]] && { rootdev=$blkdev; break; } # we have a winner!
+       [[ $fs = $1 ]] && { rootdev=$blkdev; break; } # we have a winner!
     done < /proc/mounts
     [[ -b $rootdev ]] || return 1 # oops, not a block device.
     # get major/minor for the device
@@ -72,6 +72,8 @@ find_root_block_device() {
        (read x x x x maj min x; maj=${maj//,/}; echo $maj:$min)
 }
 
+find_root_block_device() { find_block_device /; }
+
 # Walk all the slave relationships for a given block device.
 # Stop when our helper function returns success
 # $1 = function to call on every found block device
index f9a1ab45ca486dec1ea4a2ffc2d147bb24206415..253cdc06ea2599ab453e265c6860834ed60312ae 100755 (executable)
@@ -1,13 +1,24 @@
 #!/bin/bash
 if [[ -z $drivers ]]; then
-  drivers="sd_mod =fs"
+  drivers="sd_mod"
   # Include block controller drivers
   blockfuncs='ata_scsi_ioctl|scsi_add_host|blk_init_queue|register_mtd_blktrans|scsi_esp_register|register_virtio_device'
-  for modname in $(find "$srcmods/kernel/drivers" -name '*.ko'); do
-    if nm -uPA $modname | egrep -q "$blockfuncs"; then
-      drivers="${drivers} $modname"
-    fi
-  done
+  if [[ $hostonly = "" ]]; then
+      for modname in $(find "$srcmods/kernel/drivers" -name '*.ko'); do
+         if nm -uPA $modname | egrep -q "$blockfuncs"; then
+             drivers="${drivers} $modname"
+         fi
+      done
+      drivers="${drivers} =fs"
+  else
+      while read modname rest; do
+         modname=$(modinfo -F filename -k $kernel $modname)
+         if nm -uPA $modname |egrep -q "$blockfuncs"; then
+             drivers="${drivers} $modname"
+         fi
+      done </proc/modules
+      instmods $(get_fs_type "/dev/block/$(find_root_block_device)")
+  fi
   instmods $drivers
   # hardcoded list of exceptions
   rm -fr ${initdir}/lib/modules/*/kernel/fs/ocfs2