summary refs log tree commit diff
path: root/test/boot-stage-2-init.sh
blob: 3f480e87519d974f28a9d08de43de8c965eb7eda (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#! @shell@

# !!! copied from stage 1; remove duplication


# Print a greeting.
echo
echo "<<< NixOS Stage 2 >>>"
echo


# Set the PATH.
export PATH=/empty
for i in @path@; do
    PATH=$PATH:$i/bin
    if test -e $i/sbin; then
        PATH=$PATH:$i/sbin
    fi
done


# Mount special file systems.

if test -z "@readOnlyRoot@"; then
    #rootDev=$(grep "/dev/.* / " /proc/mounts | sed 's/^\([^ ]*\) .*/\1/')
    if ! mount -t dontcare -o remount,rw /dontcare /; then
	echo "Couldn't remount / read-writable, starting emergency shell!"
	exec @shell@
    fi
fi

needWritableDir() {
    if test -n "@readOnlyRoot@"; then
        mount -t tmpfs -o "mode=$2" none $1 $3
    else
        mkdir -m $2 -p $1
    fi
}

needWritableDir /etc 0755 -n # to shut up mount

test -e /etc/fstab || touch /etc/fstab # idem

mount -n -t proc none /proc
cat /proc/mounts > /etc/mtab


# Process the kernel command line.
for o in $(cat /proc/cmdline); do
    case $o in
        debugtrace)
            # Show each command.
            set -x
            ;;
        debug2)
            echo "Debug shell called from @out@"
            exec @shell@
            ;;
        S|s|single)
            # !!! argh, can't pass a startup event to Upstart yet.
            exec @shell@
            ;;
    esac
done


# More special file systems, initialise required directories.
mount -t sysfs none /sys
mount -t tmpfs -o "mode=0755" none /dev
needWritableDir /tmp 01777
needWritableDir /var 0755
needWritableDir /nix/var 0755

mkdir -m 0755 -p /nix/var/nix/db
mkdir -m 0755 -p /nix/var/nix/gcroots
mkdir -m 0755 -p /nix/var/nix/temproots

mkdir -m 0755 -p /var/log

ln -sf /nix/var/nix/profiles /nix/var/nix/gcroots/


# Ensure that the module tools can find the kernel modules.
export MODULE_DIR=@kernel@/lib/modules/


# Start udev.
udevd --daemon


# Let udev create device nodes for all modules that have already been
# loaded into the kernel (or for which support is built into the
# kernel).
udevtrigger
udevsettle # wait for udev to finish


# Necessary configuration for syslogd.
mkdir -m 0755 -p /var/run
echo "*.* /dev/tty10" > /etc/syslog.conf
echo "syslog 514/udp" > /etc/services # required, even if we don't use it


# login/su absolutely need this.
test -e /etc/login.defs || touch /etc/login.defs 


# Enable a password-less root login.
if ! test -e /etc/passwd; then
    echo "root::0:0:root:/:@shell@" > /etc/passwd
fi
if ! test -e /etc/group; then
    echo "root:*:0" > /etc/group
fi


# We need "localhost" (!!! destructive hack for NIXOS-41).
echo "127.0.0.1 localhost" > /etc/hosts
echo "hosts: files dns" > /etc/nsswitch.conf


# Set up the Upstart jobs.
export UPSTART_CFG_DIR=/etc/event.d

rm -f /etc/event.d
ln -sf @upstartJobs@/etc/event.d /etc/event.d


# Show a nice greeting on each terminal.
cat > /etc/issue <<EOF

<<< Welcome to NixOS (\m) - Kernel \r (\l) >>>


EOF


# Additional path for the interactive shell.
for i in @extraPath@; do
    PATH=$PATH:$i/bin
    if test -e $i/sbin; then
        PATH=$PATH:$i/sbin
    fi
done

cat > /etc/profile <<EOF
export PATH=$PATH
export MODULE_DIR=$MODULE_DIR
if test -f /etc/profile.local; then
    source /etc/profile.local
fi
EOF


# Set the host name.
hostname nixos


# Start an interactive shell.
#exec @shell@


# Start Upstart's init.
exec @upstart@/sbin/init -v