X-Git-Url: http://git.grml.org/?p=grml2usb.git;a=blobdiff_plain;f=grml2usb;h=2f63ce148a9db528e164115e2db2979114dea065;hp=d09e510814bbf9e8b79137b5603f052f303b8c39;hb=745f09771c1a7cfd9607d3300a55ee8ddbd59fac;hpb=4a2ffdd1ae73528596b60e342fdaa3addc5fdd1a diff --git a/grml2usb b/grml2usb index d09e510..2f63ce1 100755 --- a/grml2usb +++ b/grml2usb @@ -107,14 +107,14 @@ parser.add_option("--skip-addons", dest="skipaddons", action="store_true", help="do not install /boot/addons/ files") parser.add_option("--skip-bootflag", dest="skipbootflag", action="store_true", help="do not try to check whether the destination has the bootflag set") -parser.add_option("--skip-usb-check", dest="skipusbcheck", action="store_true", - help="skip check to verify whether given device is removable") parser.add_option("--skip-grub-config", dest="skipgrubconfig", action="store_true", help="skip generation of grub configuration files") parser.add_option("--skip-mbr", dest="skipmbr", action="store_true", help="do not install a master boot record (MBR) on the device") parser.add_option("--skip-syslinux-config", dest="skipsyslinuxconfig", action="store_true", help="skip generation of syslinux configuration files") +parser.add_option("--skip-usb-check", dest="skipusbcheck", action="store_true", + help="skip check to verify whether given device is removable") parser.add_option("--syslinux", dest="syslinux", action="callback", default=True, callback=syslinux_warning, help="install syslinux bootloader (deprecated as it's the default)") @@ -134,6 +134,12 @@ if not os.path.isdir(GRML2USB_BASE): GRML2USB_BASE = os.path.dirname(os.path.realpath(__file__)) +class HodorException(Exception): + """Throw exception if the exact error is not known and not fatal. + + @Exception: message""" + + class CriticalException(Exception): """Throw critical exception if the exact error is not known but fatal. @@ -356,9 +362,13 @@ def check_boot_flag(device): try: import parted part = get_partition_for_path(device) + if part is None: + raise HodorException("parted could not find partition") if part.getFlag(parted.PARTITION_BOOT): logging.debug("bootflag is enabled on %s" % device) return + except HodorException, e: + logging.info("%s, falling back to old bootflag detection", e) except ImportError, e: logging.debug("could not import parted, falling back to old bootflag detection") @@ -493,7 +503,8 @@ def install_grub(device): for opt in ["", "--force"]: logging.debug("grub-install --recheck %s --no-floppy --root-directory=%s %s", opt, device_mountpoint, grub_device) - proc = subprocess.Popen([GRUB_INSTALL, "--recheck", opt, "--no-floppy", + proc = subprocess.Popen([GRUB_INSTALL, "--recheck", opt, + "--no-floppy", "--target=i386-pc", "--root-directory=%s" % device_mountpoint, grub_device], stdout=file(os.devnull, "r+")) proc.wait() @@ -645,6 +656,10 @@ def install_mbr(mbrtemplate, device, partition, ismirbsdmbr=True): raise Exception("error executing dd (third run)") del tmpf + # make sure we sync filesystems before returning + proc = subprocess.Popen(["sync"]) + proc.wait() + def is_writeable(device): """Check if the device is writeable for the current user @@ -1287,7 +1302,7 @@ def initial_syslinux_config(target): def add_entry_if_not_present(filename, entry): """Write entry into filename if entry is not already in the file - @filanme: name of the file + @filename: name of the file @entry: data to write to the file """ data = open(filename, "a+") @@ -1668,6 +1683,7 @@ def handle_vfat(device): sys.exit(1) if options.skipusbcheck: + logging.info("Not checking for removable USB device as requested via option --skip-usb-check.") return if not os.path.isdir(device) and not check_for_usbdevice(device) and not options.force: @@ -1731,6 +1747,9 @@ def check_options(opts): if opts.grubmbr and not opts.grub: raise CriticalException("--grub-mbr requires --grub option.") + if opts.copyonly and opts.grub: + raise CriticalException("Cannot use --copy-only and --grub at the same time.") + def check_programs(): """check if all needed programs are installed"""