dracut: add --kernel-only and --no-kernel arguments

--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
master
Harald Hoyer 2009-07-22 12:43:26 +02:00
parent f24a2d46b7
commit 33ee031c4a
22 changed files with 123 additions and 64 deletions

View File

@ -65,3 +65,12 @@ check: all
testimage: all testimage: all
./dracut -l -a debug -f test-$(shell uname -r).img $(shell uname -r) ./dracut -l -a debug -f test-$(shell uname -r).img $(shell uname -r)
@echo wrote test-$(shell uname -r).img @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


6
README.kernel Normal file
View File

@ -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.

30
dracut
View File

@ -23,8 +23,10 @@ Creates initial ramdisk images for preloading modules
-d, --drivers [LIST] Specify a space-separated list of kernel modules to -d, --drivers [LIST] Specify a space-separated list of kernel modules to
include in the initramfs. include in the initramfs.
-k, --kmoddir [DIR] Specify the directory, where to look for kernel modules -k, --kmoddir [DIR] Specify the directory, where to look for kernel modules
--fwdir [DIR] Specify additional directory, where to look for --fwdir [DIR] Specify additional directories, where to look for
firmwares 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 -h, --help This message
--debug Output debug information of the build process --debug Output debug information of the build process
-v, --verbose Verbose output during the build process -v, --verbose Verbose output during the build process
@ -53,6 +55,8 @@ while (($# > 0)); do
-d|--drivers) drivers_l="$2"; shift;; -d|--drivers) drivers_l="$2"; shift;;
-k|--kmoddir) drivers_dir_l="$2"; shift;; -k|--kmoddir) drivers_dir_l="$2"; shift;;
--fwdir) fw_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 ;; -h|--help) usage; exit 1 ;;
--debug) debug="yes";; --debug) debug="yes";;
-v|--verbose) beverbose="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 [[ $drivers_dir_l ]] && drivers_dir=$drivers_dir_l
[[ $fw_dir_l ]] && fw_dir=$fw_dir_l [[ $fw_dir_l ]] && fw_dir=$fw_dir_l
[[ $dracutbasedir ]] || dracutbasedir=/usr/share/dracut [[ $dracutbasedir ]] || dracutbasedir=/usr/share/dracut
[[ $fw_dir ]] || fw_dir=/lib/firmware


