X-Git-Url: http://git.grml.org/?p=grml2usb.git;a=blobdiff_plain;f=grml2usb;h=e32495426199f5abc5f9e7b07ea41c34fa77e429;hp=aa87484cd4e0361b1a6e3cd0a9b8b1aeb2cb0c10;hb=7a6e10df1c335b447ed9e60e2cc1226a42b5f5c8;hpb=f993114e6888d6d67fbe693096a967629c33ae9d diff --git a/grml2usb b/grml2usb index aa87484..e324954 100755 --- a/grml2usb +++ b/grml2usb @@ -105,12 +105,16 @@ parser.add_option("--remove-bootoption", dest="removeoption", action="append", help="regex for removing existing bootoptions") 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-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)") @@ -335,9 +339,29 @@ def check_uid_root(): raise CriticalException("please run this script with uid 0 (root).") +# for usage inside check_boot_flag +def get_partition_for_path(path): + import parted + + boot_dev, x = get_device_from_partition(path) + + d = parted.getDevice(boot_dev) + disk = parted.Disk(d) + return disk.getPartitionByPath(path) + + def check_boot_flag(device): boot_dev, x = get_device_from_partition(device) + try: + import parted + part = get_partition_for_path(device) + if part.getFlag(parted.PARTITION_BOOT): + logging.debug("bootflag is enabled on %s" % device) + return + except ImportError, e: + logging.debug("could not import parted, falling back to old bootflag detection") + with open(boot_dev, 'r') as image: data = image.read(520) bootcode = data[440:] @@ -350,7 +374,7 @@ def check_boot_flag(device): else: logging.debug("bootflag is NOT enabled") raise VerifyException("Device %s does not have the bootflag set. " - "Please enable it to be able to boot." % boot_dev) + "Please enable it to be able to boot." % device) def mkfs_fat16(device): @@ -621,6 +645,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 @@ -1530,7 +1558,8 @@ def install_grml(mountpoint, device): remove_device_mountpoint = True try: check_for_fat(device) - check_boot_flag(device) + if not options.skipbootflag: + check_boot_flag(device) mount(device, device_mountpoint, ['-o', 'utf8,iocharset=iso8859-1']) except CriticalException as error: mount(device, device_mountpoint, "") @@ -1584,6 +1613,7 @@ def handle_mbr(device): if options.syslinuxmbr: mbrcode = "" mbr_locations = ('/usr/lib/syslinux/mbr.bin', + '/usr/lib/syslinux/bios/mbr.bin', '/usr/share/syslinux/mbr.bin') for mbrpath in mbr_locations: if os.path.isfile(mbrpath): @@ -1641,6 +1671,10 @@ def handle_vfat(device): logging.critical("Execution failed: %s", error) 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: print("Warning: the specified device %s does not look like a removable usb device." % device) f = raw_input("Do you really want to continue? y/N ")