diff --git a/test/boot-environment.nix b/test/boot-environment.nix index 6f124b88fef2..af7b96785185 100644 --- a/test/boot-environment.nix +++ b/test/boot-environment.nix @@ -40,10 +40,16 @@ rec { # need. extraUtils = pkgs.stdenv.mkDerivation { name = "extra-utils"; - builder = builtins.toFile "builder.sh" - "source $stdenv/setup; ensureDir $out/bin; cp $utillinux/bin/mount $utillinux/bin/umount $utillinux/sbin/pivot_root $out/bin; nuke-refs $out/bin/*"; + builder = builtins.toFile "builder.sh" " + source $stdenv/setup + ensureDir $out/bin + cp $utillinux/bin/mount $utillinux/bin/umount $utillinux/sbin/pivot_root $out/bin + cp -p $e2fsprogs/sbin/fsck* $e2fsprogs/sbin/e2fsck $out/bin + nuke-refs $out/bin/* + "; buildInputs = [pkgs.nukeReferences]; inherit (pkgsStatic) utillinux; + e2fsprogs = pkgs.e2fsprogsDiet; }; diff --git a/test/boot-stage-1-init.sh b/test/boot-stage-1-init.sh index 3d115760e06b..b25ce05368ef 100644 --- a/test/boot-stage-1-init.sh +++ b/test/boot-stage-1-init.sh @@ -81,7 +81,7 @@ if test -n "@autoDetectRootDevice@"; then echo " in $devName..." - if mount -o ro -t iso9660 $devName /mnt/root; then + if mount -n -o ro -t iso9660 $devName /mnt/root; then if test -e "/mnt/root/@rootLabel@"; then found=1 break @@ -100,7 +100,31 @@ if test -n "@autoDetectRootDevice@"; then else # Hard-coded root device. - mount -o ro "@rootDevice@" /mnt/root + rootDevice="@rootDevice@" + + # Check the root device. + fsck -C -a "$rootDevice" + fsckResult=$? + + if test $(($fsckResult | 2)) = $fsckResult; then + echo "fsck finished, rebooting..." + sleep 3 + # reboot -f -d !!! don't have reboot yet + fail + fi + + if test $(($fsckResult | 4)) = $fsckResult; then + echo "$rootDevice has unrepaired errors, please fix them manually." + fail + fi + + if test $fsckResult -ge 8; then + echo "fsck on $rootDevice failed." + fail + fi + + # Mount read-writable. + mount -n -o rw "$rootDevice" /mnt/root || fail fi diff --git a/test/boot-stage-2-init.sh b/test/boot-stage-2-init.sh index d2dc42045a17..57f9e4e444fa 100644 --- a/test/boot-stage-2-init.sh +++ b/test/boot-stage-2-init.sh @@ -21,14 +21,6 @@ done # Mount special file systems. -if test -z "@readOnlyRoot@"; then - #rootDev=$(grep "/dev/.* / " /proc/mounts | sed 's/^\([^ ]*\) .*/\1/') - if ! mount -t dontcare -o remount,rw /dontcare /; then - echo "Couldn't remount / read-writable, starting emergency shell!" - exec @shell@ - fi -fi - needWritableDir() { if test -n "@readOnlyRoot@"; then mount -t tmpfs -o "mode=$2" none $1 $3