Ensure that grub-install doesn't receive emtpy command line argument
authorMichael Prokop <mika@grml.org>
Wed, 31 May 2017 09:20:26 +0000 (11:20 +0200)
committerMichael Prokop <mika@grml.org>
Wed, 31 May 2017 09:25:28 +0000 (11:25 +0200)
We run grub-install once without --force and if that fails
try rerunning with --force. On the first run we pass an
empty argument though that grub-install assumes as install
device and fails with:

  /usr/sbin/grub-install: error: More than one install device?.

By using "--" as option to signify the end of command line
options we avoid this failure in the run without passing the
--force option.

grml2usb

index e465ebe..c4d178a 100755 (executable)
--- a/grml2usb
+++ b/grml2usb
@@ -513,14 +513,15 @@ def install_grub(device):
             mount(device, device_mountpoint, "")
 
             logging.info("Installing grub as bootloader")
-            for opt in ["", "--force"]:
+            for opt in ["--", "--force"]:
                 set_rw(device)
                 set_rw(grub_device)
-                logging.debug("grub-install --recheck %s --no-floppy --root-directory=%s %s",
-                              opt, device_mountpoint, grub_device)
-                proc = subprocess.Popen([GRUB_INSTALL, "--recheck", opt,
+                logging.debug("%s --recheck --no-floppy --target=i386-pc --root-directory=%s %s %s",
+                              GRUB_INSTALL, device_mountpoint, opt, grub_device)
+                proc = subprocess.Popen([GRUB_INSTALL, "--recheck",
                                          "--no-floppy", "--target=i386-pc",
-                                         "--root-directory=%s" % device_mountpoint, grub_device],
+                                         "--root-directory=%s" % device_mountpoint,
+                                         opt, grub_device],
                                         stdout=file(os.devnull, "r+"))
                 proc.wait()
                 if proc.returncode == 0: