From 2ea72fa9c811622bdbf93e866cd68db756d45986 Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Thu, 4 Aug 2016 23:12:39 +0300 Subject: nixos/luksroot: Reference correct output of openssl --- nixos/modules/system/boot/luksroot.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nixos/modules/system') diff --git a/nixos/modules/system/boot/luksroot.nix b/nixos/modules/system/boot/luksroot.nix index 8dad09c89207..f2755b49f88d 100644 --- a/nixos/modules/system/boot/luksroot.nix +++ b/nixos/modules/system/boot/luksroot.nix @@ -443,7 +443,7 @@ in copy_bin_and_libs pbkdf2-sha512 mkdir -p $out/etc/ssl - cp -pdv ${pkgs.openssl}/etc/ssl/openssl.cnf $out/etc/ssl + cp -pdv ${pkgs.openssl.out}/etc/ssl/openssl.cnf $out/etc/ssl cat > $out/bin/openssl-wrap < Date: Mon, 8 Aug 2016 01:32:18 +0300 Subject: nixos stage-1: factor device waiting into a function --- nixos/modules/system/boot/stage-1-init.sh | 55 ++++++++++++++++++------------- 1 file changed, 32 insertions(+), 23 deletions(-) (limited to 'nixos/modules/system') diff --git a/nixos/modules/system/boot/stage-1-init.sh b/nixos/modules/system/boot/stage-1-init.sh index 7705dcb2d125..8e33705644d8 100644 --- a/nixos/modules/system/boot/stage-1-init.sh +++ b/nixos/modules/system/boot/stage-1-init.sh @@ -352,6 +352,33 @@ mountFS() { } +# Function for waiting a device to appear. +waitDevice() { + local device="$1" + + # USB storage devices tend to appear with some delay. It would be + # great if we had a way to synchronously wait for them, but + # alas... So just wait for a few seconds for the device to + # appear. + if test ! -e $device; then + echo -n "waiting for device $device to appear..." + try=20 + while [ $try -gt 0 ]; do + sleep 1 + # also re-try lvm activation now that new block devices might have appeared + lvm vgchange -ay + # and tell udev to create nodes for the new LVs + udevadm trigger --action=add + if test -e $device; then break; fi + echo -n "." + try=$((try - 1)) + done + echo + [ $try -ne 0 ] + fi +} + + # Try to find and mount the root device. mkdir -p $targetRoot @@ -384,29 +411,11 @@ while read -u 3 mountPoint; do ;; esac - # USB storage devices tend to appear with some delay. It would be - # great if we had a way to synchronously wait for them, but - # alas... So just wait for a few seconds for the device to - # appear. If it doesn't appear, try to mount it anyway (and - # probably fail). This is a fallback for non-device "devices" - # that we don't properly recognise. - if test -z "$pseudoDevice" -a ! -e $device; then - echo -n "waiting for device $device to appear..." - try=20 - while [ $try -gt 0 ]; do - sleep 1 - # also re-try lvm activation now that new block devices might have appeared - lvm vgchange -ay - # and tell udev to create nodes for the new LVs - udevadm trigger --action=add - if test -e $device; then break; fi - echo -n "." - try=$((try - 1)) - done - echo - if [ $try -eq 0 ]; then - echo "Timed out waiting for device $device, trying to mount anyway." - fi + if test -z "$pseudoDevice" && ! waitDevice "$device"; then + # If it doesn't appear, try to mount it anyway (and + # probably fail). This is a fallback for non-device "devices" + # that we don't properly recognise. + echo "Timed out waiting for device $device, trying to mount anyway." fi # Wait once more for the udev queue to empty, just in case it's -- cgit 1.4.1 From 3ae468e8355494dda2e9c28b5d62d3c03bf4ce98 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Mon, 8 Aug 2016 01:34:23 +0300 Subject: nixos stage-1: move resumption below helper functions' definitions --- nixos/modules/system/boot/stage-1-init.sh | 66 +++++++++++++++---------------- 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'nixos/modules/system') diff --git a/nixos/modules/system/boot/stage-1-init.sh b/nixos/modules/system/boot/stage-1-init.sh index 8e33705644d8..fc50481e0bc8 100644 --- a/nixos/modules/system/boot/stage-1-init.sh +++ b/nixos/modules/system/boot/stage-1-init.sh @@ -189,39 +189,6 @@ if test -n "$debug1devices"; then fail; fi @postDeviceCommands@ -# Try to resume - all modules are loaded now, and devices exist -if test -e /sys/power/tuxonice/resume; then - if test -n "$(cat /sys/power/tuxonice/resume)"; then - echo 0 > /sys/power/tuxonice/user_interface/enabled - echo 1 > /sys/power/tuxonice/do_resume || echo "failed to resume..." - fi -fi - -if test -e /sys/power/resume -a -e /sys/power/disk; then - if test -n "@resumeDevice@"; then - resumeDev="@resumeDevice@" - resumeInfo="$(udevadm info -q property "$resumeDev" )" - else - for sd in @resumeDevices@; do - # Try to detect resume device. According to Ubuntu bug: - # https://bugs.launchpad.net/ubuntu/+source/pm-utils/+bug/923326/comments/1 - # when there are multiple swap devices, we can't know where the hibernate - # image will reside. We can check all of them for swsuspend blkid. - resumeInfo="$(test -e "$sd" && udevadm info -q property "$sd")" - if [ "$(echo "$resumeInfo" | sed -n 's/^ID_FS_TYPE=//p')" = "swsuspend" ]; then - resumeDev="$sd" - break - fi - done - fi - if test -e "$resumeDev"; then - resumeMajor="$(echo "$resumeInfo" | sed -n 's/^MAJOR=//p')" - resumeMinor="$(echo "$resumeInfo" | sed -n 's/^MINOR=//p')" - echo "$resumeMajor:$resumeMinor" > /sys/power/resume 2> /dev/null || echo "failed to resume..." - fi -fi - - # Return true if the machine is on AC power, or if we can't determine # whether it's on AC power. onACPower() { @@ -379,6 +346,39 @@ waitDevice() { } +# Try to resume - all modules are loaded now, and devices exist +if test -e /sys/power/tuxonice/resume; then + if test -n "$(cat /sys/power/tuxonice/resume)"; then + echo 0 > /sys/power/tuxonice/user_interface/enabled + echo 1 > /sys/power/tuxonice/do_resume || echo "failed to resume..." + fi +fi + +if test -e /sys/power/resume -a -e /sys/power/disk; then + if test -n "@resumeDevice@"; then + resumeDev="@resumeDevice@" + resumeInfo="$(udevadm info -q property "$resumeDev" )" + else + for sd in @resumeDevices@; do + # Try to detect resume device. According to Ubuntu bug: + # https://bugs.launchpad.net/ubuntu/+source/pm-utils/+bug/923326/comments/1 + # when there are multiple swap devices, we can't know where the hibernate + # image will reside. We can check all of them for swsuspend blkid. + resumeInfo="$(test -e "$sd" && udevadm info -q property "$sd")" + if [ "$(echo "$resumeInfo" | sed -n 's/^ID_FS_TYPE=//p')" = "swsuspend" ]; then + resumeDev="$sd" + break + fi + done + fi + if test -e "$resumeDev"; then + resumeMajor="$(echo "$resumeInfo" | sed -n 's/^MAJOR=//p')" + resumeMinor="$(echo "$resumeInfo" | sed -n 's/^MINOR=//p')" + echo "$resumeMajor:$resumeMinor" > /sys/power/resume 2> /dev/null || echo "failed to resume..." + fi +fi + + # Try to find and mount the root device. mkdir -p $targetRoot -- cgit 1.4.1 From 986a40421a94528c55531719fb382160292c7e16 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Mon, 8 Aug 2016 01:35:43 +0300 Subject: nixos stage-1: wait for devices during resumption attempt Also a microimprovement -- use `test -n` instead of `test -e` since we have already checked that the file exists. --- nixos/modules/system/boot/stage-1-init.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'nixos/modules/system') diff --git a/nixos/modules/system/boot/stage-1-init.sh b/nixos/modules/system/boot/stage-1-init.sh index fc50481e0bc8..ef04629d735f 100644 --- a/nixos/modules/system/boot/stage-1-init.sh +++ b/nixos/modules/system/boot/stage-1-init.sh @@ -346,7 +346,7 @@ waitDevice() { } -# Try to resume - all modules are loaded now, and devices exist +# Try to resume - all modules are loaded now. if test -e /sys/power/tuxonice/resume; then if test -n "$(cat /sys/power/tuxonice/resume)"; then echo 0 > /sys/power/tuxonice/user_interface/enabled @@ -355,7 +355,7 @@ if test -e /sys/power/tuxonice/resume; then fi if test -e /sys/power/resume -a -e /sys/power/disk; then - if test -n "@resumeDevice@"; then + if test -n "@resumeDevice@" && waitDevice "@resumeDevice@"; then resumeDev="@resumeDevice@" resumeInfo="$(udevadm info -q property "$resumeDev" )" else @@ -364,14 +364,16 @@ if test -e /sys/power/resume -a -e /sys/power/disk; then # https://bugs.launchpad.net/ubuntu/+source/pm-utils/+bug/923326/comments/1 # when there are multiple swap devices, we can't know where the hibernate # image will reside. We can check all of them for swsuspend blkid. - resumeInfo="$(test -e "$sd" && udevadm info -q property "$sd")" - if [ "$(echo "$resumeInfo" | sed -n 's/^ID_FS_TYPE=//p')" = "swsuspend" ]; then - resumeDev="$sd" - break + if waitDevice "$sd"; then + resumeInfo="$(udevadm info -q property "$sd")" + if [ "$(echo "$resumeInfo" | sed -n 's/^ID_FS_TYPE=//p')" = "swsuspend" ]; then + resumeDev="$sd" + break + fi fi done fi - if test -e "$resumeDev"; then + if test -n "$resumeDev"; then resumeMajor="$(echo "$resumeInfo" | sed -n 's/^MAJOR=//p')" resumeMinor="$(echo "$resumeInfo" | sed -n 's/^MINOR=//p')" echo "$resumeMajor:$resumeMinor" > /sys/power/resume 2> /dev/null || echo "failed to resume..." -- cgit 1.4.1 From ee36bb85886e4a6be1b172f5ec692727a8fe5893 Mon Sep 17 00:00:00 2001 From: Thomas Tuegel Date: Mon, 8 Aug 2016 09:28:17 -0500 Subject: nixos/stage-1: fix antiquotation --- nixos/modules/system/boot/stage-1.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nixos/modules/system') diff --git a/nixos/modules/system/boot/stage-1.nix b/nixos/modules/system/boot/stage-1.nix index 21a49d45789e..a74cfafdd37f 100644 --- a/nixos/modules/system/boot/stage-1.nix +++ b/nixos/modules/system/boot/stage-1.nix @@ -90,7 +90,7 @@ let [ ! -f "$out/lib/$(basename $LIB)" ] && cp -pdv $LIB $out/lib while [ "$(readlink $LIB)" != "" ]; do LINK="$(readlink $LIB)" - if [ "${LINK:0:1}" != "/" ]; then + if [ "''${LINK:0:1}" != "/" ]; then LINK="$(dirname $LIB)/$LINK" fi LIB="$LINK" -- cgit 1.4.1 From 68922e3f7407c5aecd8cc9cc3d22d753269b3f31 Mon Sep 17 00:00:00 2001 From: Thomas Tuegel Date: Mon, 8 Aug 2016 09:45:45 -0500 Subject: nixos/stage-1: use `readlink -e` in builder The builder has this convoluted `while` loop which just replicates `readlink -e`. I'm sure there was a reason at one point, because the loop has been there since time immemorial. It kept getting copied around, I suspect because nobody bothered to understand what it actually did. Incidentally, this fixes #17513, but I have no idea why. --- nixos/modules/system/boot/stage-1.nix | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'nixos/modules/system') diff --git a/nixos/modules/system/boot/stage-1.nix b/nixos/modules/system/boot/stage-1.nix index a74cfafdd37f..70429e9c0a22 100644 --- a/nixos/modules/system/boot/stage-1.nix +++ b/nixos/modules/system/boot/stage-1.nix @@ -87,15 +87,11 @@ let LDD="$(ldd $BIN)" || continue LIBS="$(echo "$LDD" | awk '{print $3}' | sed '/^$/d')" for LIB in $LIBS; do - [ ! -f "$out/lib/$(basename $LIB)" ] && cp -pdv $LIB $out/lib - while [ "$(readlink $LIB)" != "" ]; do - LINK="$(readlink $LIB)" - if [ "''${LINK:0:1}" != "/" ]; then - LINK="$(dirname $LIB)/$LINK" - fi - LIB="$LINK" - [ ! -f "$out/lib/$(basename $LIB)" ] && cp -pdv $LIB $out/lib - done + TGT="$out/lib/$(basename $LIB)" + if [ ! -f "$TGT" ]; then + SRC="$(readlink -e $LIB)" + cp -pdv "$SRC" "$TGT" + fi done done -- cgit 1.4.1