- mount(device, device_mountpoint, "")
- logging.debug("grub-install --recheck --no-floppy --root-directory=%s %s", device_mountpoint, device)
- proc = subprocess.Popen(["grub-install", "--recheck", "--no-floppy",
- "--root-directory=%s" % device_mountpoint, device], stdout=file(os.devnull, "r+"))
- proc.wait()
- if proc.returncode != 0:
- # raise Exception("error executing grub-install")
- logging.critical("Fatal: error executing grub-install (please check the grml2usb FAQ)" % error)
+ try:
+ mount(device, device_mountpoint, "")
+
+ # If using --grub-mbr then make sure we install grub in MBR instead of PBR
+ # Thanks to grub2. NOT.
+ if options.grubmbr:
+ logging.debug("Using option --grub-mbr ...")
+ if device[-1:].isdigit():
+ grub_device = re.match(r'(.*?)\d*$', device).group(1)
+ else:
+ grub_device = device
+ else:
+ grub_device = device
+
+ logging.debug("grub-install --recheck --no-floppy --root-directory=%s %s",
+ device_mountpoint, grub_device)
+ proc = subprocess.Popen(["grub-install", "--recheck", "--no-floppy",
+ "--root-directory=%s" % device_mountpoint, grub_device], stdout=file(os.devnull, "r+"))
+ proc.wait()
+ if proc.returncode != 0:
+ # raise Exception("error executing grub-install")
+ logging.critical("Fatal: error executing grub-install (please check the grml2usb FAQ or use --syslinux)")
+ logging.critical("Note: if using grub2 consider using the --grub-mbr option because grub2's PBR feature is broken.")
+ cleanup()
+ sys.exit(1)
+ except CriticalException, error:
+ logging.critical("Fatal: %s", error)