grub-devel
[Top][All Lists]
Advanced

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

Re: Failure to embed core.img is fatal now


From: Pavel Roskin
Subject: Re: Failure to embed core.img is fatal now
Date: Wed, 25 Jun 2008 21:44:55 -0400

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




reply via email to

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