* 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:
parent
412fcfe2f7
commit
a94dd5c8b1
|
@ -26,7 +26,7 @@ mount -t sysfs sys /sys
|
||||||
source @makeDevices@
|
source @makeDevices@
|
||||||
|
|
||||||
# Load some kernel modules.
|
# Load some kernel modules.
|
||||||
export MODULE_DIR=@kernel@/lib/modules/
|
export MODULE_DIR=@modules@/lib/modules/
|
||||||
modprobe ide-generic
|
modprobe ide-generic
|
||||||
modprobe ide-disk
|
modprobe ide-disk
|
||||||
modprobe ide-cd
|
modprobe ide-cd
|
||||||
|
|
|
@ -5,17 +5,17 @@
|
||||||
# is supposed to be put into an initial RAM disk (initrd).
|
# is supposed to be put into an initial RAM disk (initrd).
|
||||||
|
|
||||||
{ genericSubstituter, shell, staticTools
|
{ genericSubstituter, shell, staticTools
|
||||||
, module_init_tools, utillinux, kernel
|
, module_init_tools, utillinux, modules
|
||||||
}:
|
}:
|
||||||
|
|
||||||
genericSubstituter {
|
genericSubstituter {
|
||||||
src = ./boot-stage-1-init.sh;
|
src = ./boot-stage-1-init.sh;
|
||||||
isExecutable = true;
|
isExecutable = true;
|
||||||
inherit shell kernel;
|
inherit shell modules;
|
||||||
path = [
|
path = [
|
||||||
staticTools
|
staticTools
|
||||||
module_init_tools
|
module_init_tools
|
||||||
utillinux
|
# utillinux
|
||||||
];
|
];
|
||||||
makeDevices = ./make-devices.sh;
|
makeDevices = ./make-devices.sh;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"];
|
||||||
|
}
|
|
@ -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
|
||||||
|
|
|
@ -11,21 +11,20 @@ rec {
|
||||||
allPackages = import ./pkgs/top-level/all-packages.nix;
|
allPackages = import ./pkgs/top-level/all-packages.nix;
|
||||||
};
|
};
|
||||||
|
|
||||||
bash = pkgs.bash;
|
|
||||||
|
|
||||||
|
|
||||||
# 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 = import ./modules-closure.nix {
|
modulesClosure = import ./modules-closure.nix {
|
||||||
inherit (pkgs) stdenv kernel;
|
inherit (pkgs) stdenv kernel module_init_tools;
|
||||||
rootModules = "ide-cd";
|
rootModules = ["ide-cd" "ide-disk" "ide-generic"];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
# The init script of boot stage 1 (loading kernel modules for
|
# The init script of boot stage 1 (loading kernel modules for
|
||||||
# mounting the root FS).
|
# mounting the root FS).
|
||||||
bootStage1 = import ./boot-stage-1.nix {
|
bootStage1 = import ./boot-stage-1.nix {
|
||||||
inherit (pkgs) genericSubstituter
|
inherit (pkgs) genericSubstituter utillinux;
|
||||||
module_init_tools utillinux kernel;
|
inherit (pkgsDiet) module_init_tools;
|
||||||
|
modules = modulesClosure;
|
||||||
shell = stdenvLinuxStuff.bootstrapTools.bash;
|
shell = stdenvLinuxStuff.bootstrapTools.bash;
|
||||||
staticTools = stdenvLinuxStuff.staticTools;
|
staticTools = stdenvLinuxStuff.staticTools;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue