grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
From: Colin Watson <cjwatson@ubuntu.com>
To: grub-devel@gnu.org
Subject: Re: [PATCH] Fix grub-install with OS device name
Date: Wed, 4 Dec 2013 22:15:30 +0000	[thread overview]
Message-ID: <20131204221530.GA4445@riva.ucam.org> (raw)
In-Reply-To: <CADtfRCU-Yu6i-1Q+QNf4W0B1D9uHX64t_y65No+VdqXmqQUxbQ@mail.gmail.com>

On Wed, Dec 04, 2013 at 01:54:42PM -0800, Jonathan McCune wrote:
> Tested successfully on i386-pc in a QEMU VM.

Thanks.  I made a slight mistake, though, and broke the case of
"grub-install '(hd0)'", which is what Andrey had been trying to fix in
the first place.  Here's a better version which I've tested to handle
both OS and GRUB device forms successfully.

diff --git a/ChangeLog b/ChangeLog
index 8fba56c..c8072b5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2013-12-04  Colin Watson  <cjwatson@ubuntu.com>
+
+	* util/setup.c (SETUP): Accept new dev_is_drive argument.  If
+	passed, don't map dev to a GRUB drive again.
+	* include/grub/util/install.h (grub_util_bios_setup): Update
+	prototype.
+	(grub_util_sparc_setup): Likewise.
+	* util/grub-install.c (main): Tell grub_util_bios_setup that
+	install_drive has already been mapped to a GRUB drive.  Likewise for
+	grub_util_sparc_setup, and pass install_drive rather than
+	install_device.
+	* util/grub-setup.c (main): Adjust call to GRUB_SETUP_FUNC.
+
 2013-12-04  Vladimir Serbinenko  <phcoder@gmail.com>
 
 	* grub-core/boot/sparc64/ieee1275/boot.S [CDBOOT]: Move scratchpad
diff --git a/include/grub/util/install.h b/include/grub/util/install.h
index 4ba00f5..d1b4567 100644
--- a/include/grub/util/install.h
+++ b/include/grub/util/install.h
@@ -180,12 +180,12 @@ grub_install_get_image_target (const char *arg);
 void
 grub_util_bios_setup (const char *dir,
 		      const char *boot_file, const char *core_file,
-		      const char *dest, int force,
+		      const char *dev, int dev_is_drive, int force,
 		      int fs_probe, int allow_floppy);
 void
 grub_util_sparc_setup (const char *dir,
 		       const char *boot_file, const char *core_file,
-		       const char *dest, int force,
+		       const char *dev, int dev_is_drive, int force,
 		       int fs_probe, int allow_floppy);
 
 char *
diff --git a/util/grub-install.c b/util/grub-install.c
index 2d6ef75..3bb82fc 100644
--- a/util/grub-install.c
+++ b/util/grub-install.c
@@ -1436,11 +1436,12 @@ main (int argc, char *argv[])
 			platdir,
 			device_map,
 			install_device);
+	grub_util_info ("('%s' mapped to '%s')", install_device, install_drive);
 			
 	/*  Now perform the installation.  */
 	if (install_bootsector)
 	  grub_util_bios_setup (platdir, "boot.img", "core.img",
-				install_drive, force,
+				install_drive, 1, force,
 				fs_probe, allow_floppy);
 	break;
       }
@@ -1461,12 +1462,13 @@ main (int argc, char *argv[])
 			!fs_probe ? "--skip-fs-probe" : "",
 			platdir,
 			device_map,
-			install_drive);
+			install_device);
+	grub_util_info ("('%s' mapped to '%s')", install_device, install_drive);
 			
 	/*  Now perform the installation.  */
 	if (install_bootsector)
 	  grub_util_sparc_setup (platdir, "boot.img", "core.img",
-				 install_device, force,
+				 install_drive, 1, force,
 				 fs_probe, allow_floppy);
 	break;
       }
diff --git a/util/grub-setup.c b/util/grub-setup.c
index cc3af5d..6e8951e 100644
--- a/util/grub-setup.c
+++ b/util/grub-setup.c
@@ -254,7 +254,7 @@ main (int argc, char *argv[])
   GRUB_SETUP_FUNC (arguments.dir ? : DEFAULT_DIRECTORY,
 		   arguments.boot_file ? : DEFAULT_BOOT_FILE,
 		   arguments.core_file ? : DEFAULT_CORE_FILE,
-		   arguments.device, arguments.force,
+		   arguments.device, 0, arguments.force,
 		   arguments.fs_probe, arguments.allow_floppy);
 
   /* Free resources.  */
diff --git a/util/setup.c b/util/setup.c
index c1de3d2..7bf125d 100644
--- a/util/setup.c
+++ b/util/setup.c
@@ -247,7 +247,7 @@ identify_partmap (grub_disk_t disk __attribute__ ((unused)),
 void
 SETUP (const char *dir,
        const char *boot_file, const char *core_file,
-       const char *dev, int force,
+       const char *dev, int dev_is_drive, int force,
        int fs_probe, int allow_floppy)
 {
   char *core_path;
@@ -271,6 +271,7 @@ SETUP (const char *dir,
   bl.last_length = 0;
 
   {
+    /* Perhaps the user specified a parenthesised GRUB drive name.  */
     size_t len = strlen (dev);
 
     if (len > 2 && dev[0] == '(' && dev[len - 1] == ')')
@@ -283,12 +284,18 @@ SETUP (const char *dir,
 
   if (! dest)
     {
-      /* Possibly, the user specified an OS device file.  */
-      dest = grub_util_get_grub_dev (dev);
-      if (! dest)
-          grub_util_error (_("Invalid device `%s'.\n"), dev);
-      grub_util_info ("transformed OS device `%s' into GRUB device `%s'",
-                      dev, dest);
+      if (dev_is_drive)
+	dest = xstrdup (dev);
+      else
+	{
+	  /* Possibly, the user specified an OS device file.  */
+	  grub_util_pull_device (dev);
+	  dest = grub_util_get_grub_dev (dev);
+	  if (! dest)
+	    grub_util_error (_("Invalid device `%s'.\n"), dev);
+	  grub_util_info ("transformed OS device `%s' into GRUB device `%s'",
+			  dev, dest);
+	}
     }
 
 
-- 
1.8.4.4


-- 
Colin Watson                                       [cjwatson@ubuntu.com]


  reply	other threads:[~2013-12-04 22:15 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-04 21:39 [PATCH] Fix grub-install with OS device name Colin Watson
2013-12-04 21:54 ` Jonathan McCune
2013-12-04 22:15   ` Colin Watson [this message]
2013-12-05  5:56     ` arvidjaar
2013-12-05  7:08       ` Andrey Borzenkov
2013-12-07  8:44         ` [PATCH 1/2] revert 69ca97c820, it broke using OS device name as install device Andrey Borzenkov
2013-12-07  8:44           ` [PATCH 2/2] second attempt to fix using grub " Andrey Borzenkov
2013-12-07  8:47             ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-12-07  9:40               ` Andrey Borzenkov
2013-12-07  9:42                 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-12-07 10:19                   ` [PATCH 2/2 v2] " Andrey Borzenkov
2013-12-07 13:50                     ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-12-07 13:59                       ` Andrey Borzenkov
2013-12-07 14:14                         ` Vladimir 'φ-coder/phcoder' Serbinenko

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=20131204221530.GA4445@riva.ucam.org \
    --to=cjwatson@ubuntu.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).