2002-04-06 Yoshinori K. Okuji <okuji@enbug.org>

* stage2/builtins.c [GRUB_UTIL] (dump_func): New function.
	[GRUB_UTIL] (builtin_dump): New variable.
	(builtin_table) [GRUB_UTIL]: Added a pointer to BUILTIN_DUMP.
	* util/grub-install.in: Make sure that GRUB reads the same
	images as the host operating system by comparing the result of
	running the command "dump" with the contents of the OS file.
This commit is contained in:
okuji 2002-04-06 12:15:13 +00:00
parent cfce0b1fae
commit 86d5582ec2
5 changed files with 115 additions and 7 deletions

View file

@ -1,3 +1,12 @@
2002-04-06 Yoshinori K. Okuji <okuji@enbug.org>
* stage2/builtins.c [GRUB_UTIL] (dump_func): New function.
[GRUB_UTIL] (builtin_dump): New variable.
(builtin_table) [GRUB_UTIL]: Added a pointer to BUILTIN_DUMP.
* util/grub-install.in: Make sure that GRUB reads the same
images as the host operating system by comparing the result of
running the command "dump" with the contents of the OS file.
2002-04-04 Yoshinori K. Okuji <okuji@enbug.org> 2002-04-04 Yoshinori K. Okuji <okuji@enbug.org>
* stage2/builtins.c (setup_func): Don't embed a drive number, if * stage2/builtins.c (setup_func): Don't embed a drive number, if

3
NEWS
View file

@ -22,6 +22,9 @@ New in 0.92:
* A fallback entry is executed immediately after a default entry, * A fallback entry is executed immediately after a default entry,
without prompting a user's intervention, as the manual has ever been without prompting a user's intervention, as the manual has ever been
saying. saying.
* The utility ``grub-install'' makes sure that GRUB images have been
written to a physical disk completely. To assist this feature, a new
command "dump" is added.
New in 0.91 - 2002-01-21: New in 0.91 - 2002-01-21:
* Support for Linux DAC960 is added. * Support for Linux DAC960 is added.

View file

@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.23. .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.23.
.TH GRUB-INSTALL "8" "March 2002" "grub-install (GNU GRUB 0.92)" FSF .TH GRUB-INSTALL "8" "April 2002" "grub-install (GNU GRUB 0.92)" FSF
.SH NAME .SH NAME
grub-install \- install GRUB on your drive grub-install \- install GRUB on your drive
.SH SYNOPSIS .SH SYNOPSIS

View file

@ -973,6 +973,66 @@ static struct builtin builtin_displaymem =
" machine is, including all regions of physical RAM installed." " machine is, including all regions of physical RAM installed."
}; };
/* dump FROM TO */
#ifdef GRUB_UTIL
static int
dump_func (char *arg, int flags)
{
char *from, *to;
FILE *fp;
char c;
from = arg;
to = skip_to (0, arg);
if (! *from || ! *to)
{
errnum = ERR_BAD_ARGUMENT;
return 1;
}
nul_terminate (from);
nul_terminate (to);
if (! grub_open (from))
return 1;
fp = fopen (to, "w");
if (! fp)
{
errnum = ERR_WRITE;
return 1;
}
while (grub_read (&c, 1))
if (fputc (c, fp) == EOF)
{
errnum = ERR_WRITE;
fclose (fp);
return 1;
}
if (fclose (fp) == EOF)
{
errnum = ERR_WRITE;
return 1;
}
grub_close ();
return 0;
}
static struct builtin builtin_dump =
{
"dump",
dump_func,
BUILTIN_CMDLINE,
"dump FROM TO",
"Dump the contents of the file FROM to the file TO. FROM must be"
" a GRUB file and TO must be an OS file."
};
#endif /* GRUB_UTIL */
static char embed_info[32]; static char embed_info[32];
/* embed */ /* embed */
@ -4528,6 +4588,9 @@ struct builtin *builtin_table[] =
#endif /* SUPPORT_NETBOOT */ #endif /* SUPPORT_NETBOOT */
&builtin_displayapm, &builtin_displayapm,
&builtin_displaymem, &builtin_displaymem,
#ifdef GRUB_UTIL
&builtin_dump,
#endif /* GRUB_UTIL */
&builtin_embed, &builtin_embed,
&builtin_fallback, &builtin_fallback,
&builtin_find, &builtin_find,

View file

@ -1,7 +1,7 @@
#! /bin/sh #! /bin/sh
# Install GRUB on your drive. # 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 # 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 # under the terms of the GNU General Public License as published by
@ -31,6 +31,7 @@ pkgdatadir=${datadir}/${PACKAGE}/${host_cpu}-${host_vendor}
grub_shell=${sbindir}/grub grub_shell=${sbindir}/grub
log_file=/tmp/grub-install.log.$$ log_file=/tmp/grub-install.log.$$
img_file=/tmp/grub-install.img.$$
rootdir= rootdir=
grub_prefix=/boot/grub grub_prefix=/boot/grub
@ -41,11 +42,14 @@ debug=no
# look for secure tempfile creation wrappers on this platform # look for secure tempfile creation wrappers on this platform
if test -x /bin/tempfile; then 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 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 else
mkstemp="" mklog=""
mkimg=""
fi fi
# Usage: usage # Usage: usage
@ -306,7 +310,7 @@ if test -f "$device_map"; then
: :
else else
# Create a safe temporary file. # 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 $grub_shell --batch --device-map=$device_map <<EOF >$log_file
quit quit
@ -375,8 +379,37 @@ for file in \
cp -f $file ${grubdir} || exit 1 cp -f $file ${grubdir} || exit 1
done done
# Make sure that GRUB reads the same images as the host OS.
test -n "$mkimg" && img_file=`$mkimg`
test -n "$mklog" && log_file=`$mklog`
for file in ${grubdir}/stage1 ${grubdir}/stage2 ${grubdir}/*stage1_5; do
count=5
tmp=`echo $file | sed "s|^${grubdir}|${grub_prefix}|"`
while test $count -gt 0; do
$grub_shell --batch --device-map=$device_map <<EOF >$log_file
dump ${root_drive}${tmp} ${img_file}
quit
EOF
if grep "Error [0-9]*: " $log_file >/dev/null; then
:
elif cmp $file $img_file >/dev/null; then
break
fi
sleep 1
count=`expr $count - 1`
done
if test $count -eq 0; then
echo "The file $file not read correctly." 1>&2
exit 1
fi
done
rm -f $img_file
rm -f $log_file
# Create a safe temporary file. # Create a safe temporary file.
test -n "$mkstemp" && log_file=`$mkstemp` test -n "$mklog" && log_file=`$mklog`
# Now perform the installation. # Now perform the installation.
$grub_shell --batch --device-map=$device_map <<EOF >$log_file $grub_shell --batch --device-map=$device_map <<EOF >$log_file