X-Git-Url: https://git.grml.org/?p=grml2usb.git;a=blobdiff_plain;f=grml2usb;h=16b53cd85c4da0b6e3b42e0b89a109574ad531d4;hp=63c26b37598958f301eed341a6efe1412626b52c;hb=3f80e5a0eb34b5b73961de842a0e7fbf0a510011;hpb=5251ce1484272c48247551148a59dbd6bb13f6f1 diff --git a/grml2usb b/grml2usb index 63c26b3..16b53cd 100755 --- a/grml2usb +++ b/grml2usb @@ -128,6 +128,12 @@ class CriticalException(Exception): @Exception: message""" pass +class VerifyException(Exception): + """Throw critical exception if there is an fatal error when verifying something. + + @Exception: message""" + pass + # The following two functions help to operate on strings as # array (list) of bytes (octets). In Python 3000, the bytes @@ -305,6 +311,18 @@ def check_uid_root(): sys.exit("Error: please run this script with uid 0 (root).") +def check_boot_flag(device): + with open(device, 'r') as image: + data = image.read(512) + bootcode = data[440:] + if bootcode[6] == '\x80': + logging.debug("bootflag is enabled") + 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." % device) + + def mkfs_fat16(device): """Format specified device with VFAT/FAT16 filesystem. @@ -1108,9 +1126,16 @@ def identify_grml_flavour(mountpath): version_files = search_file('grml-version', mountpath, lst_return=True) if not version_files: - logging.critical("Error: could not find grml-version file.") - cleanup() - sys.exit(1) + if mountpath.startswith("/live/image"): + logging.critical("Error: could not find grml-version file.") + logging.critical("Looks like your system is running from RAM but required files are not available.") + logging.critical("Please either boot without toram=... or use boot option toram instead of toram=...") + cleanup() + sys.exit(1) + else: + logging.critical("Error: could not find grml-version file.") + cleanup() + sys.exit(1) flavours = [] logging.debug("version_files = %s", version_files) @@ -1468,7 +1493,11 @@ def install_grml(mountpoint, device): remove_device_mountpoint = True try: check_for_fat(device) + check_boot_flag(device) mount(device, device_mountpoint, ['-o', 'utf8,iocharset=iso8859-1']) + except VerifyException, error: + logging.critical("Fatal: %s", error) + raise except CriticalException, error: try: mount(device, device_mountpoint, "")