X-Git-Url: http://git.grml.org/?p=grml2usb.git;a=blobdiff_plain;f=grml2usb;h=223dae2a81c8e7c9d04cd9273b93b0659eafbafa;hp=fdc0caccec267551cda6676286dba7f2ddccfbe6;hb=9e7dd969c917d32365f2acb714c5c28e9c450dd3;hpb=aed7d831e1c9616cfeb4a2206d9e18bf7c8be24b diff --git a/grml2usb b/grml2usb index fdc0cac..223dae2 100755 --- a/grml2usb +++ b/grml2usb @@ -503,6 +503,12 @@ def get_partition_for_path(path): def check_boot_flag(device): + if os.path.isdir(device): + logging.debug( + "Device %s is a directory, skipping check for boot flag." % device + ) + return + boot_dev, x = get_device_from_partition(device) logging.info("Checking for boot flag") @@ -748,16 +754,14 @@ def install_mbr(mbrtemplate, device, partition, ismirbsdmbr=True): "mbrtemplate" file, set the "partition" (0..3) active, and install the result back to "device". - @mbrtemplate: default MBR file + @mbrtemplate: default MBR file (must be a valid MBR file of at least 440 + (or 439 if ismirbsdmbr) bytes) @device: name of a file assumed to be a hard disc (or USB stick) image, or something like "/dev/sdb" @partition: must be a number between 0 and 3, inclusive - @mbrtemplate: must be a valid MBR file of at least 440 (or 439 if - ismirbsdmbr) bytes. - @ismirbsdmbr: if true then ignore the active flag, set the mirbsdmbr specific flag to 0/1/2/3 and set the MBR's default value accordingly. If false then leave the mirbsdmbr specific flag set to FFh, set all @@ -875,6 +879,14 @@ def install_mbr(mbrtemplate, device, partition, ismirbsdmbr=True): proc = subprocess.Popen(["sync"]) proc.wait() + logging.debug("Probing device via 'blockdev --rereadpt %s'", device) + proc = subprocess.Popen(["blockdev", "--rereadpt", device]) + proc.wait() + if proc.returncode != 0: + raise Exception( + "Couldn't execute blockdev on '%s' (install util-linux?)", device + ) + set_rw(device) @@ -906,7 +918,7 @@ def mount(source, target, mount_options): if x.startswith(source): raise CriticalException( ( - "Error executing mount: %s already mounted - " + "Error executing mount: {0} already mounted - " "please unmount before invoking grml2usb" ).format(source) ) @@ -1875,10 +1887,6 @@ def install_grml(mountpoint, device): register_tmpfile(device_mountpoint) remove_device_mountpoint = True try: - check_for_fat(device) - if not options.skipbootflag: - check_boot_flag(device) - set_rw(device) mount(device, device_mountpoint, ["-o", "utf8,iocharset=iso8859-1"]) except CriticalException: @@ -1945,7 +1953,7 @@ def handle_mbr(device): break if not mbrcode: - str_locations = " or ".join(['"%s"' % l for l in mbr_locations]) + str_locations = " or ".join(['"%s"' % x for x in mbr_locations]) logging.error("Cannot find syslinux MBR, install it at %s)", str_locations) raise CriticalException( "syslinux MBR can not be found at %s." % str_locations @@ -2163,6 +2171,9 @@ def main(): # provide upgrade path handle_compat_warning(device) + if not options.skipbootflag: + check_boot_flag(device) + # check for vfat partition handle_vfat(device)