* Given a kernel build (with modules in $kernel/lib/modules/VERSION),

`modules-closure.nix' produces a module tree in
  $out/lib/modules/VERSION that contains only the modules identified
  by `rootModules', plus their dependencies.  It also generates an
  appropriate modules.dep.  This is useful for initrds, as we
  obviously don't want a copy of the entire kernel module tree in the
  initial RAM disk.

svn path=/nixu/trunk/; revision=6939
This commit is contained in:
Eelco Dolstra 2006-11-03 11:47:40 +00:00
parent 412fcfe2f7
commit a94dd5c8b1
5 changed files with 59 additions and 10 deletions

View file

@ -26,7 +26,7 @@ mount -t sysfs sys /sys
source @makeDevices@
# Load some kernel modules.
export MODULE_DIR=@kernel@/lib/modules/
export MODULE_DIR=@modules@/lib/modules/
modprobe ide-generic
modprobe ide-disk
modprobe ide-cd

View file

@ -5,17 +5,17 @@
# is supposed to be put into an initial RAM disk (initrd).
{ genericSubstituter, shell, staticTools
, module_init_tools, utillinux, kernel
, module_init_tools, utillinux, modules
}:
genericSubstituter {
src = ./boot-stage-1-init.sh;
isExecutable = true;
inherit shell kernel;
inherit shell modules;
path = [
staticTools
module_init_tools
utillinux
# utillinux
];
makeDevices = ./make-devices.sh;
}

13
test/modules-closure.nix Normal file
View file

@ -0,0 +1,13 @@
# Given a kernel build (with modules in $kernel/lib/modules/VERSION),
# produce a module tree in $out/lib/modules/VERSION that contains only
# the modules identified by `rootModules', plus their dependencies.
# Also generate an appropriate modules.dep.
{stdenv, kernel, rootModules, module_init_tools}:
stdenv.mkDerivation {
name = kernel.name + "-shrunk";
builder = ./modules-closure.sh;
inherit kernel rootModules module_init_tools;
allowedReferences = ["out"];
}

37
test/modules-closure.sh Normal file
View file

@ -0,0 +1,37 @@
source $stdenv/setup
set -o pipefail
PATH=$module_init_tools/sbin:$PATH
version=$(cd $kernel/lib/modules && ls -d *)
echo "kernel version is $version"
export MODULE_DIR=$kernel/lib/modules/
# Determine the dependencies of each root module.
closure=
for module in $rootModules; do
echo "root module: $module"
deps=$(modprobe --set-version "$version" --show-depends "$module" \
| sed 's/^insmod //')
for i in $deps; do echo $i; done
closure="$closure $deps"
done
# Remove duplicates.
closure=$(for i in $closure; do echo $i; done | sort | uniq)
echo "closure:"
ensureDir $out
for module in $closure; do
echo $module
target=$(echo $module | sed "s^$kernel^$out^")
mkdir -p $(dirname $target)
cp $module $target
grep "^$module" $kernel/lib/modules/$version/modules.dep \
| sed "s^$kernel^$out^g" \
>> $out/lib/modules/$version/modules.dep
done

View file

@ -11,21 +11,20 @@ rec {
allPackages = import ./pkgs/top-level/all-packages.nix;
};
bash = pkgs.bash;
# Determine the set of modules that we need to mount the root FS.
modulesClosure = import ./modules-closure.nix {
inherit (pkgs) stdenv kernel;
rootModules = "ide-cd";
inherit (pkgs) stdenv kernel module_init_tools;
rootModules = ["ide-cd" "ide-disk" "ide-generic"];
};
# The init script of boot stage 1 (loading kernel modules for
# mounting the root FS).
bootStage1 = import ./boot-stage-1.nix {
inherit (pkgs) genericSubstituter
module_init_tools utillinux kernel;
inherit (pkgs) genericSubstituter utillinux;
inherit (pkgsDiet) module_init_tools;
modules = modulesClosure;
shell = stdenvLinuxStuff.bootstrapTools.bash;
staticTools = stdenvLinuxStuff.staticTools;
};