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

View File

@ -4,7 +4,7 @@
# the second boot stage. The closure of the result of this expression # the second boot stage. The closure of the result of this expression
# is supposed to be put into an initial RAM disk (initrd). # is supposed to be put into an initial RAM disk (initrd).
{ substituteAll, staticShell, staticTools { substituteAll, staticShell, klibcShrunk
, module_init_tools, extraUtils, modules, modulesDir , module_init_tools, extraUtils, modules, modulesDir
, # Whether to find root device automatically using its label. , # Whether to find root device automatically using its label.
@ -27,10 +27,6 @@
# through a unionfs. # through a unionfs.
isLiveCD isLiveCD
, # The path of the stage 2 init to call once we've mounted the root
# device.
stage2Init ? "/init"
, # Resume device. [major]:[minor] , # Resume device. [major]:[minor]
resumeDevice ? "ignore-this" resumeDevice ? "ignore-this"
}: }:
@ -49,18 +45,18 @@ if !autoDetectRootDevice && mountPoints == [] then abort "You must specify the f
substituteAll { substituteAll {
src = ./boot-stage-1-init.sh; src = ./boot-stage-1-init.sh;
isExecutable = true; isExecutable = true;
inherit staticShell modules modulesDir; inherit staticShell modules modulesDir;
inherit autoDetectRootDevice isLiveCD mountPoints devices fsTypes optionss resumeDevice; inherit autoDetectRootDevice isLiveCD mountPoints devices fsTypes optionss resumeDevice;
rootLabel = if autoDetectRootDevice then rootLabel else ""; rootLabel = if autoDetectRootDevice then rootLabel else "";
path = [ path = [
staticTools
module_init_tools
extraUtils 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 extraTTYs = [7 8]; # manual, rogue
extraModulePackages = pkgs: [system.kernelPackages.aufs]; extraModulePackages = pkgs: [system.kernelPackages.aufs];
#kernelPackages = pkgs: pkgs.kernelPackages_2_6_25; kernelPackages = pkgs: pkgs.kernelPackages_2_6_25;
initrd = { initrd = {
extraKernelModules = [ extraKernelModules = [
@ -187,7 +187,6 @@ rec {
system = import ../system/system.nix { system = import ../system/system.nix {
inherit configuration platform nixpkgsPath; inherit configuration platform nixpkgsPath;
stage2Init = "/init";
}; };
@ -237,7 +236,7 @@ rec {
chainloader +1 chainloader +1
title NixOS Installer / Rescue 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 initrd /boot/initrd
title Memtest86+ title Memtest86+

View File

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