2 # -*- coding: utf-8 -*-
3 # pylint: disable-msg=C0302
8 This script installs a grml system (either a running system or ISO[s]) to a USB device
10 :copyright: (c) 2009 by Michael Prokop <mika@grml.org>
11 :license: GPL v2 or any later version
12 :bugreports: http://grml.org/bugs/
16 from optparse import OptionParser
17 from inspect import isroutine, isclass
18 import datetime, logging, os, re, subprocess, sys, tempfile, time, os.path
25 PROG_VERSION = "0.9.28"
26 MOUNTED = set() # register mountpoints
27 TMPFILES = set() # register tmpfiles
28 DATESTAMP = time.mktime(datetime.datetime.now().timetuple()) # unique identifier for syslinux.cfg
29 GRML_FLAVOURS = set() # which flavours are being installed?
32 SYSLINUX_LIBS = "/usr/lib/syslinux/"
34 def syslinux_warning(option, opt, value, opt_parser):
35 """A helper function for printing a warning about deprecated option
37 # pylint: disable-msg=W0613
38 sys.stderr.write("Note: the --syslinux option is deprecated as syslinux "
39 "is grml2usb's default. Continuing anyway.\n")
40 setattr(opt_parser.values, option.dest, True)
42 # if grub option is set, unset syslinux option
43 def grub_option(option, opt, value, opt_parser):
44 """A helper function adjusting other option values
46 # pylint: disable-msg=W0613
47 setattr(opt_parser.values, option.dest, True)
48 setattr(opt_parser.values, 'syslinux', False)
51 USAGE = "Usage: %prog [options] <[ISO[s] | /live/image]> </dev/sdX#>\n\
53 %prog installs grml ISO[s] to an USB device to be able to boot from it.\n\
54 Make sure you have at least one grml ISO or a running grml system (/live/image),\n\
55 grub or syslinux and root access.\n\
57 Run %prog --help for usage hints, further information via: man grml2usb"
59 # pylint: disable-msg=C0103
60 # pylint: disable-msg=W0603
61 parser = OptionParser(usage=USAGE)
62 parser.add_option("--bootoptions", dest="bootoptions",
63 action="store", type="string",
64 help="use specified bootoptions as default")
65 parser.add_option("--bootloader-only", dest="bootloaderonly", action="store_true",
66 help="do not copy files but just install a bootloader")
67 parser.add_option("--copy-only", dest="copyonly", action="store_true",
68 help="copy files only but do not install bootloader")
69 parser.add_option("--dry-run", dest="dryrun", action="store_true",
70 help="avoid executing commands")
71 parser.add_option("--fat16", dest="fat16", action="store_true",
72 help="format specified partition with FAT16")
73 parser.add_option("--force", dest="force", action="store_true",
74 help="force any actions requiring manual interaction")
75 parser.add_option("--grub", dest="grub", action="callback",
77 help="install grub bootloader instead of (default) syslinux")
78 parser.add_option("--grub-mbr", dest="grubmbr", action="store_true",
79 help="install grub into MBR instead of (default) PBR")
80 parser.add_option("--lilo-binary", dest="lilobin", action="store", type="string",
81 help="lilo executable to be used for installing MBR")
82 parser.add_option("--mbr-menu", dest="mbrmenu", action="store_true",
83 help="enable interactive boot menu in MBR")
84 parser.add_option("--quiet", dest="quiet", action="store_true",
85 help="do not output anything but just errors on console")
86 parser.add_option("--remove-bootoption", dest="removeoption", action="append",
87 help="regex for removing existing bootoptions")
88 parser.add_option("--skip-addons", dest="skipaddons", action="store_true",
89 help="do not install /boot/addons/ files")
90 parser.add_option("--skip-grub-config", dest="skipgrubconfig", action="store_true",
91 help="skip generation of grub configuration files")
92 parser.add_option("--skip-mbr", dest="skipmbr", action="store_true",
93 help="do not install a master boot record (MBR) on the device")
94 parser.add_option("--skip-syslinux-config", dest="skipsyslinuxconfig", action="store_true",
95 help="skip generation of syslinux configuration files")
96 parser.add_option("--syslinux", dest="syslinux", action="callback", default=True,
97 callback=syslinux_warning,
98 help="install syslinux bootloader (deprecated as it's the default)")
99 parser.add_option("--syslinux-mbr", dest="syslinuxmbr", action="store_true",
100 help="install syslinux master boot record (MBR) instead of default")
101 parser.add_option("--verbose", dest="verbose", action="store_true",
102 help="enable verbose mode")
103 parser.add_option("-v", "--version", dest="version", action="store_true",
104 help="display version and exit")
105 (options, args) = parser.parse_args()
108 GRML2USB_BASE = '/usr/share/grml2usb'
109 if not os.path.isdir(GRML2USB_BASE):
110 GRML2USB_BASE = os.path.dirname(os.path.realpath(__file__))
113 class CriticalException(Exception):
114 """Throw critical exception if the exact error is not known but fatal."
116 @Exception: message"""
120 # The following two functions help to operate on strings as
121 # array (list) of bytes (octets). In Python 3000, the bytes
122 # datatype will need to be used. This is intended for using
123 # with manipulation of files on the octet level, like shell
124 # arrays, e.g. in MBR creation.
127 def array2string(*a):
128 """Convert a list of integers [0;255] to a string."""
129 return struct.pack("%sB" % len(a), *a)
133 """Convert a (bytes) string into a list of integers."""
134 return struct.unpack("%sB" % len(s), s)
138 """Cleanup function to make sure there aren't any mounted devices left behind.
141 logging.info("Cleaning up before exiting...")
142 proc = subprocess.Popen(["sync"])
146 for device in MOUNTED:
148 for tmpfile in TMPFILES:
150 # ignore: RuntimeError: Set changed size during iteration
152 logging.debug('caught expection RuntimeError, ignoring')
155 def register_tmpfile(path):
163 def unregister_tmpfile(path):
165 remove registered tmpfile
169 TMPFILES.remove(path)
174 def register_mountpoint(target):
175 """register specified target in a set() for handling clean exiting
177 @target: destination target of mountpoint
183 def unregister_mountpoint(target):
184 """unregister specified target in a set() for handling clean exiting
186 @target: destination target of mountpoint
189 if target in MOUNTED:
190 MOUNTED.remove(target)
193 def get_function_name(obj):
194 """Helper function for use in execute() to retrive name of a function
196 @obj: the function object
198 if not (isroutine(obj) or isclass(obj)):
200 return obj.__module__ + '.' + obj.__name__
203 def execute(f, *exec_arguments):
204 """Wrapper for executing a command. Either really executes
205 the command (default) or when using --dry-run commandline option
206 just displays what would be executed."""
207 # usage: execute(subprocess.Popen, (["ls", "-la"]))
209 # pylint: disable-msg=W0141
210 logging.debug('dry-run only: %s(%s)', get_function_name(f), ', '.join(map(repr, exec_arguments)))
212 # pylint: disable-msg=W0142
213 return f(*exec_arguments)
217 """Check whether a given file can be executed
219 @fpath: full path to file
221 return os.path.exists(fpath) and os.access(fpath, os.X_OK)
225 """Check whether a given program is available in PATH
227 @program: name of executable"""
228 fpath = os.path.split(program)[0]
233 for path in os.environ["PATH"].split(os.pathsep):
234 exe_file = os.path.join(path, program)
241 def get_defaults_file(iso_mount, flavour, name):
242 """get the default file for syslinux
244 bootloader_dirs = ['/boot/isolinux/', '/boot/syslinux/']
245 for directory in bootloader_dirs:
247 "%s_%s" % (get_flavour_filename(flavour), name):
248 if os.path.isfile(iso_mount + directory + name):
249 return (directory, name)
252 def search_file(filename, search_path='/bin' + os.pathsep + '/usr/bin'):
253 """Given a search path, find file
255 @filename: name of file to search for
256 @search_path: path where searching for the specified filename"""
258 paths = search_path.split(os.pathsep)
259 current_dir = '' # make pylint happy :)
262 """Helper function ffor testing if specified file exists in cwd
264 @cwd: current working directory
266 return os.path.exists(os.path.join(cwd, filename))
270 if match_file(current_dir):
273 # pylint: disable-msg=W0612
274 for current_dir, directories, files in os.walk(path):
275 if match_file(current_dir):
279 return os.path.abspath(os.path.join(current_dir, filename))
284 def check_uid_root():
285 """Check for root permissions"""
286 if not os.geteuid()==0:
287 sys.exit("Error: please run this script with uid 0 (root).")
290 def mkfs_fat16(device):
291 """Format specified device with VFAT/FAT16 filesystem.
293 @device: partition that should be formated"""
296 logging.info("Would execute mkfs.vfat -F 16 %s now.", device)
299 logging.info("Formating partition with fat16 filesystem")
300 logging.debug("mkfs.vfat -F 16 %s", device)
301 proc = subprocess.Popen(["mkfs.vfat", "-F", "16", device])
303 if proc.returncode != 0:
304 raise CriticalException("error executing mkfs.vfat")
307 def generate_main_grub2_config(grml_flavour, bootoptions):
308 """Generate grub2 configuration for use via grub.cfg
310 @grml_flavour: name of grml flavour the configuration should be generated for
311 @bootoptions: additional bootoptions that should be used by default"""
313 local_datestamp = DATESTAMP
316 ## main grub2 configuration - generated by grml2usb [main config generated at: %(local_datestamp)s]
322 if loadfont /boot/grub/ascii.pf2 ; then
327 if terminal_output.gfxterm ; then true ; else
328 # For backward compatibility with versions of terminal.mod that don't
329 # understand terminal_output
334 if background_image /boot/grub/grml.png ; then
335 set color_normal=black/black
336 set color_highlight=red/black
338 set menu_color_normal=white/black
339 set menu_color_highlight=black/yellow
342 menuentry "%(grml_flavour)s (default)" {
343 set gfxpayload=1024x768x16,1024x768
344 linux /boot/release/%(flavour_filename)s/linux26 apm=power-off quiet boot=live nomce live-media-path=/live/%(grml_flavour)s/ bootid=%(uid)s %(bootoptions)s
345 initrd /boot/release/%(flavour_filename)s/initrd.gz
348 menuentry "Memory test (memtest86+)" {
349 linux16 /boot/addons/memtest
352 menuentry "Boot Grub (all in one image)" {
353 linux /boot/addons/memdisk
354 initrd /boot/addons/allinone.img
357 menuentry "Boot FreeDOS" {
358 linux /boot/addons/memdisk
359 initrd /boot/addons/balder10.imz
362 menuentry "Boot MirOS bsd4grml" {
363 multiboot /boot/addons/bsd4grml/ldbsd.com
364 module /boot/addons/bsd4grml/bsd.rd
365 module /boot/addons/bsd4grml/boot.1
366 module /boot/addons/bsd4grml/boot.2
367 module /boot/addons/bsd4grml/boot.3
368 module /boot/addons/bsd4grml/boot.4
369 module /boot/addons/bsd4grml/boot.5
370 module /boot/addons/bsd4grml/boot.6
371 module /boot/addons/bsd4grml/boot.cfg
374 menuentry "Boot OS of first partition on first disk" {
379 """ % {'grml_flavour': grml_flavour, 'local_datestamp': local_datestamp,
380 'flavour_filename': grml_flavour.replace('-', ''),
381 'uid': UUID, 'bootoptions': bootoptions } )
384 def generate_flavour_specific_grub2_config(grml_flavour, bootoptions):
385 """Generate grub2 configuration for use via grub.cfg
387 @grml_flavour: name of grml flavour the configuration should be generated for
388 @bootoptions: additional bootoptions that should be used by default"""
390 local_datestamp = DATESTAMP
393 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
394 menuentry "%(grml_flavour)s - boot in default mode" {
395 set gfxpayload=1024x768x16,1024x768
396 linux /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce quiet live-media-path=/live/%(grml_flavour)s/ bootid=%(uid)s %(bootoptions)s
397 initrd /boot/release/%(flavour_filename)s/initrd.gz
400 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
401 menuentry "%(grml_flavour)s-persistent - enable persistency feature" {
402 set gfxpayload=1024x768x16,1024x768
403 linux /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce quiet persistent live-media-path=/live/%(grml_flavour)s/ bootid=%(uid)s %(bootoptions)s
404 initrd /boot/release/%(flavour_filename)s/initrd.gz
407 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
408 menuentry "%(grml_flavour)s2ram - copy compressed grml file to RAM" {
409 set gfxpayload=1024x768x16,1024x768
410 linux /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce quiet live-media-path=/live/%(grml_flavour)s/ toram=%(grml_flavour)s.squashfs bootid=%(uid)s %(bootoptions)s
411 initrd /boot/release/%(flavour_filename)s/initrd.gz
414 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
415 menuentry "%(grml_flavour)s-debug - enable debugging options" {
416 set gfxpayload=1024x768x16,1024x768
417 linux /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce quiet live-media-path=/live/%(grml_flavour)s/ debug bootid=%(uid)s initcall_debug %(bootoptions)s
418 initrd /boot/release/%(flavour_filename)s/initrd.gz
421 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
422 menuentry "%(grml_flavour)s-x - start X Window System" {
423 set gfxpayload=1024x768x16,1024x768
424 linux /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce quiet live-media-path=/live/%(grml_flavour)s/ startx=wm-ng bootid=%(uid)s %(bootoptions)s
425 initrd /boot/release/%(flavour_filename)s/initrd.gz
428 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
429 menuentry "%(grml_flavour)s-nofb - disable framebuffer" {
430 linux /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce quiet live-media-path=/live/%(grml_flavour)s/ vga=normal video=ofonly bootid=%(uid)s %(bootoptions)s
431 initrd /boot/release/%(flavour_filename)s/initrd.gz
434 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
435 menuentry "%(grml_flavour)s-failsafe - disable hardware detection" {
436 linux /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce quiet live-media-path=/live/%(grml_flavour)s/ vga=normal noautoconfig atapicd noapic noacpi acpi=off nomodules nofirewire noudev nousb nohotplug noapm nopcmcia nosmp maxcpus=0 noscsi noagp nodma ide=nodma noswap nofstab nosound nogpm nosyslog nodhcp nocpu nodisc nomodem xmodule=vesa noraid nolvm noresume selinux=0 edd=off pci=nomsi bootid=%(uid)s %(bootoptions)s
437 initrd /boot/release/%(flavour_filename)s/initrd.gz
440 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
441 menuentry "%(grml_flavour)s-forensic - do not touch harddisks during hw recognition" {
442 set gfxpayload=1024x768x16,1024x768
443 linux /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce quiet live-media-path=/live/%(grml_flavour)s/ nofstab noraid nolvm noautoconfig noswap raid=noautodetect forensic readonly bootid=%(uid)s %(bootoptions)s
444 initrd /boot/release/%(flavour_filename)s/initrd.gz
447 """ % {'grml_flavour': grml_flavour, 'local_datestamp': local_datestamp,
448 'flavour_filename': grml_flavour.replace('-', ''),
449 'uid': UUID, 'bootoptions': bootoptions } )
452 def generate_flavour_specific_grub1_config(grml_flavour, install_partition, bootoptions):
453 """Generate grub1 configuration for use via menu.lst
455 @grml_flavour: name of grml flavour the configuration should be generated for
456 @install_partition: partition number for use in (hd0,X)
457 @bootoptions: additional bootoptions that should be used by default"""
459 local_datestamp = DATESTAMP
462 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
463 title %(grml_flavour)s
464 kernel (hd0,%(install_partition)s)/boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce vga=791 quiet live-media-path=/live/%(grml_flavour)s/ bootid=%(uid)s %(bootoptions)s
465 initrd (hd0,%(install_partition)s)/boot/release/%(flavour_filename)s/initrd.gz
467 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
468 title %(grml_flavour)s-persistent
469 kernel (hd0,%(install_partition)s)/boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce vga=791 quiet persistent live-media-path=/live/%(grml_flavour)s/ bootid=%(uid)s %(bootoptions)s
470 initrd (hd0,%(install_partition)s)/boot/release/%(flavour_filename)s/initrd.gz
472 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
473 title %(grml_flavour)s2ram
474 kernel (hd0,%(install_partition)s)/boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce vga=791 quiet live-media-path=/live/%(grml_flavour)s/ toram=%(grml_flavour)s.squashfs bootid=%(uid)s %(bootoptions)s
475 initrd (hd0,%(install_partition)s)/boot/release/%(flavour_filename)s/initrd.gz
477 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
478 title %(grml_flavour)s-debug
479 kernel (hd0,%(install_partition)s)/boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce vga=791 quiet live-media-path=/live/%(grml_flavour)s/ debug initcall_debug bootid=%(uid)s %(bootoptions)s
480 initrd (hd0,%(install_partition)s)/boot/release/%(flavour_filename)s/initrd.gz
482 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
483 title %(grml_flavour)s-x
484 kernel (hd0,%(install_partition)s)/boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce vga=791 quiet live-media-path=/live/%(grml_flavour)s/ startx=wm-ng bootid=%(uid)s %(bootoptions)s
485 initrd (hd0,%(install_partition)s)/boot/release/%(flavour_filename)s/initrd.gz
487 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
488 title %(grml_flavour)s-nofb
489 kernel (hd0,%(install_partition)s)/boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce quiet live-media-path=/live/%(grml_flavour)s/ vga=normal video=ofonly bootid=%(uid)s %(bootoptions)s
490 initrd (hd0,%(install_partition)s)/boot/release/%(flavour_filename)s/initrd.gz
492 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
493 title %(grml_flavour)s-failsafe
494 kernel (hd0,%(install_partition)s)/boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce quiet live-media-path=/live/%(grml_flavour)s/ vga=normal noautoconfig atapicd noapic noacpi acpi=off nomodules nofirewire noudev nousb nohotplug noapm nopcmcia nosmp maxcpus=0 noscsi noagp nodma ide=nodma noswap nofstab nosound nogpm nosyslog nodhcp nocpu nodisc nomodem xmodule=vesa noraid nolvm noresume selinux=0 edd=off pci=nomsi bootid=%(uid)s %(bootoptions)s
495 initrd (hd0,%(install_partition)s)/boot/release/%(flavour_filename)s/initrd.gz
497 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
498 title %(grml_flavour)s-forensic
499 kernel (hd0,%(install_partition)s)/boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce vga=791 quiet live-media-path=/live/%(grml_flavour)s/ nofstab noraid nolvm noautoconfig noswap raid=noautodetect forensic readonly bootid=%(uid)s %(bootoptions)s
500 initrd (hd0,%(install_partition)s)/boot/release/%(flavour_filename)s/initrd.gz
502 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
503 title %(grml_flavour)s-serial
504 kernel (hd0,%(install_partition)s)/boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce quiet live-media-path=/live/%(grml_flavour)s/ vga=normal video=vesafb:off console=tty1 console=ttyS0,9600n8 bootid=%(uid)s %(bootoptions)s
505 initrd (hd0,%(install_partition)s)/boot/release/%(flavour_filename)s/initrd.gz
507 """ % {'grml_flavour': grml_flavour, 'local_datestamp': local_datestamp,
508 'flavour_filename': grml_flavour.replace('-', ''), 'uid': UUID,
509 'bootoptions': bootoptions, 'install_partition': install_partition } )
512 def generate_main_grub1_config(grml_flavour, install_partition, bootoptions):
513 """Generate grub1 configuration for use via menu.lst
515 @grml_flavour: name of grml flavour the configuration should be generated for"""
517 local_datestamp = DATESTAMP
520 ## main grub1 configuration - generated by grml2usb [main config generated at: %(local_datestamp)s]
523 # color red/blue green/black
524 splashimage=(hd0,%(install_partition)s)/boot/grub/splash.xpm.gz
529 title %(grml_flavour)s - Default boot (using 1024x768 framebuffer)
530 kernel (hd0,%(install_partition)s)/boot/release/%(flavour_filename)s/linux26 apm=power-off vga=791 quiet boot=live nomce live-media-path=/live/%(grml_flavour)s/ bootid=%(uid)s %(bootoptions)s
531 initrd (hd0,%(install_partition)s)/boot/release/%(flavour_filename)s/initrd.gz
533 title Memory test (memtest86+)
534 kernel (hd0,%(install_partition)s)/boot/addons/memtest
536 title Grub - all in one image
537 kernel (hd0,%(install_partition)s)/boot/addons/memdisk
538 initrd (hd0,%(install_partition)s)/boot/addons/allinone.img
541 kernel (hd0,%(install_partition)s)/boot/addons/memdisk
542 initrd (hd0,%(install_partition)s)/boot/addons/balder10.imz
545 kernel (hd0,%(install_partition)s)/boot/addons/bsd4grml/ldbsd.com
547 """ % {'grml_flavour': grml_flavour, 'local_datestamp': local_datestamp,
548 'flavour_filename': grml_flavour.replace('-', ''), 'uid': UUID,
549 'bootoptions': bootoptions, 'install_partition': install_partition } )
552 def generate_isolinux_splash(grml_flavour):
553 """Generate bootsplash for isolinux/syslinux
555 @grml_flavour: name of grml flavour the configuration should be generated for"""
557 grml_name = grml_flavour
560 \ f17
\f\18/boot/syslinux/logo.16
562 Some information and boot options available via keys F2 - F10. http://grml.org/
564 """ % {'grml_name': grml_name} )
567 def generate_main_syslinux_config(*arg):
568 """Generate main configuration for use in syslinux.cfg
570 @*arg: just for backward compatibility"""
571 # pylint: disable-msg=W0613
572 # remove warning about unused arg
576 menu label Default boot modes:
585 menu label Additional boot entries for:
587 include additional.cfg
594 include promptname.cfg
597 Jump to old style isolinux prompt
598 featuring further information
599 regarding available boot options.
607 def generate_flavour_specific_syslinux_config(grml_flavour):
608 """Generate flavour specific configuration for use in syslinux.cfg
610 @grml_flavour: name of grml flavour the configuration should be generated for"""
614 menu begin grml %(grml_flavour)s
615 menu title %(display_name)s
617 menu label ^Back to main menu...
620 # include config for boot parameters from disk
621 include %(grml_flavour)s_grml.cfg
624 """ % {'grml_flavour': grml_flavour, 'display_name' : grml_flavour.replace('_', '-') } )
627 def install_grub(device):
628 """Install grub on specified device.
630 @mntpoint: mountpoint of device where grub should install its files to
631 @device: partition where grub should be installed to"""
634 logging.info("Would execute grub-install [--root-directory=mount_point] %s now.", device)
636 device_mountpoint = tempfile.mkdtemp(prefix="grml2usb")
637 register_tmpfile(device_mountpoint)
640 mount(device, device_mountpoint, "")
642 # If using --grub-mbr then make sure we install grub in MBR instead of PBR
644 logging.debug("Using option --grub-mbr ...")
645 if device[-1:].isdigit():
646 grub_device = re.match(r'(.*?)\d*$', device).group(1)
652 logging.info("Installing grub as bootloader")
653 for opt in ["", "--force" ]:
654 logging.debug("grub-install --recheck %s --no-floppy --root-directory=%s %s",
655 opt, device_mountpoint, grub_device)
656 proc = subprocess.Popen(["grub-install", "--recheck", opt, "--no-floppy",
657 "--root-directory=%s" % device_mountpoint, grub_device],
658 stdout=file(os.devnull, "r+"))
660 if proc.returncode == 0:
663 if proc.returncode != 0:
664 # raise Exception("error executing grub-install")
665 logging.critical("Fatal: error executing grub-install "
666 + "(please check the grml2usb FAQ or drop the --grub option)")
667 logging.critical("Note: if using grub2 consider using "
668 + "the --grub-mbr option as grub considers PBR problematic.")
671 except CriticalException, error:
672 logging.critical("Fatal: %s", error)
677 unmount(device_mountpoint, "")
678 os.rmdir(device_mountpoint)
679 unregister_tmpfile(device_mountpoint)
682 def install_syslinux(device):
683 """Install syslinux on specified device.
685 @device: partition where syslinux should be installed to"""
688 logging.info("Would install syslinux as bootloader on %s", device)
691 # syslinux -d boot/isolinux /dev/sdb1
692 logging.info("Installing syslinux as bootloader")
693 logging.debug("syslinux -d boot/syslinux %s", device)
694 proc = subprocess.Popen(["syslinux", "-d", "boot/syslinux", device])
696 if proc.returncode != 0:
697 raise CriticalException("Error executing syslinux (either try --fat16 or use grub?)")
700 def install_bootloader(device):
701 """Install bootloader on specified device.
703 @device: partition where bootloader should be installed to"""
705 # by default we use grub, so install syslinux only on request
709 except CriticalException, error:
710 logging.critical("Fatal: %s", error)
715 install_syslinux(device)
716 except CriticalException, error:
717 logging.critical("Fatal: %s", error)
722 def execute_lilo(lilo, device):
723 """execute lilo for activating the partitions in the MBR
725 @lilo: path of lilo executable
726 @device: device where lilo should be executed on"""
728 # to support -A for extended partitions:
729 logging.info("Activating partitions in MBR via lilo")
730 logging.debug("%s -S /dev/null -M %s ext", lilo, device)
731 proc = subprocess.Popen([lilo, "-S", "/dev/null", "-M", device, "ext"])
733 if proc.returncode != 0:
734 raise Exception("error executing lilo")
736 # activate partition:
737 logging.debug("%s -S /dev/null -A %s 1", lilo, device)
738 proc = subprocess.Popen([lilo, "-S", "/dev/null", "-A", device, "1"])
740 if proc.returncode != 0:
741 raise Exception("error executing lilo")
744 def install_syslinux_mbr(device):
745 """install syslinux's master boot record (MBR) on the specified device
747 @device: device where MBR of syslinux should be installed to"""
749 # make sure we have syslinux available
750 if not which("syslinux") and not options.copyonly:
751 raise Exception("syslinux not available (either install it or consider using the --grub option)")
753 # lilo's mbr is broken, use the one from syslinux instead:
754 if not os.path.isfile("/usr/lib/syslinux/mbr.bin"):
755 raise Exception("/usr/lib/syslinux/mbr.bin can not be read")
757 logging.info("Installing syslinux MBR")
758 logging.debug("cat /usr/lib/syslinux/mbr.bin > %s", device)
760 retcode = subprocess.call("cat /usr/lib/syslinux/mbr.bin > "+ device, shell=True)
762 logging.critical("Error copying MBR to device (%s)", retcode)
763 except OSError, error:
764 logging.critical("Execution failed: %s", error)
767 def install_mir_mbr(mbrtemplate, device, partition, ismirbsdmbr=True):
768 """install 'mbr' master boot record (MBR) on a device
770 Retrieve the partition table from "device", install an MBR from the
771 "mbrtemplate" file, set the "partition" (0..3) active, and install the
772 result back to "device".
774 @mbrtemplate: default MBR file
776 @device: name of a file assumed to be a hard disc (or USB stick) image, or
777 something like "/dev/sdb"
779 @partition: must be a number between 0 and 3, inclusive
781 @mbrtemplate: must be a valid MBR file of at least 440 (or 439 if
784 @ismirbsdmbr: if true then ignore the active flag, set the mirbsdmbr
785 specific flag to 0/1/2/3 and set the MBR's default value accordingly. If
786 false then leave the mirbsdmbr specific flag set to FFh, set all
787 active flags to 0 and set the active flag of the partition to 80h. Note:
788 behaviour of mirbsdmbr: if flag = 0/1/2/3 then use it, otherwise search for
791 logging.info("Installing default MBR")
793 if not os.path.isfile(mbrtemplate):
794 logging.critical("Error: %s can not be read.", mbrtemplate)
795 raise CriticalException("Error installing MBR (either try --syslinux-mbr or install missing file?)")
797 if (partition < 0) or (partition > 3):
798 raise ValueError("partition must be between 0 and 3")
805 tmpf = tempfile.NamedTemporaryFile()
807 logging.debug("executing: dd if='%s' of='%s' bs=512 count=1", device, tmpf.name)
808 proc = subprocess.Popen(["dd", "if=%s" % device, "of=%s" % tmpf.name, "bs=512", "count=1"],
809 stderr=file(os.devnull, "r+"))
811 if proc.returncode != 0:
812 raise Exception("error executing dd (first run)")
814 logging.debug("executing: dd if=%s of=%s bs=%s count=1 conv=notrunc", mbrtemplate,
815 tmpf.name, nmbrbytes)
816 proc = subprocess.Popen(["dd", "if=%s" % mbrtemplate, "of=%s" % tmpf.name, "bs=%s" % nmbrbytes,
817 "count=1", "conv=notrunc"], stderr=file(os.devnull, "r+"))
819 if proc.returncode != 0:
820 raise Exception("error executing dd (second run)")
822 mbrcode = tmpf.file.read(512)
823 if len(mbrcode) < 512:
824 raise EOFError("MBR size (%d) < 512" % len(mbrcode))
827 mbrcode = mbrcode[0:439] + chr(partition) + \
828 mbrcode[440:510] + "\x55\xAA"
830 actives = ["\x00", "\x00", "\x00", "\x00"]
831 actives[partition] = "\x80"
832 mbrcode = mbrcode[0:446] + actives[0] + \
833 mbrcode[447:462] + actives[1] + \
834 mbrcode[463:478] + actives[2] + \
835 mbrcode[479:494] + actives[3] + \
836 mbrcode[495:510] + "\x55\xAA"
840 tmpf.file.write(mbrcode)
843 logging.debug("executing: dd if='%s' of='%s' bs=512 count=1 conv=notrunc", tmpf.name, device)
844 proc = subprocess.Popen(["dd", "if=%s" % tmpf.name, "of=%s" % device, "bs=512", "count=1",
845 "conv=notrunc"], stderr=file(os.devnull, "r+"))
847 if proc.returncode != 0:
848 raise Exception("error executing dd (third run)")
852 def handle_syslinux_mbr(device):
853 """Install syslinux master boot record on given device
855 @device: device where MBR should be installed to"""
857 if not is_writeable(device):
858 raise IOError("device not writeable for user")
860 # try to use system's lilo
864 # otherwise fall back to our static version
865 from platform import architecture
866 if architecture()[0] == '64bit':
867 lilo = GRML2USB_BASE + '/lilo/lilo.static.amd64'
869 lilo = GRML2USB_BASE + '/lilo/lilo.static.i386'
870 # finally prefer a specified lilo executable
872 lilo = options.lilobin
875 raise Exception("lilo executable can not be execute")
878 logging.info("Would install MBR running lilo and using syslinux.")
881 execute_lilo(lilo, device)
882 install_syslinux_mbr(device)
885 def is_writeable(device):
886 """Check if the device is writeable for the current user
888 @device: partition where bootloader should be installed to"""
892 #raise Exception("no device for checking write permissions")
894 if not os.path.exists(device):
897 return os.access(device, os.W_OK) and os.access(device, os.R_OK)
900 def mount(source, target, mount_options):
901 """Mount specified source on given target
903 @source: name of device/ISO that should be mounted
904 @target: directory where the ISO should be mounted to
905 @options: mount specific options"""
907 # note: options.dryrun does not work here, as we have to
908 # locate files and identify the grml flavour
910 for x in file('/proc/mounts').readlines():
911 if x.startswith(source):
912 raise CriticalException("Error executing mount: %s already mounted - " % source
913 + "please unmount before invoking grml2usb")
915 if os.path.isdir(source):
916 logging.debug("Source %s is not a device, therefore not mounting.", source)
919 logging.debug("mount %s %s %s", mount_options, source, target)
920 proc = subprocess.Popen(["mount"] + list(mount_options) + [source, target])
922 if proc.returncode != 0:
923 raise CriticalException("Error executing mount (no filesystem on the partition?)")
925 logging.debug("register_mountpoint(%s)", target)
926 register_mountpoint(target)
929 def unmount(target, unmount_options):
930 """Unmount specified target
932 @target: target where something is mounted on and which should be unmounted
933 @options: options for umount command"""
935 # make sure we unmount only already mounted targets
936 target_unmount = False
937 mounts = open('/proc/mounts').readlines()
938 mountstring = re.compile(".*%s.*" % re.escape(os.path.realpath(target)))
940 if re.match(mountstring, line):
941 target_unmount = True
943 if not target_unmount:
944 logging.debug("%s not mounted anymore", target)
946 logging.debug("umount %s %s", list(unmount_options), target)
947 proc = subprocess.Popen(["umount"] + list(unmount_options) + [target])
949 if proc.returncode != 0:
950 raise Exception("Error executing umount")
952 logging.debug("unregister_mountpoint(%s)", target)
953 unregister_mountpoint(target)
956 def check_for_usbdevice(device):
957 """Check whether the specified device is a removable USB device
959 @device: device name, like /dev/sda1 or /dev/sda
962 usbdevice = re.match(r'/dev/(.*?)\d*$', device).group(1)
964 usbdev = os.path.realpath('/sys/class/block/' + usbdevice + '/removable')
965 if not os.path.isfile(usbdev):
966 # Ubuntu with kernel 2.6.24 for example:
967 usbdev = os.path.realpath('/sys/block/' + usbdevice + '/removable')
969 if os.path.isfile(usbdev):
970 is_usb = open(usbdev).readline()
977 def check_for_fat(partition):
978 """Check whether specified partition is a valid VFAT/FAT16 filesystem
980 @partition: device name of partition"""
982 if not os.access(partition, os.R_OK):
983 raise CriticalException("Failed to read device %s"
984 " (wrong UID/permissions or device/directory not present?)" % partition)
987 udev_info = subprocess.Popen(["/sbin/blkid", "-s", "TYPE", "-o", "value", partition],
988 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
989 filesystem = udev_info.communicate()[0].rstrip()
991 if filesystem != "vfat":
992 raise CriticalException(
993 "Partition %s does not contain a FAT16 filesystem. "
994 "(Use --fat16 or run mkfs.vfat %s)" % (partition, partition))
997 raise CriticalException("Sorry, /sbin/blkid not available (install e2fsprogs?)")
1000 def mkdir(directory):
1001 """Simple wrapper around os.makedirs to get shell mkdir -p behaviour"""
1003 # just silently pass as it's just fine it the directory exists
1004 if not os.path.isdir(directory):
1006 os.makedirs(directory)
1007 # pylint: disable-msg=W0704
1012 def exec_rsync(source, target):
1013 """Simple wrapper around rsync to install files
1015 @source: source file/directory
1016 @target: target file/directory"""
1017 logging.debug("Source: %s / Target: %s", source, target)
1018 proc = subprocess.Popen(["rsync", "-rlptDH", "--inplace", source, target])
1020 if proc.returncode == 12:
1021 logging.critical("Fatal: No space left on device")
1025 if proc.returncode != 0:
1026 logging.critical("Fatal: could not install %s", source)
1031 def write_uuid(target_file):
1032 """Generates an returns uuid and write it to the specified file
1034 @target_file: filename to write the uuid to
1037 fileh = open(target_file, 'w')
1038 uid = str(uuid.uuid4())
1044 def get_uuid(target):
1045 """Get the uuid of the specified target. Will generate an uuid if none exist.
1047 @target: directory/mountpoint containing the grml layout
1050 conf_target = target + "/conf/"
1051 uuid_file_name = conf_target + "/bootid.txt"
1052 if os.path.isdir(conf_target):
1053 if os.path.isfile(uuid_file_name):
1054 uuid_file = open(uuid_file_name, 'r')
1055 uid = uuid_file.readline().strip()
1059 return write_uuid(uuid_file_name)
1061 execute(mkdir, conf_target)
1062 return write_uuid(uuid_file_name)
1065 def copy_system_files(grml_flavour, iso_mount, target):
1066 """copy grml's main files (like squashfs, kernel and initrd) to a given target
1068 @grml_flavour: name of grml flavour the configuration should be generated for
1069 @iso_mount: path where a grml ISO is mounted on
1070 @target: path where grml's main files should be copied to"""
1072 squashfs = search_file(grml_flavour + '.squashfs', iso_mount)
1073 if squashfs is None:
1074 logging.critical("Fatal: squashfs file not found")
1075 raise CriticalException("error locating squashfs file")
1077 squashfs_target = target + '/live/' + grml_flavour + '/'
1078 execute(mkdir, squashfs_target)
1079 exec_rsync(squashfs, squashfs_target + grml_flavour + '.squashfs')
1081 for prefix in grml_flavour + "/", "":
1082 filesystem_module = search_file(prefix + 'filesystem.module', iso_mount)
1083 if filesystem_module:
1085 if filesystem_module is None:
1086 logging.critical("Fatal: filesystem.module not found")
1087 raise CriticalException("error locating filesystem.module file")
1089 exec_rsync(filesystem_module, squashfs_target + 'filesystem.module')
1092 release_path = 'boot/release/' + grml_flavour.replace('-', '')
1093 release_target = target + "/" + release_path
1094 execute(mkdir, release_target)
1097 if os.path.isdir(iso_mount + '/boot/release'):
1098 prefix = release_path + '/'
1100 kernel = search_file(prefix + 'linux26', iso_mount)
1102 logging.critical("Fatal kernel not found")
1103 raise CriticalException("error locating kernel file")
1105 exec_rsync(kernel, release_target + '/linux26')
1107 initrd = search_file(prefix + 'initrd.gz', iso_mount)
1109 logging.critical("Fatal: initrd not found")
1110 raise CriticalException("error locating initrd file")
1112 exec_rsync(initrd, release_target + '/initrd.gz')
1115 def update_grml_versions(iso_mount, target):
1116 """Update the grml version file on a cd
1117 Returns true if version was updated successfully,
1118 False if grml-version does not exist yet on the mountpoint
1120 @iso_mount: string of the iso mount point
1121 @target: path of the target mount point
1123 grml_target = target + '/grml/'
1124 target_grml_version_file = search_file('grml-version', grml_target)
1125 if target_grml_version_file:
1126 iso_grml_version_file = search_file('grml-version', iso_mount)
1127 if not iso_grml_version_file:
1128 logging.warn("Warning: %s could not be found - can not install it", iso_grml_version_file)
1132 iso_file = open(iso_grml_version_file, 'r')
1133 for line in iso_file:
1134 iso_versions[get_flavour(line)] = line.strip()
1136 for line in fileinput.input([target_grml_version_file], inplace=1):
1137 flavour = get_flavour(line)
1138 if flavour in iso_versions.keys():
1139 print iso_versions[flavour]
1143 logging.warn("Warning: Could not write file")
1151 def copy_grml_files(iso_mount, target):
1152 """copy some minor grml files to a given target
1154 @iso_mount: path where a grml ISO is mounted on
1155 @target: path where grml's main files should be copied to"""
1157 grml_target = target + '/grml/'
1158 execute(mkdir, grml_target)
1160 copy_files = [ 'grml-cheatcodes.txt', 'LICENSE.txt', 'md5sums', 'README.txt' ]
1161 # handle grml-version
1162 if not update_grml_versions(iso_mount, target):
1163 copy_files.append('grml-version')
1165 for myfile in copy_files:
1166 grml_file = search_file(myfile, iso_mount)
1167 if grml_file is None:
1168 logging.warn("Warning: myfile %s could not be found - can not install it", myfile)
1170 exec_rsync(grml_file, grml_target + myfile)
1172 grml_web_target = grml_target + '/web/'
1173 execute(mkdir, grml_web_target)
1175 for myfile in 'index.html', 'style.css':
1176 grml_file = search_file(myfile, iso_mount)
1177 if grml_file is None:
1178 logging.warn("Warning: myfile %s could not be found - can not install it")
1180 exec_rsync(grml_file, grml_web_target + myfile)
1182 grml_webimg_target = grml_web_target + '/images/'
1183 execute(mkdir, grml_webimg_target)
1185 for myfile in 'button.png', 'favicon.png', 'linux.jpg', 'logo.png':
1186 grml_file = search_file(myfile, iso_mount)
1187 if grml_file is None:
1188 logging.warn("Warning: myfile %s could not be found - can not install it")
1190 exec_rsync(grml_file, grml_webimg_target + myfile)
1193 def handle_addon_copy(filename, dst, iso_mount):
1194 """handle copy of optional addons
1196 @filename: filename of the addon
1197 @dst: destination directory
1198 @iso_mount: location of the iso mount
1200 file_location = search_file(filename, iso_mount)
1201 if file_location is None:
1202 logging.warn("Warning: %s not found (that's fine if you don't need it)", filename)
1204 exec_rsync(file_location, dst)
1207 def copy_addons(iso_mount, target):
1208 """copy grml's addons files (like allinoneimg, bsd4grml,..) to a given target
1210 @iso_mount: path where a grml ISO is mounted on
1211 @target: path where grml's main files should be copied to"""
1213 addons = target + '/boot/addons/'
1214 execute(mkdir, addons)
1216 # grub all-in-one image
1217 handle_addon_copy('allinone.img', addons, iso_mount)
1220 handle_addon_copy('bsd4grml', addons, iso_mount)
1222 handle_addon_copy('balder10.imz', addons, iso_mount)
1224 # install hdt and pci.ids only when using syslinux (grub doesn't support it)
1225 if options.syslinux:
1226 # hdt (hardware detection tool) image
1227 hdtimg = search_file('hdt.c32', iso_mount)
1229 exec_rsync(hdtimg, addons + '/hdt.c32')
1232 picids = search_file('pci.ids', iso_mount)
1234 exec_rsync(picids, addons + '/pci.ids')
1237 handle_addon_copy('memdisk', addons, iso_mount)
1240 handle_addon_copy('memtest', addons, iso_mount)
1243 handle_addon_copy('gpxe.lkrn', addons, iso_mount)
1246 def glob_and_copy(filepattern, dst):
1247 """Glob on specified filepattern and copy the result to dst
1249 @filepattern: globbing pattern
1250 @dst: target directory
1252 for name in glob.glob(filepattern):
1253 copy_if_exist(name, dst)
1255 def search_and_copy(filename, search_path, dst):
1256 """Search for the specified filename at searchpath and copy it to dst
1258 @filename: filename to look for
1259 @search_path: base search file
1260 @dst: destionation to copy the file to
1262 file_location = search_file(filename, search_path)
1263 copy_if_exist(file_location, dst)
1265 def copy_if_exist(filename, dst):
1266 """Copy filename to dst if filename is set.
1268 @filename: a filename
1271 if filename and (os.path.isfile(filename) or os.path.isdir(filename)):
1272 exec_rsync(filename, dst)
1274 def copy_bootloader_files(iso_mount, target, grml_flavour):
1275 """Copy grml's bootloader files to a given target
1277 @iso_mount: path where a grml ISO is mounted on
1278 @target: path where grml's main files should be copied to
1279 @grml_flavour: name of the current processed grml_flavour
1282 syslinux_target = target + '/boot/syslinux/'
1283 execute(mkdir, syslinux_target)
1285 grub_target = target + '/boot/grub/'
1286 execute(mkdir, grub_target)
1289 logo = search_file('logo.16', iso_mount)
1290 exec_rsync(logo, syslinux_target + 'logo.16')
1293 for ffile in ['f%d' % number for number in range(1, 11) ]:
1294 search_and_copy(ffile, iso_mount, syslinux_target + ffile)
1296 loopback_cfg = search_file("loopback.cfg", iso_mount)
1298 directory = os.path.dirname(loopback_cfg)
1299 directory = directory.replace(iso_mount, "")
1300 mkdir(os.path.join(target, directory))
1301 exec_rsync(loopback_cfg, target + os.path.sep + directory)
1303 # avoid the "file is read only, overwrite anyway (y/n) ?" question
1304 # of mtools by syslinux ("mmove -D o -D O s:/ldlinux.sys $target_file")
1305 if os.path.isfile(syslinux_target + 'ldlinux.sys'):
1306 os.unlink(syslinux_target + 'ldlinux.sys')
1308 (source_dir, name) = get_defaults_file(iso_mount, grml_flavour, "default.cfg")
1309 (source_dir, defaults_file) = get_defaults_file(iso_mount, grml_flavour, "grml.cfg")
1312 logging.critical("Fatal: file default.cfg could not be found.")
1313 logging.critical("Note: this grml2usb version requires an ISO generated by grml-live >=0.9.24 ...")
1314 logging.critical(" ... either use grml releases >=2009.10 or switch to an older grml2usb version.")
1315 logging.critical(" Please visit http://grml.org/grml2usb/#grml2usb-compat for further information.")
1318 for expr in name, 'distri.cfg', \
1319 defaults_file, 'grml.png', 'hd.cfg', 'isolinux.cfg', 'isolinux.bin', \
1320 'isoprompt.cfg', 'options.cfg', \
1321 'prompt.cfg', 'vesamenu.cfg', 'grml.png', '*.c32':
1322 glob_and_copy(iso_mount + source_dir + expr, syslinux_target)
1324 for filename in glob.glob1(syslinux_target, "*.c32"):
1325 copy_if_exist(os.path.join(SYSLINUX_LIBS, filename), syslinux_target)
1328 # copy the addons_*.cfg file to the new syslinux directory
1329 glob_and_copy(iso_mount + source_dir + 'addon*.cfg', syslinux_target)
1331 search_and_copy('hidden.cfg', iso_mount + source_dir, syslinux_target + "new_" + 'hidden.cfg')
1334 grub_target = target + '/boot/grub/'
1335 execute(mkdir, grub_target)
1337 if not os.path.isfile(GRML2USB_BASE + "/grub/splash.xpm.gz"):
1338 logging.critical("Error: %s/grub/splash.xpm.gz can not be read.", GRML2USB_BASE)
1339 logging.critical("Please make sure you've installed the grml2usb (Debian) package!")
1342 exec_rsync(GRML2USB_BASE + '/grub/splash.xpm.gz', grub_target + 'splash.xpm.gz')
1344 # grml splash in grub
1345 copy_if_exist(GRML2USB_BASE + "/grub/grml.png", grub_target + 'grml.png')
1347 # font file for graphical bootsplash in grub
1348 copy_if_exist('/usr/share/grub/ascii.pf2', grub_target + 'ascii.pf2')
1350 # always copy grub content as it might be useful
1352 glob_and_copy(iso_mount + '/boot/grub/*.mod', grub_target)
1353 glob_and_copy(iso_mount + '/boot/grub/*.img', grub_target)
1354 glob_and_copy(iso_mount + '/boot/grub/stage*', grub_target)
1356 def install_iso_files(grml_flavour, iso_mount, device, target):
1357 """Copy files from ISO to given target
1359 @grml_flavour: name of grml flavour the configuration should be generated for
1360 @iso_mount: path where a grml ISO is mounted on
1361 @device: device/partition where bootloader should be installed to
1362 @target: path where grml's main files should be copied to"""
1365 GRML_DEFAULT = GRML_DEFAULT or grml_flavour
1368 elif not options.bootloaderonly:
1369 logging.info("Copying files. This might take a while....")
1371 copy_system_files(grml_flavour, iso_mount, target)
1372 copy_grml_files(iso_mount, target)
1373 except CriticalException, error:
1374 logging.critical("Execution failed: %s", error)
1377 if not options.skipaddons:
1378 if not search_file('addons', iso_mount):
1379 logging.info("Could not find addons, therefore not installing.")
1381 copy_addons(iso_mount, target)
1383 if not options.copyonly:
1384 copy_bootloader_files(iso_mount, target, grml_flavour)
1386 if not options.dryrun:
1387 handle_bootloader_config(grml_flavour, device, target)
1389 # make sure we sync filesystems before returning
1390 proc = subprocess.Popen(["sync"])
1394 def get_flavour(flavour_str):
1395 """Returns the flavour of a grml version string
1397 return re.match(r'[\w-]*', flavour_str).group()
1399 def identify_grml_flavour(mountpath):
1400 """Get name of grml flavour
1402 @mountpath: path where the grml ISO is mounted to
1403 @return: name of grml-flavour"""
1405 version_file = search_file('grml-version', mountpath)
1407 if version_file == "":
1408 logging.critical("Error: could not find grml-version file.")
1414 tmpfile = open(version_file, 'r')
1415 for line in tmpfile.readlines():
1416 flavours.append(get_flavour(line))
1417 except TypeError, e:
1419 except Exception, e:
1420 logging.critical("Unexpected error: %s", e)
1429 def modify_grub_config(filename):
1430 """Adjust bootoptions for a grub file
1432 @filename: filename to modify
1434 if options.removeoption:
1436 for regex in options.removeoption:
1437 regexe.append(re.compile(r'%s' % regex))
1439 option_re = re.compile(r'(.*/boot/release/.*linux26.*)')
1441 for line in fileinput.input(filename, inplace=1):
1442 if regexe and option_re.search(line):
1443 for regex in regexe:
1444 line = regex.sub(' ', line)
1446 sys.stdout.write(line)
1450 def handle_grub1_config(grml_flavour, install_partition, grub_target, bootopt):
1451 """Main handler for generating grub1 configuration
1453 @grml_flavour: name of grml flavour the configuration should be generated for
1454 @install_partition: partition number for use in (hd0,X)
1455 @grub_target: path of grub's configuration files
1456 @bootoptions: additional bootoptions that should be used by default"""
1459 grub1_cfg = grub_target + 'menu.lst'
1460 logging.debug("Creating grub1 configuration file (menu.lst)")
1462 # install main configuration only *once*, no matter how many ISOs we have:
1463 if os.path.isfile(grub1_cfg):
1464 string = open(grub1_cfg).readline()
1465 main_identifier = re.compile(".*main config generated at: %s.*" % re.escape(str(DATESTAMP)))
1466 if not re.match(main_identifier, string):
1467 grub1_config_file = open(grub1_cfg, 'w')
1468 grub1_config_file.write(generate_main_grub1_config(grml_flavour, install_partition, bootopt))
1469 grub1_config_file.close()
1471 grub1_config_file = open(grub1_cfg, 'w')
1472 grub1_config_file.write(generate_main_grub1_config(grml_flavour, install_partition, bootopt))
1473 grub1_config_file.close()
1475 grub_flavour_config = True
1476 if os.path.isfile(grub1_cfg):
1477 string = open(grub1_cfg).readlines()
1478 flavour = re.compile("grml2usb for %s: %s" % (re.escape(grml_flavour), re.escape(str(DATESTAMP))))
1480 if flavour.match(line):
1481 grub_flavour_config = False
1483 if grub_flavour_config:
1484 grub1_config_file = open(grub1_cfg, 'a')
1485 grub1_config_file.write(generate_flavour_specific_grub1_config(grml_flavour, install_partition, bootopt))
1486 grub1_config_file.close()
1488 modify_grub_config(grub1_cfg)
1490 # make sure grub.conf isn't a symlink but a plain file instead,
1491 # otherwise it will break on FAT16 filesystems
1492 # this works around grub-install of (at least) Fedora 10
1493 if os.path.isfile(grub1_cfg):
1494 grubconf = grub_target + 'grub.conf'
1495 if not os.path.islink(grubconf):
1497 shutil.copyfile(grub1_cfg, grub_target + 'grub.conf')
1499 def handle_grub2_config(grml_flavour, grub_target, bootopt):
1500 """Main handler for generating grub2 configuration
1502 @grml_flavour: name of grml flavour the configuration should be generated for
1503 @grub_target: path of grub's configuration files
1504 @bootoptions: additional bootoptions that should be used by default"""
1507 grub2_cfg = grub_target + 'grub.cfg'
1508 logging.debug("Creating grub2 configuration file (grub.cfg)")
1512 # install main configuration only *once*, no matter how many ISOs we have:
1513 grub_flavour_is_default = False
1514 if os.path.isfile(grub2_cfg):
1515 string = open(grub2_cfg).readline()
1516 main_identifier = re.compile(".*main config generated at: %s.*" % re.escape(str(DATESTAMP)))
1517 if not re.match(main_identifier, string):
1518 grub2_config_file = open(grub2_cfg, 'w')
1519 GRML_DEFAULT = grml_flavour
1520 grub_flavour_is_default = True
1521 grub2_config_file.write(generate_main_grub2_config(grml_flavour, bootopt))
1522 grub2_config_file.close()
1524 grub2_config_file = open(grub2_cfg, 'w')
1525 GRML_DEFAULT = grml_flavour
1526 grub_flavour_is_default = True
1527 grub2_config_file.write(generate_main_grub2_config(grml_flavour, bootopt))
1528 grub2_config_file.close()
1530 # install flavour specific configuration only *once* as well
1531 grub_flavour_config = True
1532 if os.path.isfile(grub2_cfg):
1533 string = open(grub2_cfg).readlines()
1534 flavour = re.compile("grml2usb for %s: %s" % (re.escape(grml_flavour), re.escape(str(DATESTAMP))))
1536 if flavour.match(line):
1537 grub_flavour_config = False
1539 if grub_flavour_config:
1540 grub2_config_file = open(grub2_cfg, 'a')
1541 # display only if the grml flavour isn't the default
1542 if not grub_flavour_is_default:
1543 GRML_FLAVOURS.add(grml_flavour)
1544 grub2_config_file.write(generate_flavour_specific_grub2_config(grml_flavour, bootopt))
1545 grub2_config_file.close()
1547 modify_grub_config(grub2_cfg)
1550 def get_bootoptions(grml_flavour):
1551 """Returns bootoptions for specific flavour
1553 @grml_flavour: name of the grml_flavour
1555 # do NOT write "None" in kernel cmdline
1556 if options.bootoptions is None:
1559 bootopt = options.bootoptions
1560 bootopt = bootopt.replace("%flavour", grml_flavour)
1564 def handle_grub_config(grml_flavour, device, target):
1565 """Main handler for generating grub (v1 and v2) configuration
1567 @grml_flavour: name of grml flavour the configuration should be generated for
1568 @device: device/partition where grub should be installed to
1569 @target: path of grub's configuration files"""
1571 logging.debug("Generating grub configuration")
1573 grub_target = target + '/boot/grub/'
1575 if os.path.isdir(device):
1576 install_grub1_partition = None
1578 if device[-1:].isdigit():
1579 install_grub1_partition = int(device[-1:]) - 1
1581 raise CriticalException("error validating partition schema (raw device?)")
1584 bootopt = get_bootoptions(grml_flavour)
1587 handle_grub1_config(grml_flavour, install_grub1_partition, grub_target, bootopt)
1589 handle_grub2_config(grml_flavour, grub_target, bootopt)
1592 def initial_syslinux_config(target):
1593 """Generates intial syslinux configuration
1595 @target path of syslinux's configuration files"""
1597 target = target + "/"
1598 filename = target + "grmlmain.cfg"
1599 if os.path.isfile(target + "grmlmain.cfg"):
1601 data = open(filename, "w")
1602 data.write(generate_main_syslinux_config())
1605 filename = target + "hiddens.cfg"
1606 data = open(filename, "w")
1607 data.write("include hidden.cfg\n")
1610 def add_entry_if_not_present(filename, entry):
1611 """Write entry into filename if entry is not already in the file
1613 @filanme: name of the file
1614 @entry: data to write to the file
1616 data = open(filename, "a+")
1625 def get_flavour_filename(flavour):
1626 """Generate a iso9960 save filename out of the specified flavour
1628 @flavour: grml flavour
1630 return flavour.replace('-', '_')
1632 def adjust_syslinux_bootoptions(src, flavour):
1633 """Adjust existing bootoptions of specified syslinux config to
1634 grml2usb specific ones, e.g. change the location of the kernel...
1636 @src: config file to alter
1637 @flavour: grml flavour
1640 append_re = re.compile("^(\s*append.*/boot/release.*)$", re.I)
1641 boot_re = re.compile("/boot/([a-zA-Z0-9_]+/)+([a-zA-Z0-9._]+)")
1642 # flavour_re = re.compile("(label.*)(grml\w+)")
1643 default_re = re.compile("(default.cfg)")
1644 bootid_re = re.compile("bootid=[\w_-]+")
1645 live_media_path_re = re.compile("live-media-path=[\w_/-]+")
1647 bootopt = get_bootoptions(flavour)
1651 if options.removeoption:
1652 option_re = re.compile(r'/boot/release/.*/initrd.gz')
1654 for regex in options.removeoption:
1655 regexe.append(re.compile(r'%s' % regex))
1657 for line in fileinput.input(src, inplace=1):
1658 line = boot_re.sub(r'/boot/release/%s/\2 ' % flavour.replace('-', ''), line)
1659 # line = flavour_re.sub(r'\1 %s-\2' % flavour, line)
1660 line = default_re.sub(r'%s-\1' % flavour, line)
1661 line = bootid_re.sub('', line)
1662 line = live_media_path_re.sub('', line)
1663 line = append_re.sub(r'\1 live-media-path=/live/%s/ ' % flavour, line)
1664 line = append_re.sub(r'\1 boot=live %s ' % bootopt, line)
1665 line = append_re.sub(r'\1 %s=%s ' % ("bootid", UUID), line)
1666 if option_re and option_re.search(line):
1667 for regex in regexe:
1668 line = regex.sub(' ', line)
1669 sys.stdout.write(line)
1672 def adjust_labels(src, replacement):
1673 """Adjust the specified labels in the syslinux config file src with
1674 specified replacement
1676 label_re = re.compile("^(\s*label\s*) ([a-zA-Z0-9_-]+)", re.I)
1677 for line in fileinput.input(src, inplace=1):
1678 line = label_re.sub(replacement, line)
1679 sys.stdout.write(line)
1683 def add_syslinux_entry(filename, grml_flavour):
1684 """Add includes for a specific grml_flavour to the specified filename
1686 @filename: syslinux config file
1687 @grml_flavour: grml flavour to add
1690 entry_filename = "option_%s.cfg" % grml_flavour
1691 entry = "include %s\n" % entry_filename
1693 add_entry_if_not_present(filename, entry)
1694 path = os.path.dirname(filename)
1696 data = open(path + "/" + entry_filename, "w")
1697 data.write(generate_flavour_specific_syslinux_config(grml_flavour))
1700 def modify_filenames(grml_flavour, target, filenames):
1701 """Replace the standarf filenames with the new ones
1703 @grml_flavour: grml-flavour strin
1704 @target: directory where the files are located
1705 @filenames: list of filenames to alter
1707 grml_filename = grml_flavour.replace('-', '_')
1708 for filename in filenames:
1709 old_filename = "%s/%s" % (target, filename)
1710 new_filename = "%s/%s_%s" % (target, grml_filename, filename)
1711 os.rename(old_filename, new_filename)
1714 def remove_default_entry(filename):
1715 """Remove the default entry from specified syslinux file
1717 @filename: syslinux config file
1719 default_re = re.compile("^(\s*menu\s*default\s*)$", re.I)
1720 for line in fileinput.input(filename, inplace=1):
1721 if default_re.match(line):
1723 sys.stdout.write(line)
1727 def handle_syslinux_config(grml_flavour, target):
1728 """Main handler for generating syslinux configuration
1730 @grml_flavour: name of grml flavour the configuration should be generated for
1731 @target: path of syslinux's configuration files"""
1733 logging.debug("Generating syslinux configuration")
1734 syslinux_target = target + '/boot/syslinux/'
1735 # should be present via copy_bootloader_files(), but make sure it exits:
1736 execute(mkdir, syslinux_target)
1737 syslinux_cfg = syslinux_target + 'syslinux.cfg'
1740 # install main configuration only *once*, no matter how many ISOs we have:
1741 syslinux_config_file = open(syslinux_cfg, 'w')
1742 syslinux_config_file.write("TIMEOUT 300\n")
1743 syslinux_config_file.write("include vesamenu.cfg\n")
1744 syslinux_config_file.close()
1746 prompt_name = open(syslinux_target + 'promptname.cfg', 'w')
1747 prompt_name.write('menu label S^yslinux prompt\n')
1750 initial_syslinux_config(syslinux_target)
1751 flavour_filename = grml_flavour.replace('-', '_')
1753 if search_file('default.cfg', syslinux_target):
1754 modify_filenames(grml_flavour, syslinux_target, ['grml.cfg', 'default.cfg'])
1756 filename = search_file("new_hidden.cfg", syslinux_target)
1759 # process hidden file
1760 if not search_file("hidden.cfg", syslinux_target):
1761 new_hidden = syslinux_target + "hidden.cfg"
1762 os.rename(filename, new_hidden)
1763 adjust_syslinux_bootoptions(new_hidden, grml_flavour)
1765 new_hidden_file = "%s/%s_hidden.cfg" % (syslinux_target, flavour_filename)
1766 os.rename(filename, new_hidden_file)
1767 adjust_labels(new_hidden_file, r'\1 %s-\2' % grml_flavour)
1768 adjust_syslinux_bootoptions(new_hidden_file, grml_flavour)
1769 entry = 'include %s_hidden.cfg\n' % flavour_filename
1770 add_entry_if_not_present("%s/hiddens.cfg" % syslinux_target, entry)
1774 new_default = "%s_default.cfg" % (flavour_filename)
1775 entry = 'include %s\n' % new_default
1776 defaults_file = '%s/defaults.cfg' % syslinux_target
1777 new_default_with_path = "%s/%s" % (syslinux_target, new_default)
1778 new_grml_cfg = "%s/%s_grml.cfg" % ( syslinux_target, flavour_filename)
1780 if os.path.isfile(defaults_file):
1782 # remove default menu entry in menu
1783 remove_default_entry(new_default_with_path)
1785 # adjust all labels for additional isos
1786 adjust_labels(new_default_with_path, r'\1 %s' % grml_flavour)
1787 adjust_labels(new_grml_cfg, r'\1 %s-\2' % grml_flavour)
1789 # always adjust bootoptions
1790 adjust_syslinux_bootoptions(new_default_with_path, grml_flavour)
1791 adjust_syslinux_bootoptions(new_grml_cfg, grml_flavour)
1793 add_entry_if_not_present("%s/defaults.cfg" % syslinux_target, entry)
1795 add_syslinux_entry("%s/additional.cfg" % syslinux_target, flavour_filename)
1798 def handle_bootloader_config(grml_flavour, device, target):
1799 """Main handler for generating bootloader's configuration
1801 @grml_flavour: name of grml flavour the configuration should be generated for
1802 @device: device/partition where bootloader should be installed to
1803 @target: path of bootloader's configuration files"""
1806 UUID = get_uuid(target)
1807 if options.skipsyslinuxconfig:
1808 logging.info("Skipping generation of syslinux configuration as requested.")
1811 handle_syslinux_config(grml_flavour, target)
1812 except CriticalException, error:
1813 logging.critical("Fatal: %s", error)
1816 if options.skipgrubconfig:
1817 logging.info("Skipping generation of grub configuration as requested.")
1820 handle_grub_config(grml_flavour, device, target)
1821 except CriticalException, error:
1822 logging.critical("Fatal: %s", error)
1827 def install(image, device):
1828 """Install a grml image to the specified device
1830 @image: directory or is file
1831 @device: partition or directory to install the device
1833 iso_mountpoint = image
1834 remove_image_mountpoint = False
1835 if os.path.isdir(image):
1836 logging.info("Using %s as install base", image)
1838 logging.info("Using ISO %s", image)
1839 iso_mountpoint = tempfile.mkdtemp(prefix="grml2usb")
1840 register_tmpfile(iso_mountpoint)
1841 remove_image_mountpoint = True
1843 mount(image, iso_mountpoint, ["-o", "loop", "-t", "iso9660"])
1844 except CriticalException, error:
1845 logging.critical("Fatal: %s", error)
1849 install_grml(iso_mountpoint, device)
1851 if remove_image_mountpoint:
1853 remove_mountpoint(iso_mountpoint)
1854 except CriticalException, error:
1855 logging.critical("Fatal: %s", error)
1860 def install_grml(mountpoint, device):
1861 """Main logic for copying files of the currently running grml system.
1863 @mountpoin: directory where currently running live system resides (usually /live/image)
1864 @device: partition where the specified ISO should be installed to"""
1866 device_mountpoint = device
1867 if os.path.isdir(device):
1868 logging.info("Specified device is not a directory, therefore not mounting.")
1869 remove_device_mountpoint = False
1871 device_mountpoint = tempfile.mkdtemp(prefix="grml2usb")
1872 register_tmpfile(device_mountpoint)
1873 remove_device_mountpoint = True
1875 check_for_fat(device)
1876 mount(device, device_mountpoint, ['-o', 'utf8,iocharset=iso8859-1'])
1877 except CriticalException, error:
1879 mount(device, device_mountpoint, "")
1880 except CriticalException, error:
1881 logging.critical("Fatal: %s", error)
1884 grml_flavours = identify_grml_flavour(mountpoint)
1885 for flavour in set(grml_flavours):
1886 logging.info("Identified grml flavour \"%s\".", flavour)
1887 install_iso_files(flavour, mountpoint, device, device_mountpoint)
1888 GRML_FLAVOURS.add(flavour)
1890 if remove_device_mountpoint:
1891 remove_mountpoint(device_mountpoint)
1893 def remove_mountpoint(mountpoint):
1894 """remove a registred mountpoint
1898 unmount(mountpoint, "")
1899 if os.path.isdir(mountpoint):
1900 os.rmdir(mountpoint)
1901 unregister_tmpfile(mountpoint)
1902 except CriticalException, error:
1903 logging.critical("Fatal: %s", error)
1906 def handle_mbr(device):
1907 """Main handler for installing master boot record (MBR)
1909 @device: device where the MBR should be installed to"""
1912 logging.info("Would install MBR")
1915 if device[-1:].isdigit():
1916 mbr_device = re.match(r'(.*?)\d*$', device).group(1)
1917 partition_number = int(device[-1:]) - 1
1918 skip_install_mir_mbr = False
1920 # if we get e.g. /dev/loop1 as device we don't want to put the MBR
1921 # into /dev/loop of course, therefore use /dev/loop1 as mbr_device
1922 if mbr_device == "/dev/loop":
1924 logging.info("Detected loop device - using %s as MBR device therefore", mbr_device)
1925 skip_install_mir_mbr = True
1928 if options.syslinuxmbr:
1929 handle_syslinux_mbr(mbr_device)
1930 elif not skip_install_mir_mbr:
1932 install_mir_mbr(GRML2USB_BASE + '/mbr/mbrmgr', mbr_device, partition_number, True)
1934 install_mir_mbr(GRML2USB_BASE + '/mbr/mbrldr', mbr_device, partition_number, False)
1935 except IOError, error:
1936 logging.critical("Execution failed: %s", error)
1938 except Exception, error:
1939 logging.critical("Execution failed: %s", error)
1943 def handle_vfat(device):
1944 """Check for FAT specific settings and options
1946 @device: device that should checked / formated"""
1948 # make sure we have mkfs.vfat available
1950 if not which("mkfs.vfat") and not options.copyonly and not options.dryrun:
1951 logging.critical('Sorry, mkfs.vfat not available. Exiting.')
1952 logging.critical('Please make sure to install dosfstools.')
1956 print "Forcing mkfs.fat16 on %s as requested via option --force." % device
1958 # make sure the user is aware of what he is doing
1959 f = raw_input("Are you sure you want to format the specified partition with fat16? y/N ")
1960 if f == "y" or f == "Y":
1961 logging.info("Note: you can skip this question using the option --force")
1966 except CriticalException, error:
1967 logging.critical("Execution failed: %s", error)
1970 # check for vfat filesystem
1971 if device is not None and not os.path.isdir(device) and options.syslinux:
1973 check_for_fat(device)
1974 except CriticalException, error:
1975 logging.critical("Execution failed: %s", error)
1978 if not os.path.isdir(device) and not check_for_usbdevice(device) and not options.force:
1979 print "Warning: the specified device %s does not look like a removable usb device." % device
1980 f = raw_input("Do you really want to continue? y/N ")
1981 if f == "y" or f == "Y":
1987 def handle_compat_warning(device):
1988 """Backwards compatible checks
1990 @device: device that should be checked"""
1992 # make sure we can replace old grml2usb script and warn user when using old way of life:
1993 if device.startswith("/mnt/external") or device.startswith("/mnt/usb") and not options.force:
1994 print "Warning: the semantics of grml2usb has changed."
1995 print "Instead of using grml2usb /path/to/iso %s you might" % device
1996 print "want to use grml2usb /path/to/iso /dev/... instead."
1997 print "Please check out the grml2usb manpage for details."
1998 f = raw_input("Do you really want to continue? y/N ")
1999 if f == "y" or f == "Y":
2005 def handle_logging():
2006 """Log handling and configuration"""
2008 if options.verbose and options.quiet:
2009 parser.error("please use either verbose (--verbose) or quiet (--quiet) option")
2012 FORMAT = "Debug: %(asctime)-15s %(message)s"
2013 logging.basicConfig(level=logging.DEBUG, format=FORMAT)
2015 FORMAT = "Critical: %(message)s"
2016 logging.basicConfig(level=logging.CRITICAL, format=FORMAT)
2018 FORMAT = "%(message)s"
2019 logging.basicConfig(level=logging.INFO, format=FORMAT)
2022 def handle_bootloader(device):
2023 """wrapper for installing bootloader
2025 @device: device where bootloader should be installed to"""
2027 # Install bootloader only if not using the --copy-only option
2028 if options.copyonly:
2029 logging.info("Not installing bootloader and its files as requested via option copyonly.")
2030 elif os.path.isdir(device):
2031 logging.info("Not installing bootloader as %s is a directory.", device)
2033 install_bootloader(device)
2036 def check_options(opts):
2037 """Check compability of provided user opts
2039 @opts option dict from OptionParser
2041 if opts.grubmbr and not opts.grub:
2042 logging.critical("Error: --grub-mbr requires --grub option.")
2046 def check_programs():
2047 """check if all needed programs are installed"""
2049 if not which("grub-install"):
2050 logging.critical("Fatal: grub-install not available (please install the "
2051 + "grub package or drop the --grub option)")
2054 if options.syslinux:
2055 if not which("syslinux"):
2056 logging.critical("Fatal: syslinux not available (please install the "
2057 + "syslinux package or use the --grub option)")
2060 if not which("rsync"):
2061 logging.critical("Fatal: rsync not available, can not continue - sorry.")
2065 """Main function [make pylint happy :)]"""
2068 print os.path.basename(sys.argv[0]) + " " + PROG_VERSION
2072 parser.error("invalid usage")
2077 # make sure we have the appropriate permissions
2080 check_options(options)
2082 logging.info("Executing grml2usb version %s", PROG_VERSION)
2085 logging.info("Running in simulation mode as requested via option dry-run.")
2089 # specified arguments
2090 device = args[len(args) - 1]
2091 isos = args[0:len(args) - 1]
2093 if not os.path.isdir(device):
2094 if device[-1:].isdigit():
2095 if int(device[-1:]) > 4 or device[-2:].isdigit():
2096 logging.critical("Fatal: installation on partition number >4 not supported. (BIOS won't support it.)")
2098 elif os.path.exists(device):
2099 logging.critical("Fatal: installation on raw device not supported. (BIOS won't support it.)")
2103 # provide upgrade path
2104 handle_compat_warning(device)
2106 # check for vfat partition
2109 # main operation (like installing files)
2111 install(iso, device)
2114 if not options.skipmbr and not os.path.isdir(device):
2117 handle_bootloader(device)
2119 logging.info("Note: grml flavour %s was installed as the default booting system.", GRML_DEFAULT)
2121 for flavour in GRML_FLAVOURS:
2122 logging.info("Note: you can boot flavour %s using '%s' on the commandline.", flavour, flavour)
2124 # finally be politely :)
2125 logging.info("Finished execution of grml2usb (%s). Have fun with your grml system.", PROG_VERSION)
2128 if __name__ == "__main__":
2131 except KeyboardInterrupt:
2132 logging.info("Received KeyboardInterrupt")
2135 ## END OF FILE #################################################################
2136 # vim:foldmethod=indent expandtab ai ft=python tw=120 fileencoding=utf-8