git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #24645 from Mic92/stage-2

Stage-2 cleanup

commitb4820d49489a8b832cb9148bd23c4ddab03dce5a authorJörg Thalheim <Mic92@users.noreply.github.com> dateSat 8 Apr 2017, 21:52 (10 years ago) parent601602362c79a1
3 files changed+29−78
nixos/modules/system/boot/readonly-mountpoint.c−20 nixos/modules/system/boot/stage-2-init.sh+24−44 nixos/modules/system/boot/stage-2.nix+5−14
nixos/modules/system/boot/readonly-mountpoint.cdeleted−20
@@ -1,20 +0,0 @@
1−#include <sys/statvfs.h>
2−#include <stdio.h>
3−#include <stdlib.h>
4−
5−int main(int argc, char ** argv) {
6− struct statvfs stat;
7− if (argc != 2) {
8− fprintf(stderr, "Usage: %s PATH", argv[0]);
9− exit(2);
10− }
11− if (statvfs(argv[1], &stat) != 0) {
12− perror("statvfs");
13− exit(3);
14− }
15− if (stat.f_flag & ST_RDONLY)
16− exit(0);
17− else
18− exit(1);
19−}
20−
nixos/modules/system/boot/stage-2-init.sh+24−44
@@ -2,7 +2,22 @@
22
33systemConfig=@systemConfig@
44
5−export HOME=/root
5+export HOME=/root PATH="@path@"
6+
7+
8+# Process the kernel command line.
9+for o in $(</proc/cmdline); do
10+ case $o in
11+ boot.debugtrace)
12+ # Show each command.
13+ set -x
14+ ;;
15+ resume=*)
16+ set -- $(IFS==; echo $o)
17+ resumeDevice=$2
18+ ;;
19+ esac
20+done
621
722
823# Print a greeting.
@@ -11,21 +26,6 @@ echo -e "\e[1;32m<<< NixOS Stage 2 >>>\e[0m"
1126echo
1227
1328
14−# Set the PATH.
15−setPath() {
16− local dirs="$1"
17− export PATH=/empty
18− for i in $dirs; do
19− PATH=$PATH:$i/bin
20− if test -e $i/sbin; then
21− PATH=$PATH:$i/sbin
22− fi
23− done
24−}
25−
26−setPath "@path@"
27−
28−
2929# Normally, stage 1 mounts the root filesystem read/writable.
3030# However, in some environments, stage 2 is executed directly, and the
3131# root is read-only. So make it writable here.
@@ -61,7 +61,9 @@ echo "booting system configuration $systemConfig" > /dev/kmsg
6161chown -f 0:30000 /nix/store
6262chmod -f 1775 /nix/store
6363if [ -n "@readOnlyStore@" ]; then
64− if ! readonly-mountpoint /nix/store; then
64+ if ! [[ "$(findmnt --noheadings --output OPTIONS /nix/store)" =~ ro(,|$) ]]; then
65+ # FIXME when linux < 4.5 is EOL, switch to atomic bind mounts
66+ #mount /nix/store /nix/store -o bind,remount,ro
6567 mount --bind /nix/store /nix/store
6668 mount -o remount,ro,bind /nix/store
6769 fi
@@ -75,31 +77,12 @@ rm -f /etc/mtab* # not that we care about stale locks
7577ln -s /proc/mounts /etc/mtab
7678
7779
78−# Process the kernel command line.
79−for o in $(cat /proc/cmdline); do
80− case $o in
81− boot.debugtrace)
82− # Show each command.
83− set -x
84− ;;
85− resume=*)
86− set -- $(IFS==; echo $o)
87− resumeDevice=$2
88− ;;
89− esac
90−done
91−
92−
9380# More special file systems, initialise required directories.
9481[ -e /proc/bus/usb ] && mount -t usbfs usbfs /proc/bus/usb # UML doesn't have USB by default
9582mkdir -m 01777 -p /tmp
96−mkdir -m 0755 -p /var /var/log /var/lib /var/db
97−mkdir -m 0755 -p /nix/var
98−mkdir -m 0700 -p /root
99−chmod 0700 /root
100−mkdir -m 0755 -p /bin # for the /bin/sh symlink
101−mkdir -m 0755 -p /home
102−mkdir -m 0755 -p /etc/nixos
83+mkdir -m 0755 -p /var/{log,lib,db} /nix/var /etc/nixos/ \
84+ /run/lock /home /bin # for the /bin/sh symlink
85+install -m 0700 -d /root
10386
10487
10588# Miscellaneous boot time cleanup.
@@ -111,9 +94,6 @@ rm -f /etc/{group,passwd,shadow}.lock
11194rm -rf /nix/var/nix/gcroots/tmp /nix/var/nix/temproots
11295
11396
114−mkdir -m 0755 -p /run/lock
115−
116−
11797# For backwards compatibility, symlink /var/run to /run, and /var/lock
11898# to /run/lock.
11999ln -s /run /var/run
@@ -127,8 +107,8 @@ fi
127107
128108
129109# Use /etc/resolv.conf supplied by systemd-nspawn, if applicable.
130−if [ -n "@useHostResolvConf@" -a -e /etc/resolv.conf ]; then
131− cat /etc/resolv.conf | resolvconf -m 1000 -a host
110+if [ -n "@useHostResolvConf@" ] && [ -e /etc/resolv.conf ]; then
111+ resolvconf -m 1000 -a host </etc/resolv.conf
132112fi
133113
134114# Log the script output to /dev/kmsg or /run/log/stage-2-init.log.
nixos/modules/system/boot/stage-2.nix+5−14
@@ -7,15 +7,6 @@ let
77 kernel = config.boot.kernelPackages.kernel;
88 activateConfiguration = config.system.activationScripts.script;
99
10− readonlyMountpoint = pkgs.stdenv.mkDerivation {
11− name = "readonly-mountpoint";
12− unpackPhase = "true";
13− installPhase = ''
14− mkdir -p $out/bin
15− cc -O3 ${./readonly-mountpoint.c} -o $out/bin/readonly-mountpoint
16− '';
17− };
18−
1910 bootStage2 = pkgs.substituteAll {
2011 src = ./stage-2-init.sh;
2112 shellDebug = "${pkgs.bashInteractive}/bin/bash";
@@ -23,11 +14,11 @@ let
2314 inherit (config.nix) readOnlyStore;
2415 inherit (config.networking) useHostResolvConf;
2516 inherit (config.system.build) earlyMountScript;
26− path =
27− [ pkgs.coreutils
28− pkgs.utillinux
29− pkgs.openresolv
30− ] ++ optional config.nix.readOnlyStore readonlyMountpoint;
17+ path = lib.makeBinPath [
18+ pkgs.coreutils
19+ pkgs.utillinux
20+ pkgs.openresolv
21+ ];
3122 postBootCommands = pkgs.writeText "local-cmds"
3223 ''
3324 ${config.boot.postBootCommands}