mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 15:03:28 +00:00
* 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
This commit is contained in:
parent
008ef42267
commit
3514c5658b
@ -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."
|
@ -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
|
@ -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;
|
||||
}
|
||||
|
12
boot/halt.sh
Normal file
12
boot/halt.sh
Normal file
@ -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
|
15
boot/login.sh
Normal file
15
boot/login.sh
Normal file
@ -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
|
@ -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
|
||||
|
@ -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"
|
||||
|
4
pkgs.nix
4
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];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user