From: Pavel Roskin <proski@gnu.org>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: Failure to embed core.img is fatal now
Date: Wed, 25 Jun 2008 21:44:55 -0400 [thread overview]
Message-ID: <1214444695.18337.15.camel@dv> (raw)
In-Reply-To: <1214430514.11716.19.camel@dv>
On Wed, 2008-06-25 at 17:48 -0400, Pavel Roskin wrote:
> It turns out following happens in grub-setup:
>
> - core.img is read by the OS facilities
> - the memory image is modified
> - the memory image is compared to core.img read by GRUB FS code and fails
> - the memory image is modified again
> - first 2 sectors of the memory image are written to core.img
>
> I think the 2 sectors should be written before the image is read back.
> I tried to fix it, but it didn't work in the first try (GRUB hangs after
> showing "GRUB Loading kernel.")
It turns out the second sector is modified first. And the first sector
is modified with the locations of the subsequent sectors. Thus we
should either write the second sector before the first sector or keep an
unmodified image in memory to check that core.img can be read with the
GRUB filesystem code.
I'm not very concerned about memory consumption, but I think it would be
safer and easier to split writing sectors. We want to write as little
as possible to core.img after it have been tested for readability and
the blocks have been calculated.
ChangeLog:
* util/i386/pc/grub-setup.c (setup): If core.img cannot be
embedded, write the second sector before the reading with
GRUB filesystem code is tested, so that GRUB reads the
image with the changes made to the second sector.
diff --git a/util/i386/pc/grub-setup.c b/util/i386/pc/grub-setup.c
index 62c1bf1..d8cbb12 100644
--- a/util/i386/pc/grub-setup.c
+++ b/util/i386/pc/grub-setup.c
@@ -365,6 +365,15 @@ setup (const char *dir,
/* The core image must be put on a filesystem unfortunately. */
grub_util_info ("will leave the core image on the filesystem");
+ /* Write the second sector of the core image onto the disk. */
+ grub_util_info ("opening the core image `%s'", core_path);
+ fp = fopen (core_path, "r+b");
+ if (! fp)
+ grub_util_error ("Cannot open `%s'", core_path);
+ grub_util_write_image_at (core_img + GRUB_DISK_SECTOR_SIZE,
+ GRUB_DISK_SECTOR_SIZE, GRUB_DISK_SECTOR_SIZE, fp);
+ fclose (fp);
+
/* Make sure that GRUB reads the identical image as the OS. */
tmp_img = xmalloc (core_size);
core_path_dev = grub_util_get_path (DEFAULT_DIRECTORY, core_file);
@@ -485,13 +494,13 @@ setup (const char *dir,
the boot device. */
*root_drive = 0xFF;
- /* Write the first two sectors of the core image onto the disk. */
+ /* Write the first sector of the core image onto the disk. */
grub_util_info ("opening the core image `%s'", core_path);
fp = fopen (core_path, "r+b");
if (! fp)
grub_util_error ("Cannot open `%s'", core_path);
- grub_util_write_image (core_img, GRUB_DISK_SECTOR_SIZE * 2, fp);
+ grub_util_write_image (core_img, GRUB_DISK_SECTOR_SIZE, fp);
fclose (fp);
/* Write the boot image onto the disk. */
--
Regards,
Pavel Roskin
next prev parent reply other threads:[~2008-06-26 1:48 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-25 21:48 Failure to embed core.img is fatal now Pavel Roskin
2008-06-26 1:02 ` Javier Martín
2008-06-26 1:32 ` Pavel Roskin
2008-06-26 1:44 ` Pavel Roskin [this message]
2008-06-26 14:20 ` Robert Millan
2008-06-26 14:48 ` Pavel Roskin
2008-06-26 16:54 ` Pavel Roskin
2008-06-29 11:27 ` Robert Millan
2008-06-29 16:20 ` Pavel Roskin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1214444695.18337.15.camel@dv \
--to=proski@gnu.org \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.