2006-11-04 00:01:13 +00:00
|
|
|
#! @shell@
|
|
|
|
|
2010-09-13 22:10:25 +00:00
|
|
|
systemConfig=@systemConfig@
|
2006-11-04 00:01:13 +00:00
|
|
|
|
2006-11-13 11:41:27 +00:00
|
|
|
|
2006-11-04 00:01:13 +00:00
|
|
|
# Print a greeting.
|
|
|
|
echo
|
2009-11-06 21:51:28 +00:00
|
|
|
echo -e "\e[1;32m<<< NixOS Stage 2 >>>\e[0m"
|
2006-11-04 00:01:13 +00:00
|
|
|
echo
|
|
|
|
|
2006-11-13 11:41:27 +00:00
|
|
|
|
2006-11-04 00:01:13 +00:00
|
|
|
# Set the PATH.
|
2006-12-11 00:52:36 +00:00
|
|
|
setPath() {
|
|
|
|
local dirs="$1"
|
|
|
|
export PATH=/empty
|
|
|
|
for i in $dirs; do
|
|
|
|
PATH=$PATH:$i/bin
|
|
|
|
if test -e $i/sbin; then
|
|
|
|
PATH=$PATH:$i/sbin
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
setPath "@path@"
|
2006-11-04 00:01:13 +00:00
|
|
|
|
2006-11-13 11:41:27 +00:00
|
|
|
|
2010-01-20 18:06:33 +00:00
|
|
|
# Normally, stage 1 mounts the root filesystem read/writable.
|
|
|
|
# However, in some environments (such as Amazon EC2), stage 2 is
|
|
|
|
# executed directly, and the root is read-only. So make it writable
|
|
|
|
# here.
|
2012-08-10 18:46:36 +00:00
|
|
|
mount -n -o remount,rw /
|
2010-01-20 18:06:33 +00:00
|
|
|
|
|
|
|
|
2010-07-14 10:55:45 +00:00
|
|
|
# Likewise, stage 1 mounts /proc, /dev and /sys, so if we don't have a
|
|
|
|
# stage 1, we need to do that here.
|
|
|
|
if [ ! -e /proc/1 ]; then
|
|
|
|
mkdir -m 0755 -p /proc
|
|
|
|
mount -n -t proc none /proc
|
|
|
|
mkdir -m 0755 -p /dev
|
2012-06-19 19:15:40 +00:00
|
|
|
mount -t devtmpfs none /dev
|
2010-07-14 10:55:45 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2012-09-25 20:33:21 +00:00
|
|
|
# Make /nix/store a read-only bind mount to enforce immutability of
|
2012-10-04 20:15:30 +00:00
|
|
|
# the Nix store. Note that we can't use "chown root:nixbld" here
|
|
|
|
# because users/groups might not exist yet.
|
|
|
|
chown 0:30000 /nix/store
|
2012-09-28 14:59:58 +00:00
|
|
|
chmod 1775 /nix/store
|
2012-09-25 20:33:21 +00:00
|
|
|
if [ -n "@readOnlyStore@" ]; then
|
2012-10-02 14:32:56 +00:00
|
|
|
if ! mountpoint -q /nix/store; then
|
2012-09-25 20:33:21 +00:00
|
|
|
mkdir -p /nix/rw-store
|
|
|
|
mount --bind /nix/store /nix/store
|
|
|
|
mount -o remount,ro,bind /nix/store
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2010-07-14 10:55:45 +00:00
|
|
|
# Provide a /etc/mtab.
|
2008-01-24 16:56:09 +00:00
|
|
|
mkdir -m 0755 -p /etc
|
|
|
|
test -e /etc/fstab || touch /etc/fstab # to shut up mount
|
2009-10-09 16:09:56 +00:00
|
|
|
rm -f /etc/mtab* # not that we care about stale locks
|
2012-06-02 00:15:07 +00:00
|
|
|
ln -s /proc/mounts /etc/mtab
|
2006-12-12 00:08:26 +00:00
|
|
|
|
2006-11-24 00:18:14 +00:00
|
|
|
|
|
|
|
# Process the kernel command line.
|
2012-03-02 13:17:05 +00:00
|
|
|
debug2=
|
2006-11-24 00:18:14 +00:00
|
|
|
for o in $(cat /proc/cmdline); do
|
|
|
|
case $o in
|
|
|
|
debugtrace)
|
|
|
|
# Show each command.
|
|
|
|
set -x
|
|
|
|
;;
|
|
|
|
debug2)
|
2012-03-02 13:17:05 +00:00
|
|
|
debug2=1
|
2006-11-24 00:18:14 +00:00
|
|
|
;;
|
|
|
|
S|s|single)
|
|
|
|
# !!! argh, can't pass a startup event to Upstart yet.
|
|
|
|
exec @shell@
|
|
|
|
;;
|
2008-03-22 16:03:43 +00:00
|
|
|
resume=*)
|
|
|
|
set -- $(IFS==; echo $o)
|
|
|
|
resumeDevice=$2
|
|
|
|
;;
|
2006-11-24 00:18:14 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
# More special file systems, initialise required directories.
|
2012-06-27 13:35:53 +00:00
|
|
|
mkdir -m 0755 /dev/shm
|
2010-04-17 15:20:13 +00:00
|
|
|
mount -t tmpfs -o "rw,nosuid,nodev,size=@devShmSize@" tmpfs /dev/shm
|
2007-01-16 22:34:15 +00:00
|
|
|
mkdir -m 0755 -p /dev/pts
|
2010-06-01 15:53:24 +00:00
|
|
|
[ -e /proc/bus/usb ] && mount -t usbfs none /proc/bus/usb # UML doesn't have USB by default
|
2011-09-13 18:49:50 +00:00
|
|
|
mkdir -m 01777 -p /tmp
|
2012-06-14 22:44:56 +00:00
|
|
|
mkdir -m 0755 -p /var /var/log
|
2008-02-04 10:20:38 +00:00
|
|
|
mkdir -m 0755 -p /nix/var
|
|
|
|
mkdir -m 0700 -p /root
|
|
|
|
mkdir -m 0755 -p /bin # for the /bin/sh symlink
|
|
|
|
mkdir -m 0755 -p /home
|
2009-02-05 16:19:59 +00:00
|
|
|
mkdir -m 0755 -p /etc/nixos
|
2012-06-14 22:44:56 +00:00
|
|
|
mkdir -m 0700 -p /var/log/journal
|
2008-01-24 16:56:09 +00:00
|
|
|
|
2006-11-06 22:21:50 +00:00
|
|
|
|
2006-12-10 22:29:44 +00:00
|
|
|
# Miscellaneous boot time cleanup.
|
2011-07-24 23:36:30 +00:00
|
|
|
rm -rf /var/run /var/lock /var/log/upstart
|
2012-02-20 00:00:50 +00:00
|
|
|
rm -f /etc/resolv.conf
|
2008-10-29 13:10:49 +00:00
|
|
|
|
2012-06-11 07:05:13 +00:00
|
|
|
if test -n "@cleanTmpDir@"; then
|
|
|
|
echo -n "cleaning \`/tmp'..."
|
|
|
|
find /tmp -maxdepth 1 -mindepth 1 -print0 | xargs -0r rm -rf --one-file-system
|
|
|
|
echo " done"
|
|
|
|
else
|
|
|
|
# Get rid of ICE locks...
|
|
|
|
rm -rf /tmp/.ICE-unix
|
|
|
|
fi
|
2009-08-11 21:09:25 +00:00
|
|
|
|
2012-06-11 07:05:13 +00:00
|
|
|
# ... and ensure that it's owned by root.
|
2010-08-09 10:59:20 +00:00
|
|
|
mkdir -m 1777 /tmp/.ICE-unix
|
|
|
|
|
2008-10-29 15:43:37 +00:00
|
|
|
# This is a good time to clean up /nix/var/nix/chroots. Doing an `rm
|
|
|
|
# -rf' on it isn't safe in general because it can contain bind mounts
|
|
|
|
# to /nix/store and other places. But after rebooting these are all
|
|
|
|
# gone, of course.
|
|
|
|
rm -rf /nix/var/nix/chroots # recreated in activate-configuration.sh
|
|
|
|
|
2006-11-19 18:16:29 +00:00
|
|
|
|
2010-08-25 11:59:04 +00:00
|
|
|
# Also get rid of temporary GC roots.
|
|
|
|
rm -rf /nix/var/nix/gcroots/tmp /nix/var/nix/temproots
|
|
|
|
|
|
|
|
|
2011-07-16 19:27:45 +00:00
|
|
|
# Create a tmpfs on /run to hold runtime state for programs such as
|
2011-07-24 23:36:30 +00:00
|
|
|
# udev (if stage 1 hasn't already done so).
|
|
|
|
if ! mountpoint -q /run; then
|
|
|
|
rm -rf /run
|
|
|
|
mkdir -m 0755 -p /run
|
2011-10-27 17:34:16 +00:00
|
|
|
mount -t tmpfs -o "mode=0755,size=@runSize@" none /run
|
2011-07-24 23:36:30 +00:00
|
|
|
fi
|
|
|
|
|
2012-08-26 08:17:22 +00:00
|
|
|
mkdir -m 0755 -p /run/lock
|
2011-07-16 19:27:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
# For backwards compatibility, symlink /var/run to /run, and /var/lock
|
|
|
|
# to /run/lock.
|
|
|
|
ln -s /run /var/run
|
|
|
|
ln -s /run/lock /var/lock
|
2010-06-09 22:29:06 +00:00
|
|
|
|
|
|
|
|
2008-03-22 16:03:43 +00:00
|
|
|
# Clear the resume device.
|
|
|
|
if test -n "$resumeDevice"; then
|
|
|
|
mkswap "$resumeDevice" || echo 'Failed to clear saved image.'
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2006-12-09 19:25:23 +00:00
|
|
|
# Run the script that performs all configuration activation that does
|
|
|
|
# not have to be done at boot time.
|
2010-06-01 15:53:24 +00:00
|
|
|
echo "running activation script..."
|
2010-09-13 22:10:25 +00:00
|
|
|
$systemConfig/activate
|
2007-03-20 13:01:53 +00:00
|
|
|
|
|
|
|
|
2010-06-20 20:54:31 +00:00
|
|
|
# Record the boot configuration.
|
2012-07-16 15:30:37 +00:00
|
|
|
ln -sfn "$systemConfig" /run/booted-system
|
2010-09-13 22:10:25 +00:00
|
|
|
|
|
|
|
# Prevent the booted system form being garbage-collected If it weren't
|
|
|
|
# a gcroot, if we were running a different kernel, switched system,
|
|
|
|
# and garbage collected all, we could not load kernel modules anymore.
|
2012-07-16 15:30:37 +00:00
|
|
|
ln -sfn /run/booted-system /nix/var/nix/gcroots/booted-system
|
2006-12-09 02:51:42 +00:00
|
|
|
|
|
|
|
|
2007-03-06 00:45:33 +00:00
|
|
|
# Run any user-specified commands.
|
2009-06-05 16:02:58 +00:00
|
|
|
@shell@ @postBootCommands@
|
2007-03-06 00:45:33 +00:00
|
|
|
|
2010-06-08 12:48:16 +00:00
|
|
|
|
2009-11-06 10:43:38 +00:00
|
|
|
# For debugging Upstart.
|
2012-03-02 13:17:05 +00:00
|
|
|
if [ -n "$debug2" ]; then
|
2012-03-11 22:01:46 +00:00
|
|
|
# Get the console from the kernel cmdline
|
|
|
|
console=tty1
|
|
|
|
for o in $(cat /proc/cmdline); do
|
|
|
|
case $o in
|
|
|
|
console=*)
|
|
|
|
set -- $(IFS==; echo $o)
|
2012-03-28 19:58:44 +00:00
|
|
|
params=$2
|
|
|
|
set -- $(IFS=,; echo $params)
|
|
|
|
console=$1
|
2012-03-11 22:01:46 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2012-03-02 13:17:05 +00:00
|
|
|
echo "Debug shell called from @out@"
|
2012-03-11 22:43:37 +00:00
|
|
|
setsid @shellDebug@ < /dev/$console >/dev/$console 2>/dev/$console
|
2012-03-02 13:17:05 +00:00
|
|
|
fi
|
2007-03-06 00:45:33 +00:00
|
|
|
|
2010-06-08 12:48:16 +00:00
|
|
|
|
2012-06-02 00:15:07 +00:00
|
|
|
# Start systemd.
|
|
|
|
echo "starting systemd..."
|
2012-07-16 21:27:11 +00:00
|
|
|
PATH=/run/current-system/systemd/lib/systemd \
|
2012-08-14 21:09:44 +00:00
|
|
|
MODULE_DIR=/run/booted-system/kernel-modules/lib/modules \
|
2012-09-18 22:12:39 +00:00
|
|
|
LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive \
|
2012-08-14 20:45:50 +00:00
|
|
|
exec systemd --log-target=journal # --log-level=debug --log-target=console --crash-shell
|