Skip to content

Commit

Permalink
* Substitute the path of the system derivation directly in the stage 2
Browse files Browse the repository at this point in the history
  init script.  This removes the need for the `systemConfig' boot
  parameter; `init=<stage-2-init>' is enough.  However, the GRUB menu
  builder still needs to add `systemConfig' to the kernel command line
  for compatibility with old configurations.

svn path=/nixos/trunk/; revision=23775
  • Loading branch information
edolstra committed Sep 13, 2010
1 parent 4046056 commit c4f910f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 38 deletions.
10 changes: 4 additions & 6 deletions modules/installer/cd-dvd/iso-image.nix
Expand Up @@ -174,11 +174,9 @@ in
# Closures to be copied to the Nix store on the CD, namely the init
# script and the top-level system configuration directory.
isoImage.storeContents =
[ config.system.build.bootStage2
config.system.build.toplevel
] ++
(optional config.isoImage.includeSystemBuildDependencies
config.system.build.toplevel.drvPath);
[ config.system.build.toplevel ] ++
optional config.isoImage.includeSystemBuildDependencies
config.system.build.toplevel.drvPath;

# Create the squashfs image that contains the Nix store.
system.build.squashfsStore = import ../../../lib/make-squashfs.nix {
Expand Down Expand Up @@ -220,7 +218,7 @@ in
boot.loader.grub.extraEntries =
''
menuentry "NixOS Installer / Rescue" {
linux /boot/bzImage init=${config.system.build.bootStage2} systemConfig=${config.system.build.toplevel} ${toString config.boot.kernelParams}
linux /boot/bzImage init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams}
initrd /boot/initrd
}
Expand Down
10 changes: 2 additions & 8 deletions modules/installer/cd-dvd/system-tarball.nix
Expand Up @@ -34,8 +34,7 @@ let
# A clue for the uboot loading
ubootKernelParams = pkgs.writeText "uboot-kernel-params.txt" ''
Kernel Parameters:
init=${config.system.build.bootStage2}
systemConfig=${config.system.build.toplevel}
init=${config.system.build.toplevel}/init
${toString config.boot.kernelParams}
'';

Expand Down Expand Up @@ -70,12 +69,7 @@ in
# Closures to be copied to the Nix store on the CD, namely the init
# script and the top-level system configuration directory.
tarball.storeContents =
[ {
object = config.system.build.bootStage2;
symlink = "none";
}
{
object = config.system.build.toplevel;
[ { object = config.system.build.toplevel;
symlink = "/var/run/current-system";
}
];
Expand Down
4 changes: 3 additions & 1 deletion modules/system/activation/top-level.nix
Expand Up @@ -103,13 +103,15 @@ let
ln -s $grub $out/grub
fi
ln -s ${config.system.build.bootStage2} $out/init
ln -s ${config.system.build.initialRamdisk}/initrd $out/initrd
echo "$activationScript" > $out/activate
substituteInPlace $out/activate --subst-var out
chmod u+x $out/activate
unset activationScript
cp ${config.system.build.bootStage2} $out/init
substituteInPlace $out/init --subst-var-by systemConfig $out
ln -s ${config.system.build.etc}/etc $out/etc
ln -s ${config.system.path} $out/sw
Expand Down
30 changes: 8 additions & 22 deletions modules/system/boot/stage-2-init.sh
@@ -1,6 +1,6 @@
#! @shell@

# !!! copied from stage 1; remove duplication
systemConfig=@systemConfig@


# Print a greeting.
Expand Down Expand Up @@ -56,11 +56,6 @@ rm -f /etc/mtab* # not that we care about stale locks
cat /proc/mounts > /etc/mtab


# If no `systemConfig' parameter is specified on the kernel command
# line, use a fallback.
systemConfig=/nix/var/nix/profiles/system


# Process the kernel command line.
for o in $(cat /proc/cmdline); do
case $o in
Expand All @@ -79,19 +74,13 @@ for o in $(cat /proc/cmdline); do
safemode)
safeMode=1
;;
systemConfig=*)
set -- $(IFS==; echo $o)
systemConfig=$2
;;
resume=*)
set -- $(IFS==; echo $o)
resumeDevice=$2
;;
esac
done

systemConfig="$(readlink -f "$systemConfig")"


# More special file systems, initialise required directories.
mkdir -m 0777 /dev/shm
Expand Down Expand Up @@ -153,19 +142,16 @@ fi
# Run the script that performs all configuration activation that does
# not have to be done at boot time.
echo "running activation script..."
"$systemConfig"/activate
$systemConfig/activate


# Record the boot configuration.
if test -n "$systemConfig"; then
ln -sfn "$systemConfig" /var/run/booted-system

# Prevent the booted system form being garbage-collected
# If it weren't a gcroot, if we were running a different kernel,
# switched system, and garbage collected all, we could not load
# kernel modules anymore.
ln -sfn /var/run/booted-system /nix/var/nix/gcroots/booted-system
fi
ln -sfn "$systemConfig" /var/run/booted-system

# Prevent the booted system form being garbage-collected If it weren't
# a gcroot, if we were running a different kernel, switched system,
# and garbage collected all, we could not load kernel modules anymore.
ln -sfn /var/run/booted-system /nix/var/nix/gcroots/booted-system


# Ensure that the module tools can find the kernel modules.
Expand Down
2 changes: 1 addition & 1 deletion modules/virtualisation/qemu-vm.nix
Expand Up @@ -167,7 +167,7 @@ let
-drive file=$NIX_DISK_IMAGE,if=virtio,boot=on,cache=writeback,werror=report \
-kernel ${config.system.build.toplevel}/kernel \
-initrd ${config.system.build.toplevel}/initrd \
-append "$(cat ${config.system.build.toplevel}/kernel-params) init=${config.system.build.bootStage2} systemConfig=${config.system.build.toplevel} regInfo=${regInfo} ${kernelConsole} $QEMU_KERNEL_PARAMS" \
-append "$(cat ${config.system.build.toplevel}/kernel-params) init=${config.system.build.toplevel}/init regInfo=${regInfo} ${kernelConsole} $QEMU_KERNEL_PARAMS" \
''} \
${qemuGraphics} \
$QEMU_OPTS \
Expand Down

0 comments on commit c4f910f

Please sign in to comment.