* Use the tools from klibc in the initrd instead of the static-tools.

This makes the initrd a few megabytes smaller.
* Use run-init from klibc to delete everything in the initrd ramfs
  prior to switching to the real root FS.
* Removed the stage2Init argument.

svn path=/nixos/trunk/; revision=12544
This commit is contained in:
Eelco Dolstra 2008-08-08 15:49:57 +00:00
parent 2bcb5a8efe
commit 4d6548e94c
4 changed files with 48 additions and 52 deletions

View file

@ -26,7 +26,7 @@ done
# Mount special file systems.
mkdir -p /etc # to shut up mount
touch /etc/fstab # idem
echo -n > /etc/fstab # idem
mkdir -p /proc
mount -t proc none /proc
mkdir -p /sys
@ -34,7 +34,7 @@ mount -t sysfs none /sys
# Process the kernel command line.
stage2Init=@stage2Init@
stage2Init=
for o in $(cat /proc/cmdline); do
case $o in
init=*)
@ -66,6 +66,10 @@ for i in @modules@; do
done
# Create /dev/null.
mknod /dev/null c 1 3
# Try to resume - all modules are loaded now.
if test -e /sys/power/tuxonice/resume; then
if test -n "$(cat /sys/power/tuxonice/resume)"; then
@ -74,14 +78,14 @@ if test -e /sys/power/tuxonice/resume; then
fi
fi
echo "@resumeDevice@" > /sys/power/resume || echo "Failed to resume..."
echo "@resumeDevice@" > /sys/power/resume 2> /dev/null || echo "Failed to resume..."
echo shutdown > /sys/power/disk
# Create device nodes in /dev.
mknod -m 0666 /dev/null c 1 3
export UDEV_CONFIG_FILE=/udev.conf
echo 'udev_rules="/no-rules"' > $UDEV_CONFIG_FILE
echo -n > /no-rules
udevd --daemon
udevadm trigger
udevadm settle
@ -122,8 +126,7 @@ mountFS() {
if test $(($fsckResult | 2)) = $fsckResult; then
echo "fsck finished, rebooting..."
sleep 3
# reboot -f -d !!! don't have reboot yet
fail
reboot
fi
if test $(($fsckResult | 4)) = $fsckResult; then
@ -138,13 +141,12 @@ mountFS() {
fi
# Mount read-writable.
mount -n -t "$fsType" -o "$options" "$device" /mnt/root$mountPoint || fail
mount -t "$fsType" -o "$options" "$device" /mnt-root$mountPoint || fail
}
# Try to find and mount the root device.
mkdir /mnt
mkdir /mnt/root
mkdir /mnt-root
echo "mounting the root device.... (fix: sleeping 5 seconds to wait for upcoming usb drivers)"
sleep 5
@ -157,22 +159,22 @@ if test -n "@autoDetectRootDevice@"; then
for i in /sys/block/*; do
if test "$(cat $i/removable)" = "1"; then
echo " in $(basename $i)..."
echo " in $i..."
set -- $(IFS=: ; echo $(cat $i/dev))
major="$1"
minor="$2"
# Create a device node for this device.
rm -f /dev/tmpdev
nuke /dev/tmpdev # don't have `rm' in klibc
mknod /dev/tmpdev b "$major" "$minor"
if mount -n -o ro -t iso9660 /dev/tmpdev /mnt/root; then
if test -e "/mnt/root/@rootLabel@"; then
if mount -o ro -t iso9660 /dev/tmpdev /mnt-root; then
if test -e "/mnt-root/@rootLabel@"; then
found=1
break
fi
umount /mnt/root
umount /mnt-root
fi
fi
@ -198,7 +200,7 @@ else
options=${optionss[$n]}
# !!! Really quick hack to support bind mounts, i.e., where
# the "device" should be taken relative to /mnt/root, not /.
# the "device" should be taken relative to /mnt-root, not /.
# Assume that every device that start with / but doesn't
# start with /dev or LABEL= is a bind mount.
case $device in
@ -207,7 +209,7 @@ else
LABEL=*)
;;
/*)
device=/mnt/root$device
device=/mnt-root$device
;;
esac
@ -221,30 +223,30 @@ fi
# If this is a live-CD/DVD, then union-mount a tmpfs on top of the
# original root.
targetRoot=/mnt/root
targetRoot=/mnt-root
if test -n "@isLiveCD@"; then
mkdir /mnt/tmpfs
mount -n -t tmpfs -o "mode=755" none /mnt/tmpfs
mkdir /mnt/union
mount -t aufs -o dirs=/mnt/tmpfs=rw:$targetRoot=ro none /mnt/union
targetRoot=/mnt/union
mkdir /mnt-tmpfs
mount -t tmpfs -o "mode=755" none /mnt-tmpfs
mkdir /mnt-union
mount -t aufs -o dirs=/mnt-tmpfs=rw:$targetRoot=ro none /mnt-union
targetRoot=/mnt-union
fi
if test -n "$debug1mounts"; then fail; fi
# Start stage 2.
# !!! Note: we can't use pivot_root here (the kernel gods have
# decreed), but we could use run-init from klibc, which deletes all
# files in the initramfs, remounts the target root on /, and chroots.
cd "$targetRoot"
mount --move . /
umount /proc # cleanup
umount /sys
# `run-init' needs a /dev/console on the target FS.
if ! test -e $targetRoot/dev/console; then
mkdir -p $targetRoot/dev
mknod $targetRoot/dev/console c 5 1
fi
# Start stage 2. `run-init' deletes all files in the ramfs on the
# current /.
if test -z "$stage2Init"; then fail; fi
exec chroot . $stage2Init
umount /sys
umount /proc
exec run-init "$targetRoot" "$stage2Init"
fail

View file

@ -4,7 +4,7 @@
# the second boot stage. The closure of the result of this expression
# is supposed to be put into an initial RAM disk (initrd).
{ substituteAll, staticShell, staticTools
{ substituteAll, staticShell, klibcShrunk
, module_init_tools, extraUtils, modules, modulesDir
, # Whether to find root device automatically using its label.
@ -27,10 +27,6 @@
# through a unionfs.
isLiveCD
, # The path of the stage 2 init to call once we've mounted the root
# device.
stage2Init ? "/init"
, # Resume device. [major]:[minor]
resumeDevice ? "ignore-this"
}:
@ -49,18 +45,18 @@ if !autoDetectRootDevice && mountPoints == [] then abort "You must specify the f
substituteAll {
src = ./boot-stage-1-init.sh;
isExecutable = true;
inherit staticShell modules modulesDir;
inherit autoDetectRootDevice isLiveCD mountPoints devices fsTypes optionss resumeDevice;
rootLabel = if autoDetectRootDevice then rootLabel else "";
path = [
staticTools
module_init_tools
extraUtils
module_init_tools
klibcShrunk
];
# We only want the path of the stage 2 init, we don't want it as a
# dependency (since then it the stage 2 init would end up in the
# initrd).
stage2Init = toString stage2Init; # !!! doesn't work
}

View file

@ -20,7 +20,7 @@ rec {
extraTTYs = [7 8]; # manual, rogue
extraModulePackages = pkgs: [system.kernelPackages.aufs];
#kernelPackages = pkgs: pkgs.kernelPackages_2_6_25;
kernelPackages = pkgs: pkgs.kernelPackages_2_6_25;
initrd = {
extraKernelModules = [
@ -187,7 +187,6 @@ rec {
system = import ../system/system.nix {
inherit configuration platform nixpkgsPath;
stage2Init = "/init";
};
@ -237,7 +236,7 @@ rec {
chainloader +1
title NixOS Installer / Rescue
kernel /boot/vmlinuz ${toString system.config.boot.kernelParams}
kernel /boot/vmlinuz init=/init ${toString system.config.boot.kernelParams}
initrd /boot/initrd
title Memtest86+

View file

@ -1,5 +1,4 @@
{ platform ? __currentSystem
, stage2Init ? ""
, configuration
, nixpkgsPath ? ../../nixpkgs
}:
@ -110,17 +109,16 @@ rec {
inherit (pkgs) substituteAll;
inherit (pkgsDiet) module_init_tools;
inherit extraUtils;
inherit (kernelPackages) klibcShrunk;
inherit (config.boot) autoDetectRootDevice isLiveCD;
fileSystems =
pkgs.lib.filter
(fs: fs.mountPoint == "/" || (fs ? neededForBoot && fs.neededForBoot))
config.fileSystems;
rootLabel = config.boot.rootLabel;
inherit stage2Init;
modulesDir = modulesClosure;
modules = rootModules;
staticShell = stdenvLinuxStuff.bootstrapTools.bash;
staticTools = stdenvLinuxStuff.staticTools;
resumeDevice = config.boot.resumeDevice;
};
@ -446,8 +444,9 @@ rec {
pkgs.diffutils
pkgs.upstart # for initctl
];
# !!! wtf does this do???
children = map (x: ((import ./system.nix)
{inherit platform stage2Init;
{ inherit platform;
configuration = x//{boot=((x.boot)//{grubDevice = "";});};}).system)
config.nesting.children;
configurationName = config.boot.configurationName;