diff --git a/test/boot-stage-1-init.sh b/test/boot-stage-1-init.sh index 091dc4310de3..b9e2d1f44341 100644 --- a/test/boot-stage-1-init.sh +++ b/test/boot-stage-1-init.sh @@ -36,9 +36,15 @@ mkdir /mnt mkdir /mnt/cdrom mount -o ro /dev/hdc /mnt/cdrom -# Start stage 2. !!! We use chroot for now, but I guess that should -# be pivot_root or so. -chroot /mnt/cdrom /init +# 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 /mnt/cdrom +mount --move . / +umount /proc # cleanup +umount /sys +exec chroot . /init # If starting stage 2 failed, start an interactive shell. echo "Stage 2 failed, starting emergency shell..." diff --git a/test/boot-stage-2-init.sh b/test/boot-stage-2-init.sh index 02b440f5a369..28ed1d19de3c 100644 --- a/test/boot-stage-2-init.sh +++ b/test/boot-stage-2-init.sh @@ -23,6 +23,12 @@ mount -t proc none /proc mount -t sysfs none /sys mount -t tmpfs none /dev mount -t tmpfs none /tmp +mount -t tmpfs none /var +mount -t tmpfs none /nix/var + +mkdir -p /nix/var/nix/db +mkdir -p /nix/var/nix/gcroots +mkdir -p /nix/var/nix/temproots # Create device nodes in /dev. source @makeDevices@ @@ -38,5 +44,43 @@ for i in @extraPath@; do fi done +# Start syslogd. +mkdir -p /var/run +#mkdir -p /var/log +#touch /var/log/messages +echo "*.* /dev/tty10" > /etc/syslog.conf +echo "syslog 514/udp" > /etc/services # required, even if we don't use it +@sysklogd@/sbin/syslogd & + +# login/su absolutely need this. +touch /etc/login.defs + +# Enable a password-less root login. +echo "root::0:0:root:/:@shell@" > /etc/passwd +echo "root:*:0" > /etc/group + +cat > /etc/profile <> /etc/inittab +done + +# Show a nice greeting on each terminal. +cat > /etc/issue <>> + +You can log in as \`root'. + + +EOF + # Start an interactive shell. -exec @shell@ +#exec @shell@ + +# Start init. +exec init 2 diff --git a/test/boot-stage-2.nix b/test/boot-stage-2.nix index 8f68858f5368..f1aff2d59a9d 100644 --- a/test/boot-stage-2.nix +++ b/test/boot-stage-2.nix @@ -1,11 +1,12 @@ { genericSubstituter, shell, coreutils -, utillinux, kernel, path ? [] +, utillinux, kernel, sysklogd, mingetty +, path ? [] }: genericSubstituter { src = ./boot-stage-2-init.sh; isExecutable = true; - inherit shell kernel; + inherit shell kernel sysklogd mingetty; path = [ coreutils utillinux diff --git a/test/make-devices.sh b/test/make-devices.sh index dead9814f7a8..1e9f9719ea45 100644 --- a/test/make-devices.sh +++ b/test/make-devices.sh @@ -1,4 +1,3 @@ -#mknod -m 0600 /dev/console c 5 1 mknod -m 0600 /dev/ttyS0 c 4 64 mknod -m 0600 /dev/ttyS1 c 4 65 mknod -m 0600 /dev/ttyS2 c 4 66 @@ -11,16 +10,12 @@ mknod -m 0666 /dev/zero c 1 5 # tty mknod -m 0600 /dev/tty c 5 0 -mknod -m 0600 /dev/tty0 c 4 0 -mknod -m 0600 /dev/tty1 c 4 1 -mknod -m 0600 /dev/tty2 c 4 2 -mknod -m 0600 /dev/tty3 c 4 3 -mknod -m 0600 /dev/tty4 c 4 4 -mknod -m 0600 /dev/tty5 c 4 5 -mknod -m 0600 /dev/tty6 c 4 6 -mknod -m 0600 /dev/tty7 c 4 7 -mknod -m 0600 /dev/tty8 c 4 8 -mknod -m 0600 /dev/tty9 c 4 9 +if ! test -e /dev/console; then + mknod -m 0600 /dev/console c 5 1 +fi +for i in $(seq 0 10); do + mknod -m 0600 /dev/tty$i c 4 $i +done mkdir -m 0755 /dev/pts mknod -m 0666 /dev/ptmx c 5 2 diff --git a/test/rescue-system.nix b/test/rescue-system.nix index 216cf2009f98..044bf1a70654 100644 --- a/test/rescue-system.nix +++ b/test/rescue-system.nix @@ -33,7 +33,7 @@ rec { extraUtils = pkgs.stdenv.mkDerivation { name = "extra-utils"; builder = builtins.toFile "builder.sh" - "source $stdenv/setup; ensureDir $out/bin; cp $utillinux/bin/mount $out/bin; nuke-refs $out/bin/mount"; + "source $stdenv/setup; ensureDir $out/bin; cp $utillinux/bin/mount $utillinux/bin/umount $utillinux/sbin/pivot_root $out/bin; nuke-refs $out/bin/*"; buildInputs = [pkgs.nukeReferences]; inherit (pkgsStatic) utillinux; }; @@ -63,7 +63,8 @@ rec { # The init script of boot stage 2, which is supposed to do # everything else to bring up the system. bootStage2 = import ./boot-stage-2.nix { - inherit (pkgs) genericSubstituter coreutils utillinux kernel; + inherit (pkgs) genericSubstituter coreutils utillinux kernel + sysklogd; shell = pkgs.bash + "/bin/sh"; # Additional stuff; add whatever you want here. @@ -86,7 +87,15 @@ rec { pkgs.netcat pkgs.nettools pkgs.vim + pkgs.nix + pkgs.strace + pkgs.sysvinit + pkgs.procps + pkgs.shadowutils + pkgs.sysklogd ]; + + mingetty = pkgs.mingettyWrapper; }; @@ -94,12 +103,13 @@ rec { 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"; + "source $stdenv/setup; mkdir $out; cd $out; mkdir proc sys tmp etc dev var mnt nix nix/var"; }; # Create an ISO image containing the isolinux boot loader, the - # kernel, and initrd produced above. + # kernel, the initrd produced above, and the closure of the stage 2 + # init. rescueCD = import ./make-iso9660-image.nix { inherit (pkgs) stdenv cdrtools; isoName = "nixos.iso"; @@ -128,5 +138,5 @@ rec { bootImage = "isolinux/isolinux.bin"; }; - + }