From e940f1fbd73196be50a3904d22e8a3f8718b27a6 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 10 Jun 2009 15:02:39 +0000 Subject: [PATCH] * Cleaned up the error messages in the stage 1 init script. * Use the basename from coreutils rather than a bash hack. svn path=/nixos/branches/modular-nixos/; revision=15927 --- modules/system/boot/stage-1-init.sh | 91 +++++++++++------------------ modules/system/boot/stage-1.nix | 4 ++ 2 files changed, 38 insertions(+), 57 deletions(-) diff --git a/modules/system/boot/stage-1-init.sh b/modules/system/boot/stage-1-init.sh index 524735b1ba26..50870909489d 100644 --- a/modules/system/boot/stage-1-init.sh +++ b/modules/system/boot/stage-1-init.sh @@ -5,50 +5,37 @@ targetRoot=/mnt/root export LD_LIBRARY_PATH=@extraUtils@/lib -errorDialog() { +fail() { + # If starting stage 2 failed, allow the user to repair the problem + # in an interactive shell. timeout=15 - echo - echo "Press within $timeout seconds:" - echo " i) to launch an interactive shell" - echo " f) to start an interactive shell having pid 1" - echo " (needed if you want to start Stage 2 manually)" - echo " *) to continue immediately (ignoring the failing command)" + cat < /sys/power/tuxonice/user_interface/enabled - echo 1 > /sys/power/tuxonice/do_resume || echo "Failed to resume..." + echo 1 > /sys/power/tuxonice/do_resume || echo "failed to resume..." fi fi -echo "@resumeDevice@" > /sys/power/resume 2> /dev/null || echo "Failed to resume..." +echo "@resumeDevice@" > /sys/power/resume 2> /dev/null || echo "failed to resume..." echo shutdown > /sys/power/disk @@ -131,7 +118,7 @@ udevadm trigger udevadm settle if type -p dmsetup > /dev/null; then - echo "dmsetup found, starting device mapper and lvm" + echo "starting device mapper and LVM..." dmsetup mknodes lvm vgscan --ignorelockingfailure lvm vgchange -ay --ignorelockingfailure @@ -143,21 +130,9 @@ if test -n "$debug1devices"; then fail; fi # Return true if the machine is on AC power, or if we can't determine # whether it's on AC power. onACPower() { - if test -d "/proc/acpi/battery"; then - if ls /proc/acpi/battery/BAT[0-9]* > /dev/null 2>&1; then - if cat /proc/acpi/battery/BAT*/state \ - | grep "^charging state" \ - | grep -q "discharg" ; then - false - else - true - fi - else - true - fi - else - true - fi + ! test -d "/proc/acpi/battery" || + ! ls /proc/acpi/battery/BAT[0-9]* > /dev/null 2>&1 || + ! cat /proc/acpi/battery/BAT*/state | grep "^charging state" | grep -q "discharg" } @@ -169,7 +144,7 @@ checkFS() { # Don't run `fsck' if the machine is on battery power. !!! Is # this a good idea? if ! onACPower; then - echo "on battery power, so \`fsck' not run on \`$device'" + echo "on battery power, so no \`fsck' will be performed on \`$device'" return 0 fi @@ -204,8 +179,9 @@ mountFS() { local fsType="$4" checkFS "$device" + + mkdir -p "/mnt-root$mountPoint" || true - # Mount read-writable. mount -t "$fsType" -o "$options" "$device" /mnt-root$mountPoint || fail } @@ -286,12 +262,13 @@ fi # Start stage 2. `run-init' deletes all files in the ramfs on the # current /. -if test -z "$stage2Init"; then fail; fi +if test -z "$stage2Init" -o ! -e "$targetRoot/$stage2Init"; then + echo "stage 2 init script not found" + fail +fi + umount /sys umount /proc exec run-init "$targetRoot" "$stage2Init" -echo -echo "$1: failed running $stage2Init" -echo "Dropping into a root shell..." -export $stage2Init; exec @shell@ +fail # should never be reached diff --git a/modules/system/boot/stage-1.nix b/modules/system/boot/stage-1.nix index 8e092990699d..0a451648eb1a 100644 --- a/modules/system/boot/stage-1.nix +++ b/modules/system/boot/stage-1.nix @@ -96,6 +96,9 @@ let # Copy some utillinux stuff. cp ${pkgs.utillinux}/bin/mount ${pkgs.utillinux}/bin/umount ${pkgs.utillinux}/sbin/pivot_root $out/bin + # Copy some coreutils. + cp ${pkgs.coreutils}/bin/basename $out/bin + # Copy e2fsck and friends. cp ${pkgs.e2fsprogs}/sbin/e2fsck $out/bin cp ${pkgs.e2fsprogs}/sbin/tune2fs $out/bin @@ -154,6 +157,7 @@ let fi $out/bin/reiserfsck -V $out/bin/mdadm --version + $out/bin/basename --version ''; # */