From 477ea7015c8e50dc07fcb20af67c22152cf94470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Fri, 28 Nov 2008 12:03:56 +0000 Subject: [PATCH] boot-stage-1: Don't run `fsck' when on battery power. svn path=/nixos/trunk/; revision=13484 --- boot/boot-stage-1-init.sh | 55 ++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/boot/boot-stage-1-init.sh b/boot/boot-stage-1-init.sh index 0ddf6bb7eae..c6d7214028c 100644 --- a/boot/boot-stage-1-init.sh +++ b/boot/boot-stage-1-init.sh @@ -138,6 +138,26 @@ fi 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 +} + # Function for mounting a file system. mountFS() { local device="$1" @@ -158,24 +178,29 @@ mountFS() { fi if test -n "$mustCheck"; then - FSTAB_FILE="/etc/mtab" fsck -V -v -C -a "$device" - fsckResult=$? + if onACPower; then + FSTAB_FILE="/etc/mtab" fsck -V -v -C -a "$device" + fsckResult=$? - if test $(($fsckResult | 2)) = $fsckResult; then - echo "fsck finished, rebooting..." - sleep 3 - reboot - fi + if test $(($fsckResult | 2)) = $fsckResult; then + echo "fsck finished, rebooting..." + sleep 3 + reboot + fi - if test $(($fsckResult | 4)) = $fsckResult; then - echo "$device has unrepaired errors, please fix them manually." - fail - fi + if test $(($fsckResult | 4)) = $fsckResult; then + echo "$device has unrepaired errors, please fix them manually." + fail + fi - if test $fsckResult -ge 8; then - echo "fsck on $device failed." - fail - fi + if test $fsckResult -ge 8; then + echo "fsck on $device failed." + fail + fi + else + # Don't run `fsck' if the machine is on battery power. + echo "on battery power, so \`fsck' not run on \`$device'" + fi fi # Mount read-writable.