2006-11-04 03:01:13 +03:00
|
|
|
#! @shell@
|
|
|
|
|
|
|
|
# !!! copied from stage 1; remove duplication
|
|
|
|
|
2006-11-13 14:41:27 +03:00
|
|
|
|
2010-01-20 21:06:33 +03:00
|
|
|
# If no `systemConfig' parameter is specified on the kernel command
|
2010-01-22 20:31:23 +03:00
|
|
|
# line, use a fallback.
|
|
|
|
systemConfig=/nix/var/nix/profiles/system
|
2010-01-20 21:06:33 +03:00
|
|
|
|
|
|
|
|
2006-11-04 03:01:13 +03:00
|
|
|
# Print a greeting.
|
|
|
|
echo
|
2009-11-07 00:51:28 +03:00
|
|
|
echo -e "\e[1;32m<<< NixOS Stage 2 >>>\e[0m"
|
2006-11-04 03:01:13 +03:00
|
|
|
echo
|
|
|
|
|
2006-11-13 14:41:27 +03:00
|
|
|
|
2006-11-04 03:01:13 +03:00
|
|
|
# Set the PATH.
|
2006-12-11 03:52:36 +03: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 03:01:13 +03:00
|
|
|
|
2006-11-13 14:41:27 +03:00
|
|
|
|
2010-01-20 21:06:33 +03: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.
|
|
|
|
mount -n -o remount,rw none /
|
|
|
|
|
|
|
|
|
2010-06-01 19:53:24 +04:00
|
|
|
# Mount special file systems. Note that /dev, /proc and /sys are
|
|
|
|
# already mounted by `switch_root' in the initrd.
|
2008-01-24 19:56:09 +03:00
|
|
|
mkdir -m 0755 -p /etc
|
|
|
|
test -e /etc/fstab || touch /etc/fstab # to shut up mount
|
2009-11-07 18:24:59 +03:00
|
|
|
test -s /etc/mtab && rm /etc/mtab # while installing a symlink is created (see man mount), if it's still there for whateever reason remove it
|
2009-10-09 20:09:56 +04:00
|
|
|
rm -f /etc/mtab* # not that we care about stale locks
|
2009-02-05 19:19:59 +03:00
|
|
|
|
|
|
|
rm -f /etc/mtab
|
2006-11-24 01:58:25 +03:00
|
|
|
cat /proc/mounts > /etc/mtab
|
2006-12-12 03:08:26 +03:00
|
|
|
|
2006-11-24 03:18:14 +03:00
|
|
|
|
|
|
|
# Process the kernel command line.
|
|
|
|
for o in $(cat /proc/cmdline); do
|
|
|
|
case $o in
|
|
|
|
debugtrace)
|
|
|
|
# Show each command.
|
|
|
|
set -x
|
|
|
|
;;
|
|
|
|
debug2)
|
2006-11-24 03:24:08 +03:00
|
|
|
echo "Debug shell called from @out@"
|
2006-11-24 03:18:14 +03:00
|
|
|
exec @shell@
|
|
|
|
;;
|
|
|
|
S|s|single)
|
|
|
|
# !!! argh, can't pass a startup event to Upstart yet.
|
|
|
|
exec @shell@
|
|
|
|
;;
|
2006-12-23 02:34:42 +03:00
|
|
|
safemode)
|
|
|
|
safeMode=1
|
|
|
|
;;
|
2007-03-20 16:01:53 +03:00
|
|
|
systemConfig=*)
|
|
|
|
set -- $(IFS==; echo $o)
|
|
|
|
systemConfig=$2
|
|
|
|
;;
|
2008-03-22 19:03:43 +03:00
|
|
|
resume=*)
|
|
|
|
set -- $(IFS==; echo $o)
|
|
|
|
resumeDevice=$2
|
|
|
|
;;
|
2006-11-24 03:18:14 +03:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
# More special file systems, initialise required directories.
|
2009-01-29 22:17:55 +03:00
|
|
|
mkdir -m 0777 /dev/shm
|
2010-04-17 19:20:13 +04:00
|
|
|
mount -t tmpfs -o "rw,nosuid,nodev,size=@devShmSize@" tmpfs /dev/shm
|
2007-01-17 01:34:15 +03:00
|
|
|
mkdir -m 0755 -p /dev/pts
|
2010-01-09 17:23:20 +03:00
|
|
|
mount -t devpts -o mode=0600,gid=@ttyGid@ none /dev/pts
|
2010-06-01 19:53:24 +04:00
|
|
|
[ -e /proc/bus/usb ] && mount -t usbfs none /proc/bus/usb # UML doesn't have USB by default
|
2008-02-04 13:20:38 +03:00
|
|
|
mkdir -m 01777 -p /tmp
|
|
|
|
mkdir -m 0755 -p /var
|
|
|
|
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 19:19:59 +03:00
|
|
|
mkdir -m 0755 -p /etc/nixos
|
2008-01-24 19:56:09 +03:00
|
|
|
|
2006-11-07 01:21:50 +03:00
|
|
|
|
2006-12-11 01:29:44 +03:00
|
|
|
# Miscellaneous boot time cleanup.
|
|
|
|
rm -rf /var/run
|
2009-02-05 19:19:59 +03:00
|
|
|
rm -rf /var/lock
|
2010-06-01 23:44:23 +04:00
|
|
|
rm -rf /var/log/upstart
|
2008-10-29 16:10:49 +03:00
|
|
|
|
|
|
|
#echo -n "cleaning \`/tmp'..."
|
|
|
|
#rm -rf --one-file-system /tmp/*
|
|
|
|
#echo " done"
|
2006-12-11 01:29:44 +03:00
|
|
|
|
2009-08-12 01:09:25 +04:00
|
|
|
|
2008-10-29 18:43:37 +03: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 21:16:29 +03:00
|
|
|
|
2010-06-10 02:29:06 +04:00
|
|
|
# Use a tmpfs for /var/run to ensure that / or /var can be unmounted
|
|
|
|
# or at least remounted read-only during shutdown. (Upstart 0.6
|
|
|
|
# apparently uses nscd to do some name lookups, resulting in it
|
|
|
|
# holding some mmap mapping to deleted files in /var/run/nscd.
|
|
|
|
# Similarly, portmap and statd have open files in /var/run and are
|
|
|
|
# needed during shutdown to unmount NFS volumes.)
|
|
|
|
mkdir -m 0755 -p /var/run
|
|
|
|
mount -t tmpfs -o "mode=755" none /var/run
|
|
|
|
|
|
|
|
|
2008-03-22 19:03:43 +03:00
|
|
|
# Clear the resume device.
|
|
|
|
if test -n "$resumeDevice"; then
|
|
|
|
mkswap "$resumeDevice" || echo 'Failed to clear saved image.'
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2006-12-09 22:25:23 +03:00
|
|
|
# Run the script that performs all configuration activation that does
|
|
|
|
# not have to be done at boot time.
|
2010-06-01 19:53:24 +04:00
|
|
|
echo "running activation script..."
|
2007-03-20 16:01:53 +03:00
|
|
|
@activateConfiguration@ "$systemConfig"
|
|
|
|
|
|
|
|
|
2010-06-21 00:54:31 +04:00
|
|
|
# Record the boot configuration.
|
2007-03-20 16:01:53 +03:00
|
|
|
if test -n "$systemConfig"; then
|
|
|
|
ln -sfn "$systemConfig" /var/run/booted-system
|
2010-06-21 00:54:31 +04: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.
|
|
|
|
ln -sfn /var/run/booted-system /nix/var/nix/gcroots/booted-system
|
2007-03-20 16:01:53 +03:00
|
|
|
fi
|
2006-12-09 05:51:42 +03:00
|
|
|
|
|
|
|
|
2006-11-04 16:25:10 +03:00
|
|
|
# Ensure that the module tools can find the kernel modules.
|
|
|
|
export MODULE_DIR=@kernel@/lib/modules/
|
|
|
|
|
2006-11-08 01:05:27 +03:00
|
|
|
|
2007-03-06 03:45:33 +03:00
|
|
|
# Run any user-specified commands.
|
2009-06-05 20:02:58 +04:00
|
|
|
@shell@ @postBootCommands@
|
2007-03-06 03:45:33 +03:00
|
|
|
|
2010-06-08 16:48:16 +04:00
|
|
|
|
2009-11-06 13:43:38 +03:00
|
|
|
# For debugging Upstart.
|
|
|
|
#@shell@ --login < /dev/console > /dev/console 2>&1 &
|
2007-03-06 03:45:33 +03:00
|
|
|
|
2010-06-08 16:48:16 +04:00
|
|
|
|
2009-11-07 00:08:06 +03:00
|
|
|
# Start Upstart's init.
|
2009-11-06 13:43:38 +03:00
|
|
|
echo "starting Upstart..."
|
2009-11-07 00:08:06 +03:00
|
|
|
PATH=/var/run/current-system/upstart/sbin exec init
|