[[ $allowlocal && -f "$(dirname $0)/dracut-functions" ]] && dsrc="$(dirname $0)" || dsrc=$dracutbasedir [[ $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" chmod 755 "$initdir"


export initdir hookdirs dsrc dracutmodules drivers \ 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 if [[ "$kernel_only" != "yes" ]]; then
for d in bin sbin usr/bin usr/sbin usr/lib etc proc sys sysroot tmp dev/pts var/run; do # Create some directory structure first
mkdir -p "$initdir/$d"; for d in bin sbin usr/bin usr/sbin usr/lib etc proc sys sysroot tmp dev/pts var/run; do
done mkdir -p "$initdir/$d";
done
fi


# check all our modules to see if they should be sourced. # check all our modules to see if they should be sourced.
# This builds a list of modules that we will install next. # 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 for moddir in "$dsrc/modules.d"/[0-9][0-9]*; do
mod=${moddir##*/}; mod=${mod#[0-9][0-9]} mod=${moddir##*/}; mod=${mod#[0-9][0-9]}
if strstr "$mods_to_load" " $mod "; then 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 /} mods_to_load=${mods_to_load// $mod /}
fi fi
done done

View File

@ -1,8 +1,8 @@
#!/bin/bash #!/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 # 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 # it under the terms of the GNU General Public License as published by
@ -17,10 +17,6 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # 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_RTLD=""
IF_dynamic="" IF_dynamic=""
@ -238,6 +234,10 @@ check_module_deps() {
should_source_module() { should_source_module() {
local dep local dep
[[ -x $1/install ]] || return 1 [[ -x $1/install ]] || return 1
if [[ "$kernel_only" = "yes" ]]; then
[[ -x $1/installkernel ]] && return 0
return 1
fi
[[ -x $1/check ]] || return 0 [[ -x $1/check ]] || return 0
"$1/check" $hostonly || return 1 "$1/check" $hostonly || return 1
for dep in $("$1/check" -d); do for dep in $("$1/check" -d); do
@ -266,6 +266,7 @@ check_modules() {


# install kernel modules, and handle installing all their dependencies as well. # install kernel modules, and handle installing all their dependencies as well.
instmods() { instmods() {
[[ "$no_kernel" = "yes" ]] && return
local mod mpargs modpath modname cmd local mod mpargs modpath modname cmd
while (($# > 0)); do while (($# > 0)); do
mod=${1%.ko} mod=${1%.ko}
@ -294,7 +295,7 @@ instmods() {
[[ $hostonly ]] && ! grep -q "$mod" /proc/modules && { [[ $hostonly ]] && ! grep -q "$mod" /proc/modules && {
shift; continue; 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 | \ --show-depends $mod 2>/dev/null | \
while read cmd modpath options; do while read cmd modpath options; do
[[ $cmd = insmod ]] || continue [[ $cmd = insmod ]] || continue
@ -304,16 +305,20 @@ instmods() {
dinfo "Installing dependencies for $mod ($modpath)" dinfo "Installing dependencies for $mod ($modpath)"
instmods $mpargs $modname instmods $mpargs $modname
fi fi
inst_simple "$modpath" inst_simple "$modpath" "/lib/modules/$kernel/${modpath##*/lib/modules/$kernel/}"
done for fw in $(modinfo -k $kernel -F firmware $modpath 2>/dev/null); do
for fw in $(modinfo -F firmware $mod 2>/dev/null); do unset found
if [[ -n "$fw_dir" && -f $fw_dir/$fw ]]; then IFS=:
inst_simple "$fw_dir/$fw" for fwdir in $fw_dir; do
elif [[ -f /lib/firmware/$fw ]]; then if [ -d "$fwdir" -a -f $fwdir/$fw ]; then
inst_simple "/lib/firmware/$fw" inst_simple "$fwdir/$fw" "/lib/firmware/$fw"
else found=yes
dwarning "Possible missing firmware ${fw} for module ${mod}.ko" fi
fi done
if [ "$found" != "yes" ]; then
dwarning "Possible missing firmware ${fw} for module ${mod}.ko"
fi
done
done done
;; ;;
esac esac

View File

@ -36,6 +36,12 @@ specify the directory, where to look for kernel modules
.BR " \-\-fwdir " \fI[DIR]\fR .BR " \-\-fwdir " \fI[DIR]\fR
specify additional directory, where to look for firmwares specify additional directory, where to look for firmwares
.TP .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 .BR \-h ", " \-\-help
display help text and exit. display help text and exit.
.TP .TP

View File

@ -51,7 +51,6 @@ BuildArch: noarch
%description %description
dracut is a new, event-driven initramfs infrastructure based around udev. dracut is a new, event-driven initramfs infrastructure based around udev.



%package generic %package generic
Summary: Metapackage to build a generic initramfs Summary: Metapackage to build a generic initramfs
Requires: %{name} = %{version}-%{release} Requires: %{name} = %{version}-%{release}
@ -60,17 +59,25 @@ Requires: iscsi-initiator-utils
Requires: nbd Requires: nbd
Requires: bridge-utils Requires: bridge-utils
Requires: net-tools iproute Requires: net-tools iproute
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 Requires: plymouth-system-theme plymouth-theme-charge plymouth-theme-solar


%description generic %description generic
This package requires everything which is needed to build a generic This package requires everything which is needed to build a generic
all purpose initramfs. 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

%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 %prep
%setup -q -n %{name}-%{version}%{?dashgittag} %setup -q -n %{name}-%{version}%{?dashgittag}


@ -107,6 +114,10 @@ rm -rf $RPM_BUILD_ROOT
%defattr(-,root,root,0755) %defattr(-,root,root,0755)
%doc README.generic %doc README.generic


%files kernel
%defattr(-,root,root,0755)
%doc README.kernel

%changelog %changelog
* Fri Jul 17 2009 Harald Hoyer <harald@redhat.com> 0.5-1 * Fri Jul 17 2009 Harald Hoyer <harald@redhat.com> 0.5-1
- version 0.5 - version 0.5

View File

@ -1,22 +1,9 @@
#!/bin/bash #!/bin/bash
dracut_install ip dhclient hostname brctl 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/ifup" "/sbin/ifup"
inst "$moddir/netroot" "/sbin/netroot" inst "$moddir/netroot" "/sbin/netroot"
inst "$moddir/dhclient-script" "/sbin/dhclient-script" inst "$moddir/dhclient-script" "/sbin/dhclient-script"
inst "$moddir/dhclient.conf" "/etc/dhclient.conf" 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 pre-udev 60 "$moddir/net-genrules.sh"
inst_hook cmdline 91 "$moddir/dhcp-root.sh" inst_hook cmdline 91 "$moddir/dhcp-root.sh"
inst_hook cmdline 99 "$moddir/parse-ip-opts.sh" inst_hook cmdline 99 "$moddir/parse-ip-opts.sh"

View File

@ -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

View File

@ -5,7 +5,3 @@ inst_hook pre-pivot 90 "$moddir"/plymouth-newroot.sh
inst_hook pre-trigger 10 "$moddir"/plymouth-pretrigger.sh inst_hook pre-trigger 10 "$moddir"/plymouth-pretrigger.sh
inst_hook emergency 50 "$moddir"/plymouth-emergency.sh inst_hook emergency 50 "$moddir"/plymouth-emergency.sh
inst "$moddir"/cryptroot-ask.sh /sbin/cryptroot-ask 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

View File

@ -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

View File

@ -1,6 +1,5 @@
#!/bin/bash #!/bin/bash
inst cryptsetup inst cryptsetup
instmods dm_crypt cbc aes sha256 xts
inst_rules "$moddir/70-luks.rules" inst_rules "$moddir/70-luks.rules"
inst "$moddir"/cryptroot-ask.sh /sbin/cryptroot-ask inst "$moddir"/cryptroot-ask.sh /sbin/cryptroot-ask
inst_hook cmdline 30 "$moddir/parse-crypt.sh" inst_hook cmdline 30 "$moddir/parse-crypt.sh"

View File

@ -0,0 +1,2 @@
#!/bin/bash
instmods dm_crypt cbc aes sha256 xts

View File

@ -1,13 +1,3 @@
#!/bin/bash #!/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 [ -f /etc/modprobe.conf ] && dracut_install /etc/modprobe.conf
dracut_install $(find /etc/modprobe.d/ -type f -name '*.conf') dracut_install $(find /etc/modprobe.d/ -type f -name '*.conf')

View File

@ -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

View File

@ -11,8 +11,6 @@ dracut_install mdadm partx
# inst /etc/passwd # inst /etc/passwd
# inst /etc/group # inst /etc/group


instmods =drivers/md

if [ -x /lib/udev/vol_id ]; then if [ -x /lib/udev/vol_id ]; then
inst_rules "$moddir/61-mdadm.rules" inst_rules "$moddir/61-mdadm.rules"
else else

View File

@ -0,0 +1,3 @@
#!/bin/bash
instmods =drivers/md

View File

@ -6,4 +6,3 @@ inst iscsi-iname
inst_hook cmdline 90 "$moddir/parse-iscsiroot.sh" inst_hook cmdline 90 "$moddir/parse-iscsiroot.sh"
inst "$moddir/iscsiroot" "/sbin/iscsiroot" inst "$moddir/iscsiroot" "/sbin/iscsiroot"
inst "$moddir/mount-lun.sh" "/bin/mount-lun.sh" inst "$moddir/mount-lun.sh" "/bin/mount-lun.sh"
instmods iscsi_tcp crc32c

View File

@ -0,0 +1,2 @@
#!/bin/bash
instmods iscsi_tcp crc32c

View File

@ -9,4 +9,3 @@ else
fi fi


inst "$moddir/nbdroot" "/sbin/nbdroot" inst "$moddir/nbdroot" "/sbin/nbdroot"
instmods nbd

2
modules.d/95nbd/installkernel Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
instmods nbd

View File

@ -16,7 +16,6 @@ fi
dracut_install $(ls {/usr,}$LIBDIR/libnfsidmap*.so* 2>/dev/null ) dracut_install $(ls {/usr,}$LIBDIR/libnfsidmap*.so* 2>/dev/null )
dracut_install $(ls {/usr,}$LIBDIR/libnss*.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 cmdline 90 "$moddir/parse-nfsroot.sh"
inst_hook pre-pivot 70 "$moddir/nfsroot-cleanup.sh" inst_hook pre-pivot 70 "$moddir/nfsroot-cleanup.sh"
inst "$moddir/nfsroot" "/sbin/nfsroot" inst "$moddir/nfsroot" "/sbin/nfsroot"

2
modules.d/95nfs/installkernel Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
instmods nfs sunrpc ipv6