* Added an option `boot.initrd.availableKernelModules' that specifies

modules that should be added to the initrd, but should only be
  loaded on demand (e.g. by the kernel or by udev).  This is
  especially useful in the installation CD, where we now only load the
  modules needed by the hardware.
* Enable automatic modprobing by udev in the initrd.

svn path=/nixos/trunk/; revision=18975
This commit is contained in:
Eelco Dolstra 2009-12-15 16:38:20 +00:00
parent e8372257a1
commit 6c9059e717
6 changed files with 106 additions and 96 deletions

View file

@ -114,7 +114,7 @@ in
# The initrd has to contain any module that might be necessary for # The initrd has to contain any module that might be necessary for
# mounting the CD/DVD. # mounting the CD/DVD.
boot.initrd.kernelModules = boot.initrd.availableKernelModules =
[ # SATA/PATA support. [ # SATA/PATA support.
"ahci" "ahci"
@ -160,9 +160,11 @@ in
"vfat" "vfat"
# And of course we need to be able to mount the CD. # And of course we need to be able to mount the CD.
"iso9660" "loop" "squashfs" "iso9660"
]; ];
boot.initrd.kernelModules = [ "loop" ];
# nixos-install will do a pull from this channel to speed up the # nixos-install will do a pull from this channel to speed up the
# installation. # installation.
installer.nixpkgsURL = http://nixos.org/releases/nixpkgs/channels/nixpkgs-unstable; installer.nixpkgsURL = http://nixos.org/releases/nixpkgs/channels/nixpkgs-unstable;

View file

@ -128,7 +128,7 @@ in
(! config.boot.kernelPackages.kernel.features ? aufs) (! config.boot.kernelPackages.kernel.features ? aufs)
config.boot.kernelPackages.aufs; config.boot.kernelPackages.aufs;
boot.initrd.kernelModules = ["aufs" "squashfs"]; boot.initrd.availableKernelModules = [ "aufs" "squashfs" ];
# Tell stage 1 of the boot to mount a tmpfs on top of the CD using # Tell stage 1 of the boot to mount a tmpfs on top of the CD using
# AUFS. !!! It would be nicer to make the stage 1 init pluggable # AUFS. !!! It would be nicer to make the stage 1 init pluggable

View file

@ -61,13 +61,65 @@ let kernel = config.boot.kernelPackages.kernel; in
The set of kernel modules to be loaded in the second stage of The set of kernel modules to be loaded in the second stage of
the boot process. Note that modules that are needed to the boot process. Note that modules that are needed to
mount the root file system should be added to mount the root file system should be added to
<option>boot.initrd.availableKernelModules</option> or
<option>boot.initrd.kernelModules</option>. <option>boot.initrd.kernelModules</option>.
''; '';
}; };
boot.initrd.availableKernelModules = mkOption {
default = [];
example = [ "sata_nv" "ext3" ];
description = ''
The set of kernel modules in the initial ramdisk used during the
boot process. This set must include all modules necessary for
mounting the root device. That is, it should include modules
for the physical device (e.g., SCSI drivers) and for the file
system (e.g., ext3). The set specified here is automatically
closed under the module dependency relation, i.e., all
dependencies of the modules list here are included
automatically. The modules listed here are available in the
initrd, but are only loaded on demand (e.g., the ext3 module is
loaded automatically when an ext3 filesystem is mounted, and
modules for PCI devices are loaded when they match the PCI ID
of a device in your system). To force a module to be loaded,
include it in <option>boot.initrd.kernelModules</option>.
'';
};
boot.initrd.kernelModules = mkOption { boot.initrd.kernelModules = mkOption {
default = [ default = [
# Note: most of these (especially the SATA/PATA modules) ];
description = "List of modules that are always loaded by the initrd.";
};
system.modulesTree = mkOption {
internal = true;
default = [];
description = ''
Tree of kernel modules. This includes the kernel, plus modules
built outside of the kernel. Combine these into a single tree of
symlinks because modprobe only supports one directory.
'';
merge = mergeListOption;
# Convert the list of path to only one path.
apply = pkgs.aggregateModules;
};
};
###### implementation
config = {
system.build = { inherit kernel; };
system.modulesTree = [ kernel ] ++ config.boot.extraModulePackages;
boot.kernelModules = [ "loop" ];
boot.initrd.availableKernelModules =
[ # Note: most of these (especially the SATA/PATA modules)
# shouldn't be included by default since nixos-hardware-scan # shouldn't be included by default since nixos-hardware-scan
# detects them, but I'm keeping them for now for backwards # detects them, but I'm keeping them for now for backwards
# compatibility. # compatibility.
@ -100,50 +152,17 @@ let kernel = config.boot.kernelPackages.kernel; in
"ohci_hcd" "ohci_hcd"
"usbhid" "usbhid"
# LVM. # Unix domain sockets (needed by udev).
"dm_mod"
# All-mod-config case:
"unix" "unix"
# Misc. stuff.
"i8042" "pcips2" "serio" "atkbd" "xtkbd" "i8042" "pcips2" "serio" "atkbd" "xtkbd"
]; ];
description = ''
The set of kernel modules in the initial ramdisk used during the boot.initrd.kernelModules =
boot process. This set must include all modules necessary for [ # For LVM.
mounting the root device. That is, it should include modules "dm_mod"
for the physical device (e.g., SCSI drivers) and for the file ];
system (e.g., ext3). The set specified here is automatically
closed under the module dependency relation, i.e., all
dependencies of the modules list here are included
automatically.
'';
};
system.modulesTree = mkOption {
internal = true;
default = [];
description = ''
Tree of kernel modules. This includes the kernel, plus modules
built outside of the kernel. Combine these into a single tree of
symlinks because modprobe only supports one directory.
'';
merge = mergeListOption;
# Convert the list of path to only one path.
apply = pkgs.aggregateModules;
};
};
###### implementation
config = {
system.build = { inherit kernel; };
system.modulesTree = [ kernel ] ++ config.boot.extraModulePackages;
boot.kernelModules = [ "loop" ];
# The Linux kernel >= 2.6.27 provides firmware. # The Linux kernel >= 2.6.27 provides firmware.
hardware.firmware = [ "${kernel}/lib/firmware" ]; hardware.firmware = [ "${kernel}/lib/firmware" ];

View file

@ -3,6 +3,7 @@
targetRoot=/mnt-root targetRoot=/mnt-root
export LD_LIBRARY_PATH=@extraUtils@/lib export LD_LIBRARY_PATH=@extraUtils@/lib
export PATH=@extraUtils@/bin:@klibc@/bin
fail() { fail() {
@ -43,16 +44,6 @@ echo "<<< NixOS Stage 1 >>>"
echo echo
# Set the PATH.
export PATH=/empty
for i in @path@; do
PATH=$PATH:$i/bin
if test -e $i/sbin; then
PATH=$PATH:$i/sbin
fi
done
# Mount special file systems. # Mount special file systems.
mkdir -p /etc # to shut up mount mkdir -p /etc # to shut up mount
echo -n > /etc/fstab # idem echo -n > /etc/fstab # idem
@ -87,10 +78,11 @@ for o in $(cat /proc/cmdline); do
done done
# Load some kernel modules. # Load the required kernel modules.
for i in $(cat @modulesClosure@/insmod-list); do echo @extraUtils@/bin/modprobe > /proc/sys/kernel/modprobe
for i in @kernelModules@; do
echo "loading module $(basename $i)..." echo "loading module $(basename $i)..."
insmod $i || true modprobe $i || true
done done
@ -107,12 +99,13 @@ if test -e /sys/power/tuxonice/resume; then
fi fi
if test -e /sys/power/resume -a -e /sys/power/disk; then if test -e /sys/power/resume -a -e /sys/power/disk; then
echo "@resumeDevice@" > /sys/power/resume 2> /dev/null || echo "failed to resume..." echo "@resumeDevice@" > /sys/power/resume 2> /dev/null || echo "failed to resume..."
echo shutdown > /sys/power/disk echo shutdown > /sys/power/disk
fi fi
# Create device nodes in /dev. # Create device nodes in /dev.
echo "running udev..."
export UDEV_CONFIG_FILE=@udevConf@ export UDEV_CONFIG_FILE=@udevConf@
mkdir -p /dev/.udev # !!! bug in udev? mkdir -p /dev/.udev # !!! bug in udev?
udevd --daemon udevd --daemon
@ -120,10 +113,10 @@ udevadm trigger
udevadm settle udevadm settle
if type -p dmsetup > /dev/null; then if type -p dmsetup > /dev/null; then
echo "starting device mapper and LVM..." echo "starting device mapper and LVM..."
dmsetup mknodes dmsetup mknodes
lvm vgscan --ignorelockingfailure lvm vgscan --ignorelockingfailure
lvm vgchange -ay --ignorelockingfailure lvm vgchange -ay --ignorelockingfailure
fi fi
if test -n "$debug1devices"; then fail; fi if test -n "$debug1devices"; then fail; fi

View file

@ -3,7 +3,7 @@
# the modules necessary to mount the root file system, then calls the # the modules necessary to mount the root file system, then calls the
# init in the root file system to start the second boot stage. # init in the root file system to start the second boot stage.
{pkgs, config, ...}: { config, pkgs, ... }:
let let
@ -30,15 +30,6 @@ let
"; ";
}; };
boot.initrd.allowMissing = mkOption {
default = true;
description = ''
Allow some initrd components to be missing. Useful for
custom kernel that are changed too often to track needed
kernelModules.
'';
};
boot.initrd.lvm = mkOption { boot.initrd.lvm = mkOption {
default = true; default = true;
description = " description = "
@ -82,6 +73,7 @@ let
}; };
boot.initrd.extraUtilsCommands = mkOption { boot.initrd.extraUtilsCommands = mkOption {
internal = true;
default = ""; default = "";
merge = pkgs.lib.mergeStringOption; merge = pkgs.lib.mergeStringOption;
description = '' description = ''
@ -110,9 +102,9 @@ let
# Determine the set of modules that we need to mount the root FS. # Determine the set of modules that we need to mount the root FS.
modulesClosure = pkgs.makeModulesClosure { modulesClosure = pkgs.makeModulesClosure {
rootModules = config.boot.initrd.kernelModules; rootModules = config.boot.initrd.availableKernelModules ++ config.boot.initrd.kernelModules;
kernel = modulesTree; kernel = modulesTree;
allowMissing = config.boot.initrd.allowMissing; allowMissing = true;
}; };
@ -125,7 +117,7 @@ let
{ buildInputs = [pkgs.nukeReferences]; { buildInputs = [pkgs.nukeReferences];
devicemapper = if config.boot.initrd.lvm then pkgs.devicemapper else null; devicemapper = if config.boot.initrd.lvm then pkgs.devicemapper else null;
lvm2 = if config.boot.initrd.lvm then pkgs.lvm2 else null; lvm2 = if config.boot.initrd.lvm then pkgs.lvm2 else null;
allowedReferences = ["out"]; # prevent accidents like glibc being included in the initrd allowedReferences = [ "out" modulesClosure ]; # prevent accidents like glibc being included in the initrd
doublePatchelf = (pkgs.stdenv.system == "armv5tel-linux"); doublePatchelf = (pkgs.stdenv.system == "armv5tel-linux");
} }
'' ''
@ -179,9 +171,9 @@ let
cp ${pkgs.bash}/bin/bash $out/bin cp ${pkgs.bash}/bin/bash $out/bin
ln -s bash $out/bin/sh ln -s bash $out/bin/sh
# Copy insmod. # Copy modprobe.
cp ${pkgs.module_init_tools}/sbin/insmod $out/bin cp ${pkgs.module_init_tools}/sbin/modprobe $out/bin/modprobe.real
${config.boot.initrd.extraUtilsCommands} ${config.boot.initrd.extraUtilsCommands}
# Run patchelf to make the programs refer to the copied libraries. # Run patchelf to make the programs refer to the copied libraries.
@ -191,12 +183,20 @@ let
if ! test -L $i; then if ! test -L $i; then
echo "patching $i..." echo "patching $i..."
patchelf --set-interpreter $out/lib/ld-linux*.so.? --set-rpath $out/lib $i || true patchelf --set-interpreter $out/lib/ld-linux*.so.? --set-rpath $out/lib $i || true
if [ "$doublePatchelf" -eq 1 ]; then if [ -n "$doublePatchelf" ]; then
patchelf --set-interpreter $out/lib/ld-linux*.so.? --set-rpath $out/lib $i || true patchelf --set-interpreter $out/lib/ld-linux*.so.? --set-rpath $out/lib $i || true
fi fi
fi fi
done done
# Make the modprobe wrapper that sets $MODULE_DIR.
cat > $out/bin/modprobe <<EOF
#! $out/bin/bash
export MODULE_DIR=${modulesClosure}/lib/modules
exec $out/bin/modprobe.real "\$@"
EOF
chmod u+x $out/bin/modprobe
# Make sure that the patchelf'ed binaries still work. # Make sure that the patchelf'ed binaries still work.
echo "testing patched programs..." echo "testing patched programs..."
$out/bin/bash --version $out/bin/bash --version
@ -215,7 +215,7 @@ let
$out/bin/reiserfsck -V $out/bin/reiserfsck -V
$out/bin/mdadm --version $out/bin/mdadm --version
$out/bin/basename --version $out/bin/basename --version
$out/bin/insmod --version $out/bin/modprobe --version
''; # */ ''; # */
@ -234,6 +234,7 @@ let
cp ${pkgs.udev}/libexec/rules.d/60-cdrom_id.rules $out/ cp ${pkgs.udev}/libexec/rules.d/60-cdrom_id.rules $out/
cp ${pkgs.udev}/libexec/rules.d/60-persistent-storage.rules $out/ cp ${pkgs.udev}/libexec/rules.d/60-persistent-storage.rules $out/
cp ${pkgs.udev}/libexec/rules.d/80-drivers.rules $out/
for i in $out/*.rules; do for i in $out/*.rules; do
substituteInPlace $i \ substituteInPlace $i \
@ -243,7 +244,8 @@ let
--replace path_id ${extraUtils}/bin/path_id \ --replace path_id ${extraUtils}/bin/path_id \
--replace vol_id ${extraUtils}/bin/vol_id \ --replace vol_id ${extraUtils}/bin/vol_id \
--replace cdrom_id ${extraUtils}/bin/cdrom_id \ --replace cdrom_id ${extraUtils}/bin/cdrom_id \
--replace /sbin/blkid ${extraUtils}/bin/blkid --replace /sbin/blkid ${extraUtils}/bin/blkid \
--replace /sbin/modprobe ${extraUtils}/bin/modprobe
done done
# Remove rule preventing creation of a by-label symlink # Remove rule preventing creation of a by-label symlink
@ -272,12 +274,14 @@ let
isExecutable = true; isExecutable = true;
inherit modulesClosure udevConf extraUtils; klibc = pkgs.klibcShrunk;
inherit udevConf extraUtils;
inherit (config.boot) isLiveCD resumeDevice; inherit (config.boot) isLiveCD resumeDevice;
inherit (config.boot.initrd) checkJournalingFS inherit (config.boot.initrd) checkJournalingFS
postDeviceCommands postMountCommands; postDeviceCommands postMountCommands kernelModules;
# !!! copy&pasted from upstart-jobs/filesystems.nix. # !!! copy&pasted from upstart-jobs/filesystems.nix.
mountPoints = mountPoints =
@ -287,14 +291,6 @@ let
devices = map (fs: if fs.device != null then fs.device else "/dev/disk/by-label/${fs.label}") fileSystems; devices = map (fs: if fs.device != null then fs.device else "/dev/disk/by-label/${fs.label}") fileSystems;
fsTypes = map (fs: fs.fsType) fileSystems; fsTypes = map (fs: fs.fsType) fileSystems;
optionss = map (fs: fs.options) fileSystems; optionss = map (fs: fs.options) fileSystems;
path = [
# `extraUtils' comes first because it overrides the `mount'
# command provided by klibc (which isn't capable of
# auto-detecting FS types).
extraUtils
pkgs.klibcShrunk
];
}; };

View file

@ -71,8 +71,8 @@ in
# All the modules the initrd needs to mount the host filesystem via # All the modules the initrd needs to mount the host filesystem via
# CIFS. Also use paravirtualised network and block devices for # CIFS. Also use paravirtualised network and block devices for
# performance. # performance.
boot.initrd.kernelModules = boot.initrd.availableKernelModules =
["cifs" "virtio_net" "virtio_pci" "virtio_blk" "virtio_balloon" "nls_utf8"]; [ "cifs" "virtio_net" "virtio_pci" "virtio_blk" "virtio_balloon" "nls_utf8" ];
boot.initrd.extraUtilsCommands = boot.initrd.extraUtilsCommands =
'' ''