From 6c9059e7178de44c6017438c3a464d4f312fe173 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 15 Dec 2009 16:38:20 +0000 Subject: [PATCH] * 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 --- .../installer/cd-dvd/installation-cd-base.nix | 6 +- modules/installer/cd-dvd/iso-image.nix | 2 +- modules/system/boot/kernel.nix | 103 +++++++++++------- modules/system/boot/stage-1-init.sh | 31 ++---- modules/system/boot/stage-1.nix | 56 +++++----- modules/virtualisation/qemu-vm.nix | 4 +- 6 files changed, 106 insertions(+), 96 deletions(-) diff --git a/modules/installer/cd-dvd/installation-cd-base.nix b/modules/installer/cd-dvd/installation-cd-base.nix index 428b262f75f..64eb4ee5b75 100644 --- a/modules/installer/cd-dvd/installation-cd-base.nix +++ b/modules/installer/cd-dvd/installation-cd-base.nix @@ -114,7 +114,7 @@ in # The initrd has to contain any module that might be necessary for # mounting the CD/DVD. - boot.initrd.kernelModules = + boot.initrd.availableKernelModules = [ # SATA/PATA support. "ahci" @@ -160,9 +160,11 @@ in "vfat" # 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 # installation. installer.nixpkgsURL = http://nixos.org/releases/nixpkgs/channels/nixpkgs-unstable; diff --git a/modules/installer/cd-dvd/iso-image.nix b/modules/installer/cd-dvd/iso-image.nix index 1d23acb36d1..e711a582334 100644 --- a/modules/installer/cd-dvd/iso-image.nix +++ b/modules/installer/cd-dvd/iso-image.nix @@ -128,7 +128,7 @@ in (! config.boot.kernelPackages.kernel.features ? 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 # AUFS. !!! It would be nicer to make the stage 1 init pluggable diff --git a/modules/system/boot/kernel.nix b/modules/system/boot/kernel.nix index 973fe33b09e..69b1b944de7 100644 --- a/modules/system/boot/kernel.nix +++ b/modules/system/boot/kernel.nix @@ -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 boot process. Note that modules that are needed to mount the root file system should be added to + or . ''; }; + 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 . + ''; + }; + boot.initrd.kernelModules = mkOption { 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 # detects them, but I'm keeping them for now for backwards # compatibility. @@ -100,50 +152,17 @@ let kernel = config.boot.kernelPackages.kernel; in "ohci_hcd" "usbhid" - # LVM. - "dm_mod" - - # All-mod-config case: + # Unix domain sockets (needed by udev). "unix" + + # Misc. stuff. "i8042" "pcips2" "serio" "atkbd" "xtkbd" ]; - 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. - ''; - }; - - 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.kernelModules = + [ # For LVM. + "dm_mod" + ]; # The Linux kernel >= 2.6.27 provides firmware. hardware.firmware = [ "${kernel}/lib/firmware" ]; diff --git a/modules/system/boot/stage-1-init.sh b/modules/system/boot/stage-1-init.sh index 182fe7e98e1..616f14156a4 100644 --- a/modules/system/boot/stage-1-init.sh +++ b/modules/system/boot/stage-1-init.sh @@ -3,6 +3,7 @@ targetRoot=/mnt-root export LD_LIBRARY_PATH=@extraUtils@/lib +export PATH=@extraUtils@/bin:@klibc@/bin fail() { @@ -43,16 +44,6 @@ echo "<<< NixOS Stage 1 >>>" 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. mkdir -p /etc # to shut up mount echo -n > /etc/fstab # idem @@ -87,10 +78,11 @@ for o in $(cat /proc/cmdline); do done -# Load some kernel modules. -for i in $(cat @modulesClosure@/insmod-list); do +# Load the required kernel modules. +echo @extraUtils@/bin/modprobe > /proc/sys/kernel/modprobe +for i in @kernelModules@; do echo "loading module $(basename $i)..." - insmod $i || true + modprobe $i || true done @@ -107,12 +99,13 @@ if test -e /sys/power/tuxonice/resume; then fi 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 shutdown > /sys/power/disk + echo "@resumeDevice@" > /sys/power/resume 2> /dev/null || echo "failed to resume..." + echo shutdown > /sys/power/disk fi # Create device nodes in /dev. +echo "running udev..." export UDEV_CONFIG_FILE=@udevConf@ mkdir -p /dev/.udev # !!! bug in udev? udevd --daemon @@ -120,10 +113,10 @@ udevadm trigger udevadm settle if type -p dmsetup > /dev/null; then - echo "starting device mapper and LVM..." - dmsetup mknodes - lvm vgscan --ignorelockingfailure - lvm vgchange -ay --ignorelockingfailure + echo "starting device mapper and LVM..." + dmsetup mknodes + lvm vgscan --ignorelockingfailure + lvm vgchange -ay --ignorelockingfailure fi if test -n "$debug1devices"; then fail; fi diff --git a/modules/system/boot/stage-1.nix b/modules/system/boot/stage-1.nix index 907f5b7260a..4b51ce1b024 100644 --- a/modules/system/boot/stage-1.nix +++ b/modules/system/boot/stage-1.nix @@ -3,7 +3,7 @@ # the modules necessary to mount the root file system, then calls the # init in the root file system to start the second boot stage. -{pkgs, config, ...}: +{ config, pkgs, ... }: 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 { default = true; description = " @@ -82,6 +73,7 @@ let }; boot.initrd.extraUtilsCommands = mkOption { + internal = true; default = ""; merge = pkgs.lib.mergeStringOption; description = '' @@ -110,9 +102,9 @@ let # Determine the set of modules that we need to mount the root FS. modulesClosure = pkgs.makeModulesClosure { - rootModules = config.boot.initrd.kernelModules; + rootModules = config.boot.initrd.availableKernelModules ++ config.boot.initrd.kernelModules; kernel = modulesTree; - allowMissing = config.boot.initrd.allowMissing; + allowMissing = true; }; @@ -125,7 +117,7 @@ let { buildInputs = [pkgs.nukeReferences]; devicemapper = if config.boot.initrd.lvm then pkgs.devicemapper 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"); } '' @@ -179,9 +171,9 @@ let cp ${pkgs.bash}/bin/bash $out/bin ln -s bash $out/bin/sh - # Copy insmod. - cp ${pkgs.module_init_tools}/sbin/insmod $out/bin - + # Copy modprobe. + cp ${pkgs.module_init_tools}/sbin/modprobe $out/bin/modprobe.real + ${config.boot.initrd.extraUtilsCommands} # Run patchelf to make the programs refer to the copied libraries. @@ -191,12 +183,20 @@ let if ! test -L $i; then echo "patching $i..." 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 fi fi done + # Make the modprobe wrapper that sets $MODULE_DIR. + cat > $out/bin/modprobe <