From 3514c5658b7a8d618ef3babdf54377bf17406689 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 18 Feb 2004 14:56:32 +0000 Subject: [PATCH] * Proper sysvinit boot/halt. At runlevel 2, creates login shells at virtual consoles 0 and 1. To shutdown, do `init 0' (`halt' and `shutdown' don't work because they call /sbin/init). svn path=/nixu/trunk/; revision=803 --- boot/{init.sh => boot.sh} | 13 +------------ boot/builder.sh | 24 +++++++++++++----------- boot/default.nix | 6 ++++-- boot/halt.sh | 12 ++++++++++++ boot/login.sh | 15 +++++++++++++++ fill-disk.sh | 7 +++++-- make-disk.sh | 6 +++--- pkgs.nix | 4 ++-- 8 files changed, 55 insertions(+), 32 deletions(-) rename boot/{init.sh => boot.sh} (65%) create mode 100644 boot/halt.sh create mode 100644 boot/login.sh diff --git a/boot/init.sh b/boot/boot.sh similarity index 65% rename from boot/init.sh rename to boot/boot.sh index e34a516c6de4..3f17ea32ac00 100644 --- a/boot/init.sh +++ b/boot/boot.sh @@ -16,15 +16,4 @@ mount -n -o remount,rw /dev/root / echo "mounting /mnt/host..." mount -n -t hostfs none /mnt/host -echo "starting root shell..." - -@bash@/bin/sh - -echo "remounting / read-only..." -mount -n -o remount,rw /dev/root / || echo "(failed)" # ignore errors - -echo "syncing..." -sync || echo "(failed)" # ignore errors - -echo "shutting down..." -halt -d -f +echo "boot done." diff --git a/boot/builder.sh b/boot/builder.sh index a12da5342b14..902940dc9075 100755 --- a/boot/builder.sh +++ b/boot/builder.sh @@ -5,14 +5,16 @@ mkdir $out mkdir $out/bin -sed \ - -e "s^@bash\@^$bash^g" \ - -e "s^@coreutils\@^$coreutils^g" \ - -e "s^@findutils\@^$findutils^g" \ - -e "s^@utillinux\@^$utillinux^g" \ - -e "s^@sysvinit\@^$sysvinit^g" \ - -e "s^@e2fsprogs\@^$e2fsprogs^g" \ - -e "s^@nix\@^$nix^g" \ - < $src > $out/bin/init - -chmod +x $out/bin/init +for i in $boot $halt $login; do + dst=$out/bin/$(basename $i | cut -c34-) + sed \ + -e "s^@bash\@^$bash^g" \ + -e "s^@coreutils\@^$coreutils^g" \ + -e "s^@findutils\@^$findutils^g" \ + -e "s^@utillinux\@^$utillinux^g" \ + -e "s^@sysvinit\@^$sysvinit^g" \ + -e "s^@e2fsprogs\@^$e2fsprogs^g" \ + -e "s^@nix\@^$nix^g" \ + < $i > $dst + chmod +x $dst +done \ No newline at end of file diff --git a/boot/default.nix b/boot/default.nix index c49891d593f5..8f6820c5e4ac 100644 --- a/boot/default.nix +++ b/boot/default.nix @@ -1,9 +1,11 @@ {stdenv, bash, coreutils, findutils, utillinux, sysvinit, e2fsprogs, nix}: derivation { - name = "init"; + name = "boot"; system = stdenv.system; builder = ./builder.sh; - src = ./init.sh; + boot = ./boot.sh; + halt = ./halt.sh; + login = ./login.sh; inherit stdenv bash coreutils findutils utillinux sysvinit e2fsprogs nix; } diff --git a/boot/halt.sh b/boot/halt.sh new file mode 100644 index 000000000000..19e890458547 --- /dev/null +++ b/boot/halt.sh @@ -0,0 +1,12 @@ +#! @bash@/bin/sh -e + +export PATH=@nix@/bin:@bash@/bin:@coreutils@/bin:@findutils@/bin:@utillinux@/bin:@utillinux@/sbin:@sysvinit@/bin:@sysvinit@/sbin:@e2fsprogs@/bin:@e2fsprogs@/sbin + +echo "remounting / read-only..." +mount -n -o remount,rw /dev/root / || echo "(failed)" # ignore errors + +echo "syncing..." +sync || echo "(failed)" # ignore errors + +echo "shutting down..." +halt -d -f diff --git a/boot/login.sh b/boot/login.sh new file mode 100644 index 000000000000..74e14b64de6d --- /dev/null +++ b/boot/login.sh @@ -0,0 +1,15 @@ +#! @bash@/bin/sh -e + +tty=$1 + +exec < $tty > $tty 2>&1 + +export PATH=@nix@/bin:@bash@/bin:@coreutils@/bin:@findutils@/bin:@utillinux@/bin:@utillinux@/sbin:@sysvinit@/bin:@sysvinit@/sbin:@e2fsprogs@/bin:@e2fsprogs@/sbin + +echo +echo "=== Welcome to Nix! ===" + +export HOME=/home/root +cd $HOME + +exec @bash@/bin/sh diff --git a/fill-disk.sh b/fill-disk.sh index 8c9e3b6c8fd1..b50088e16e08 100755 --- a/fill-disk.sh +++ b/fill-disk.sh @@ -1,7 +1,7 @@ #! /bin/sh -e sysvinitPath=$1 -initPath=$2 +bootPath=$2 make_dir() { mode=$1 @@ -66,7 +66,10 @@ ln -s $sysvinitPath/sbin/init $root/init echo setting up inittab... rm -f $root/etc/inittab echo "id:2:initdefault:" >> $root/etc/inittab -echo "si::bootwait:$initPath/bin/init" >> $root/etc/inittab +echo "si::bootwait:$bootPath/bin/boot.sh" >> $root/etc/inittab +echo "ht:06:wait:$bootPath/bin/halt.sh" >> $root/etc/inittab +echo "1:2345:respawn:$bootPath/bin/login.sh /dev/ttys/0" >> $root/etc/inittab +echo "2:2345:respawn:$bootPath/bin/login.sh /dev/ttys/1" >> $root/etc/inittab echo unmounting... umount $root diff --git a/make-disk.sh b/make-disk.sh index 498753d6fbbc..00e3cb28de1d 100755 --- a/make-disk.sh +++ b/make-disk.sh @@ -30,10 +30,10 @@ done) < $storePaths > $successors # Location of sysvinit? sysvinitPath=$(nix-store -qn $(echo '(import ./pkgs.nix).sysvinit' | nix-instantiate -)) -# Location of Nix init? -initPath=$(nix-store -qn $(echo '(import ./pkgs.nix).init' | nix-instantiate -)) +# Location of Nix boot scripts? +bootPath=$(nix-store -qn $(echo '(import ./pkgs.nix).boot' | nix-instantiate -)) # Fill the disk with the minimal Nix store. if ! test -d /tmp/mnt; then mkdir /tmp/mnt; fi linux ubd0=$image root=/dev/root rootflags=/ rootfstype=hostfs \ - init="$(pwd)/fill-disk.sh $sysvinitPath $initPath" + init="$(pwd)/fill-disk.sh $sysvinitPath $bootPath" diff --git a/pkgs.nix b/pkgs.nix index d0314a6b3001..d0df974d9024 100644 --- a/pkgs.nix +++ b/pkgs.nix @@ -2,8 +2,8 @@ rec { inherit (import pkgs/system/i686-linux.nix) stdenv bash coreutils findutils utillinux sysvinit e2fsprogs nix; - init = (import ./init) + boot = (import ./boot) {inherit stdenv bash coreutils findutils utillinux sysvinit e2fsprogs nix;}; - everything = [init sysvinit]; + everything = [boot sysvinit]; }