X-Git-Url: http://git.grml.org/?p=grml2usb.git;a=blobdiff_plain;f=grml2usb;h=3ca38a5c0d9dec415800965a9296ec49624ce4a9;hp=0a34583c9b17e3b9074c9cbb1936a93e34f0627a;hb=0deeae3373cffe3a007b8bf6c0b642830601c9b7;hpb=7c076d1dd83dc76e700f430d33d81507c322de30 diff --git a/grml2usb b/grml2usb index 0a34583..3ca38a5 100755 --- a/grml2usb +++ b/grml2usb @@ -60,10 +60,10 @@ def grub_option(option, opt, value, opt_parser): setattr(opt_parser.values, 'syslinux', False) # cmdline parsing -USAGE = "Usage: %prog [options] <[ISO[s] | /live/image]> \n\ +USAGE = "Usage: %prog [options] <[ISO[s] | /lib/live/mount/medium]> \n\ \n\ -%prog installs grml ISO[s] to an USB device to be able to boot from it.\n\ -Make sure you have at least one grml ISO or a running grml system (/live/image),\n\ +%prog installs Grml ISO[s] to an USB device to be able to boot from it.\n\ +Make sure you have at least one Grml ISO or a running Grml system (/lib/live/mount/medium),\n\ grub or syslinux and root access.\n\ \n\ Run %prog --help for usage hints, further information via: man grml2usb" @@ -108,6 +108,8 @@ parser.add_option("--syslinux", dest="syslinux", action="callback", default=True help="install syslinux bootloader (deprecated as it's the default)") parser.add_option("--syslinux-mbr", dest="syslinuxmbr", action="store_true", help="install syslinux master boot record (MBR) instead of default") +parser.add_option("--tmpdir", dest="tmpdir", default="/tmp", + help="directory to be used for temporary files") parser.add_option("--verbose", dest="verbose", action="store_true", help="enable verbose mode") parser.add_option("-v", "--version", dest="version", action="store_true", @@ -126,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 @@ -303,6 +311,23 @@ def check_uid_root(): sys.exit("Error: please run this script with uid 0 (root).") +def check_boot_flag(device): + if device[-1:].isdigit(): + boot_dev = re.match(r'(.*?)\d*$', device).group(1) + else: + boot_dev = device + + with open(boot_dev, '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." % boot_dev) + + def mkfs_fat16(device): """Format specified device with VFAT/FAT16 filesystem. @@ -902,22 +927,15 @@ def copy_addons(iso_mount, target): # grub all-in-one image handle_addon_copy('allinone.img', addons, iso_mount) - # bsd imag + # bsd image handle_addon_copy('bsd4grml', addons, iso_mount) + # DOS image handle_addon_copy('balder10.imz', addons, iso_mount) - # install hdt and pci.ids only when using syslinux (grub doesn't support it) - if options.syslinux: - # hdt (hardware detection tool) image - hdtimg = search_file('hdt.c32', iso_mount) - if hdtimg: - exec_rsync(hdtimg, addons + '/hdt.c32') - - # pci.ids file - picids = search_file('pci.ids', iso_mount) - if picids: - exec_rsync(picids, addons + '/pci.ids') + # syslinux + pci.ids for hdt + for expr in '*.c32', 'pci.ids': + glob_and_copy(iso_mount + '/boot/addons/' + expr, addons) # memdisk image handle_addon_copy('memdisk', addons, iso_mount) @@ -1113,8 +1131,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.") - raise + if mountpath.startswith("/lib/live/mount/medium"): + 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) @@ -1436,7 +1462,7 @@ def install(image, device): logging.info("Using %s as install base", image) else: logging.info("Using ISO %s", image) - iso_mountpoint = tempfile.mkdtemp(prefix="grml2usb") + iso_mountpoint = tempfile.mkdtemp(prefix="grml2usb", dir=options.tmpdir) register_tmpfile(iso_mountpoint) remove_image_mountpoint = True try: @@ -1459,12 +1485,12 @@ def install(image, device): def install_grml(mountpoint, device): """Main logic for copying files of the currently running grml system. - @mountpoin: directory where currently running live system resides (usually /live/image) + @mountpoint: directory where currently running live system resides (usually /lib/live/mount/medium) @device: partition where the specified ISO should be installed to""" device_mountpoint = device if os.path.isdir(device): - logging.info("Specified device is not a directory, therefore not mounting.") + logging.info("Specified device is a directory, therefore not mounting.") remove_device_mountpoint = False else: device_mountpoint = tempfile.mkdtemp(prefix="grml2usb") @@ -1472,7 +1498,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, "")