* 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
wip/yesman
Eelco Dolstra 21 years ago
parent 1f7a8c8ae9
commit 1e87e75d07
  1. 20
      fill-disk.sh
  2. 4
      init/builder.sh
  3. 4
      init/default.nix
  4. 25
      init/init.sh
  5. 21
      make-disk.sh
  6. 9
      pkgs.nix

@ -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

@ -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

@ -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;
}

@ -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

@ -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"

@ -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];
}

Loading…
Cancel
Save