From 1e87e75d079c4d80bf6cba8b2d986894121b217f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 18 Feb 2004 10:56:07 +0000 Subject: [PATCH] * Use sysvinit's init to start the system. This has the happy side-effect of initialising the console properly (i.e., enabling Ctrl-[C, Z]). svn path=/nixu/trunk/; revision=801 --- fill-disk.sh | 20 +++++++++++++++++--- init/builder.sh | 4 ++++ init/default.nix | 4 ++-- init/init.sh | 25 ++++++++++++++++++++++--- make-disk.sh | 21 +++++++++++++-------- pkgs.nix | 9 +++++++-- 6 files changed, 65 insertions(+), 18 deletions(-) diff --git a/fill-disk.sh b/fill-disk.sh index b3c852ddb20..8c9e3b6c8fd 100755 --- a/fill-disk.sh +++ b/fill-disk.sh @@ -1,6 +1,7 @@ #! /bin/sh -e -initExpr=$1 +sysvinitPath=$1 +initPath=$2 make_dir() { mode=$1 @@ -18,6 +19,8 @@ mount -t ext2 /dev/discs/disc0/disc $root make_dir 00755 /dev make_dir 00755 /proc make_dir 01777 /tmp +make_dir 00755 /etc # global non-constant configuration +make_dir 00755 /var make_dir 00755 /nix make_dir 00755 /nix/store make_dir 00755 /nix/var @@ -25,6 +28,13 @@ make_dir 00755 /nix/var/nix make_dir 00755 /nix/var/nix/db make_dir 00755 /nix/var/log make_dir 00755 /nix/var/log/nix +make_dir 00755 /mnt +make_dir 00755 /mnt/host +make_dir 00755 /home +make_dir 00755 /home/root + +rm -f $root/etc/mtab +ln -s /proc/mounts $root/etc/mtab export NIX_ROOT=$root @@ -50,9 +60,13 @@ echo registering successors... done) < /tmp/successors echo setting init symlink... -initPath=$(/nix/bin/nix-store -qn $initExpr) rm -f $root/init -ln -s $initPath/bin/init $root/init +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 unmounting... umount $root diff --git a/init/builder.sh b/init/builder.sh index 5809ad62a30..a12da5342b1 100755 --- a/init/builder.sh +++ b/init/builder.sh @@ -9,6 +9,10 @@ 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 diff --git a/init/default.nix b/init/default.nix index 82bbb460db0..c49891d593f 100644 --- a/init/default.nix +++ b/init/default.nix @@ -1,9 +1,9 @@ -{stdenv, bash, coreutils, findutils}: +{stdenv, bash, coreutils, findutils, utillinux, sysvinit, e2fsprogs, nix}: derivation { name = "init"; system = stdenv.system; builder = ./builder.sh; src = ./init.sh; - inherit stdenv bash coreutils findutils; + inherit stdenv bash coreutils findutils utillinux sysvinit e2fsprogs nix; } diff --git a/init/init.sh b/init/init.sh index bb17ef5208f..c5007b44f2d 100644 --- a/init/init.sh +++ b/init/init.sh @@ -1,14 +1,33 @@ #! @bash@/bin/sh -e -export PATH=@bash@/bin:@coreutils@/bin:@findutils@/bin +trap "echo 'ignoring TERM signal'" SIGTERM +trap "echo 'ignoring INT signal'" SIGINT + +export PATH=@nix@/bin:@bash@/bin:@coreutils@/bin:@findutils@/bin:@utillinux@/bin:@utillinux@/sbin:@sysvinit@/bin:@sysvinit@/sbin:@e2fsprogs@/bin:@e2fsprogs@/sbin echo "--- Nix ---" -#echo "remounting root..." +echo "mounting /proc..." +mount -n -t proc none /proc + +echo "checking /dev/root..." +e2fsck -y /dev/root || test "$?" -le 1 + +echo "remounting / writable..." +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..." -exit 0 +halt -d -f diff --git a/make-disk.sh b/make-disk.sh index fb2c3a38545..498753d6fbb 100755 --- a/make-disk.sh +++ b/make-disk.sh @@ -2,7 +2,7 @@ image=/tmp/disk.img size=$(expr 256 \* 1024 \* 1024) -storepaths=/tmp/storepaths +storePaths=/tmp/storepaths successors=/tmp/successors if ! test -f $image; then @@ -16,19 +16,24 @@ if ! test -f $image; then fi - # What to copy? -storeexpr=$(echo '(import ./pkgs.nix).init' | nix-instantiate -) -nix-store -rB $storeexpr -nix-store -qn --requisites $storeexpr > $storepaths +storeExpr=$(echo '(import ./pkgs.nix).everything' | nix-instantiate -) +nix-store -rB $storeExpr +nix-store -qn --requisites $storeExpr > $storePaths (while read storepath; do nix-store -q --predecessors $storepath | (while read predecessor; do echo $predecessor $storepath done) -done) < $storepaths > $successors +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 -)) # 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 $storeexpr" - +linux ubd0=$image root=/dev/root rootflags=/ rootfstype=hostfs \ + init="$(pwd)/fill-disk.sh $sysvinitPath $initPath" diff --git a/pkgs.nix b/pkgs.nix index b9fc7a22273..d0314a6b300 100644 --- a/pkgs.nix +++ b/pkgs.nix @@ -1,4 +1,9 @@ rec { - inherit (import pkgs/system/i686-linux.nix) stdenv bash coreutils findutils; - init = (import ./init) {inherit stdenv bash coreutils findutils;}; + inherit (import pkgs/system/i686-linux.nix) + stdenv bash coreutils findutils utillinux sysvinit e2fsprogs nix; + + init = (import ./init) + {inherit stdenv bash coreutils findutils utillinux sysvinit e2fsprogs nix;}; + + everything = [init sysvinit]; }