bug-grub
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Double sync, one more time


From: Yoshinori K. Okuji
Subject: Re: Double sync, one more time
Date: Fri, 05 Apr 2002 15:01:26 +0900
User-agent: Wanderlust/2.8.1 (Something) SEMI/1.14.3 (Ushinoya) FLIM/1.14.3 (Unebigoryƍmae) APEL/10.3 Emacs/21.1 (i386-debian-linux-gnu) MULE/5.0 (SAKAKI)

At Thu, 4 Apr 2002 11:01:24 -0500 (EST),
Pavel Roskin wrote:
> grub-install copies new stage* files to /boot/grub, but grub only runs
> sync() once, which is insufficient on Linux, at least on journaling
> filesystems.  We can discuss whether Linux does the right thing or not,
> but GRUB does a wrong thing by not taking the necessary precaucions.
> 
> I suggest this patch to be applied before the release.  Feel free to back 
> it out once you have a better solution.

The reason why your patch is bad is that GRUB already calls sync three
times (once in main and twice in grub_stage2) but it is obvious that
that doesn't do anything useful. So what your patch does is to just
add some more latency, I think.

Yes, I have a better solution. What do you think about this patch:

Index: util/grub-install.in
===================================================================
RCS file: /cvsroot/grub/grub/util/grub-install.in,v
retrieving revision 1.34
diff -u -r1.34 grub-install.in
--- util/grub-install.in        11 Feb 2002 08:10:35 -0000      1.34
+++ util/grub-install.in        5 Apr 2002 05:50:00 -0000
@@ -1,7 +1,7 @@
 #! /bin/sh
 
 # Install GRUB on your drive.
-#   Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
+#   Copyright (C) 1999,2000,2001,2002 Free Software Foundation, Inc.
 #
 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -31,6 +31,7 @@
 
 grub_shell=${sbindir}/grub
 log_file=/tmp/grub-install.log.$$
+img_file=/tmp/grub-install.img.$$
 rootdir=
 grub_prefix=/boot/grub
 
@@ -41,11 +42,14 @@
 
 # look for secure tempfile creation wrappers on this platform
 if test -x /bin/tempfile; then
-    mkstemp="/bin/tempfile --prefix=grub"
+    mklog="/bin/tempfile --prefix=grub"
+    mkimg="/bin/tempfile --prefix=grub"
 elif test -x /bin/mktemp; then
-    mkstemp="/bin/mktemp /tmp/grub-install.log.XXXXXX"
+    mklog="/bin/mktemp /tmp/grub-install.log.XXXXXX"
+    mkimg="/bin/mktemp /tmp/grub-install.img.XXXXXX"
 else
-    mkstemp=""
+    mklog=""
+    mkimg=""
 fi
 
 # Usage: usage
@@ -306,7 +310,7 @@
     :
 else
     # Create a safe temporary file.
-    test -n "$mkstemp" && log_file=`$mkstemp`
+    test -n "$mklog" && log_file=`$mklog`
 
     $grub_shell --batch --device-map=$device_map <<EOF >$log_file
 quit
@@ -375,8 +379,35 @@
     cp -f $file ${grubdir} || exit 1
 done
 
+# Make sure that GRUB reads the same images as the host OS.
+test -n "$mkimg" && img_file=`$mkimg`
+
+for file in ${grubdir}/stage1 ${grubdir}/stage2 ${grubdir}/*stage1_5; do
+    count=5
+    while test $count -gt 0; do
+       $grub_shell --batch --device-map=$device_map <<EOF >$img_file
+cat ${root_drive}${file}
+quit
+EOF
+       if sed '1,/^grub> cat/d; /^grub> quit/,$d' | sed '$d' \
+           | cmp $file >/dev/null; then
+           break
+       else
+           sleep 1
+           count=`expr $count - 1`
+       fi
+    done
+    if test $count -eq 0; then
+       echo "The file $file not read correctly." 1>&2
+       rm -f $img_file
+       exit 1
+    fi
+done
+
+rm -f $img_file
+
 # Create a safe temporary file.
-test -n "$mkstemp" && log_file=`$mkstemp`
+test -n "$mklog" && log_file=`$mklog`
 
 # Now perform the installation.
 $grub_shell --batch --device-map=$device_map <<EOF >$log_file



reply via email to

[Prev in Thread] Current Thread [Next in Thread]