diff --git a/test/boot-stage-1-init.sh b/test/boot-stage-1-init.sh index b9e2d1f4434..a2e958d91f6 100644 --- a/test/boot-stage-1-init.sh +++ b/test/boot-stage-1-init.sh @@ -1,5 +1,11 @@ #! @shell@ +fail() { + # If starting stage 2 failed, start an interactive shell. + echo "Stage 2 failed, starting emergency shell..." + exec @shell@ +} + # Print a greeting. echo echo "<<< NixOS Stage 1 >>>" @@ -31,10 +37,37 @@ modprobe ide-generic modprobe ide-disk modprobe ide-cd +# Try to find and mount the installation CD. + # Mount the installation CD. mkdir /mnt mkdir /mnt/cdrom -mount -o ro /dev/hdc /mnt/cdrom + +echo "probing for the NixOS installation CD..." + +for i in /sys/devices/*/*/media; do + if test "$(cat $i)" = "cdrom"; then + + # Hopefully `drivename' matches the device created in /dev. + devName=/dev/$(cat $(dirname $i)/drivename) + + echo " in $devName..." + + if mount -o ro -t iso9660 $devName /mnt/cdrom; then + if test -e "/mnt/cdrom/@cdromLabel@"; then + found=1 + break + fi + umount /mnt/cdrom + fi + + fi +done + +if test -z "$found"; then + echo "CD not found!" + fail +fi # Start stage 2. # !!! Note: we can't use pivot_root here (the kernel gods have @@ -46,6 +79,4 @@ umount /proc # cleanup umount /sys exec chroot . /init -# If starting stage 2 failed, start an interactive shell. -echo "Stage 2 failed, starting emergency shell..." -exec @shell@ +fail diff --git a/test/boot-stage-1.nix b/test/boot-stage-1.nix index 329ca513a95..0f714a6d599 100644 --- a/test/boot-stage-1.nix +++ b/test/boot-stage-1.nix @@ -6,12 +6,13 @@ { genericSubstituter, shell, staticTools , module_init_tools, extraUtils, modules +, cdromLabel ? "" }: genericSubstituter { src = ./boot-stage-1-init.sh; isExecutable = true; - inherit shell modules; + inherit shell modules cdromLabel; path = [ staticTools module_init_tools diff --git a/test/boot-stage-2-init.sh b/test/boot-stage-2-init.sh index 8235715e09e..be54926aabc 100644 --- a/test/boot-stage-2-init.sh +++ b/test/boot-stage-2-init.sh @@ -106,6 +106,9 @@ export PATH=$PATH export MODULE_DIR=$MODULE_DIR EOF +# Set the host name. +hostname nixos + # Start an interactive shell. #exec @shell@ diff --git a/test/rescue-system.nix b/test/rescue-system.nix index 4e22ecb4d89..097ca084b29 100644 --- a/test/rescue-system.nix +++ b/test/rescue-system.nix @@ -20,6 +20,10 @@ rec { }; + # The label used to identify the installation CD. + cdromLabel = "NIXOS"; + + # Determine the set of modules that we need to mount the root FS. modulesClosure = import ./modules-closure.nix { inherit (pkgs) stdenv kernel module_init_tools; @@ -45,6 +49,7 @@ rec { inherit (pkgs) genericSubstituter; inherit (pkgsDiet) module_init_tools; inherit extraUtils; + inherit cdromLabel; modules = modulesClosure; shell = stdenvLinuxStuff.bootstrapTools.bash; staticTools = stdenvLinuxStuff.staticTools; @@ -110,8 +115,13 @@ rec { # Since the CD is read-only, the mount points must be on disk. cdMountPoints = pkgs.stdenv.mkDerivation { name = "mount-points"; - builder = builtins.toFile "builder.sh" - "source $stdenv/setup; mkdir $out; cd $out; mkdir proc sys tmp etc dev var mnt nix nix/var"; + builder = builtins.toFile "builder.sh" " + source $stdenv/setup + mkdir $out + cd $out + mkdir proc sys tmp etc dev var mnt nix nix/var + touch $out/${cdromLabel} + "; };