* Use sh from klibc in the initrd. svn path=/nixpkgs/trunk/; revision=11154wip/yesman
parent
ed9107e33c
commit
3ee0b9bb74
@ -0,0 +1,31 @@ |
||||
# Create an initial ramdisk containing the closure of the specified |
||||
# file system objects. An initial ramdisk is used during the initial |
||||
# stages of booting a Linux system. It is loaded by the boot loader |
||||
# along with the kernel image. It's supposed to contain everything |
||||
# (such as kernel modules) necessary to allow us to mount the root |
||||
# file system. Once the root file system is mounted, the `real' boot |
||||
# script can be called. |
||||
# |
||||
# An initrd is really just a gzipped cpio archive. |
||||
# |
||||
# Symlinks are created for each top-level file system object. E.g., |
||||
# `contents = {object = ...; symlink = /init;}' is a typical |
||||
# argument. |
||||
|
||||
{stdenv, perl, cpio, contents}: |
||||
|
||||
stdenv.mkDerivation { |
||||
name = "initrd"; |
||||
builder = ./make-initrd.sh; |
||||
buildInputs = [perl cpio]; |
||||
|
||||
# !!! should use XML. |
||||
objects = map (x: x.object) contents; |
||||
symlinks = map (x: x.symlink) contents; |
||||
suffices = map (x: if x ? suffix then x.suffix else "none") contents; |
||||
|
||||
# For obtaining the closure of `contents'. |
||||
exportReferencesGraph = |
||||
map (x: [("closure-" + baseNameOf x.symlink) x.object]) contents; |
||||
pathsFromGraph = ./paths-from-graph.pl; |
||||
} |
@ -0,0 +1,39 @@ |
||||
source $stdenv/setup |
||||
|
||||
set -o pipefail |
||||
|
||||
objects=($objects) |
||||
symlinks=($symlinks) |
||||
suffices=($suffices) |
||||
|
||||
mkdir root |
||||
|
||||
# Needed for splash_helper, which gets run before init. |
||||
mkdir root/dev |
||||
mkdir root/sys |
||||
mkdir root/proc |
||||
|
||||
|
||||
for ((n = 0; n < ${#objects[*]}; n++)); do |
||||
object=${objects[$n]} |
||||
symlink=${symlinks[$n]} |
||||
suffix=${suffices[$n]} |
||||
if test "$suffix" = none; then suffix=; fi |
||||
|
||||
mkdir -p $(dirname root/$symlink) |
||||
ln -s $object$suffix root/$symlink |
||||
done |
||||
|
||||
|
||||
# Get the paths in the closure of `object'. |
||||
storePaths=$(perl $pathsFromGraph closure-*) |
||||
|
||||
|
||||
# Paths in cpio archives *must* be relative, otherwise the kernel |
||||
# won't unpack 'em. |
||||
(cd root && cp -prd --parents $storePaths .) |
||||
|
||||
|
||||
# Put the closure in a gzipped cpio archive. |
||||
ensureDir $out |
||||
(cd root && find * -print0 | cpio -ov -H newc --null | gzip -9 > $out/initrd) |
@ -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,36 @@ |
||||
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 --config /dev/null --set-version "$version" --show-depends "$module" \ |
||||
| sed 's/^insmod //') |
||||
#for i in $deps; do echo $i; done |
||||
closure="$closure $deps" |
||||
done |
||||
|
||||
echo "closure:" |
||||
ensureDir $out |
||||
for module in $closure; do |
||||
target=$(echo $module | sed "s^$kernel^$out^") |
||||
if test -e "$target"; then continue; fi |
||||
echo $module |
||||
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 |
||||
echo $target >> $out/insmod-list |
||||
done |
||||
|
@ -0,0 +1,68 @@ |
||||
use strict; |
||||
use File::Basename; |
||||
|
||||
my %storePaths; |
||||
my %refs; |
||||
|
||||
foreach my $graph (@ARGV) { |
||||
open GRAPH, "<$graph" or die; |
||||
|
||||
while (<GRAPH>) { |
||||
chomp; |
||||
my $storePath = "$_"; |
||||
$storePaths{$storePath} = 1; |
||||
|
||||
my $deriver = <GRAPH>; chomp $deriver; |
||||
my $count = <GRAPH>; chomp $count; |
||||
|
||||
my @refs = (); |
||||
for (my $i = 0; $i < $count; ++$i) { |
||||
my $ref = <GRAPH>; chomp $ref; |
||||
push @refs, $ref; |
||||
} |
||||
$refs{$storePath} = \@refs; |
||||
|
||||
} |
||||
|
||||
close GRAPH; |
||||
} |
||||
|
||||
|
||||
if ($ENV{"printManifest"} eq "1") { |
||||
print "version {\n"; |
||||
print " ManifestVersion: 3\n"; |
||||
print "}\n"; |
||||
|
||||
foreach my $storePath (sort (keys %storePaths)) { |
||||
my $base = basename $storePath; |
||||
print "localPath {\n"; |
||||
print " StorePath: $storePath\n"; |
||||
print " CopyFrom: /tmp/inst-store/$base\n"; |
||||
print " References: "; |
||||
foreach my $ref (@{$refs{$storePath}}) { |
||||
print "$ref "; |
||||
} |
||||
print "\n"; |
||||
print "}\n"; |
||||
} |
||||
} |
||||
|
||||
elsif ($ENV{"printRegistration"} eq "1") { |
||||
# This is the format used by `nix-store --register-validity |
||||
# --hash-given' / `nix-store --load-db'. |
||||
foreach my $storePath (sort (keys %storePaths)) { |
||||
print "$storePath\n"; |
||||
print "0000000000000000000000000000000000000000000000000000000000000000\n"; # !!! fix |
||||
print "\n"; # don't care about preserving the deriver |
||||
print scalar(@{$refs{$storePath}}), "\n"; |
||||
foreach my $ref (@{$refs{$storePath}}) { |
||||
print "$ref\n"; |
||||
} |
||||
} |
||||
} |
||||
|
||||
else { |
||||
foreach my $storePath (sort (keys %storePaths)) { |
||||
print "$storePath\n"; |
||||
} |
||||
} |
Loading…
Reference in new issue