import datetime, logging, os, re, subprocess, sys, tempfile, time
# global variables
import datetime, logging, os, re, subprocess, sys, tempfile, time
# global variables
MOUNTED = set() # register mountpoints
TMPFILES = set() # register tmpfiles
DATESTAMP = time.mktime(datetime.datetime.now().timetuple()) # unique identifier for syslinux.cfg
MOUNTED = set() # register mountpoints
TMPFILES = set() # register tmpfiles
DATESTAMP = time.mktime(datetime.datetime.now().timetuple()) # unique identifier for syslinux.cfg
Make sure you have at least one grml ISO or a running grml system (/live/image),\n\
grub or syslinux and root access.\n\
\n\
Make sure you have at least one grml ISO or a running grml system (/live/image),\n\
grub or syslinux and root access.\n\
\n\
# help="install specified kernel instead of the default [TODO - not implemented yet]")
parser.add_option("--lilo-binary", dest="lilobin", action="store", type="string",
help="lilo executable to be used for installing MBR")
# help="install specified kernel instead of the default [TODO - not implemented yet]")
parser.add_option("--lilo-binary", dest="lilobin", action="store", type="string",
help="lilo executable to be used for installing MBR")
-parser.add_option("--mbr-manager", dest="mbrmgr", action="store_true",
- help="enable interactive boot manager menu in MBR")
+parser.add_option("--mbr-menu", dest="mbrmenu", action="store_true",
+ help="enable interactive boot menu in MBR")
parser.add_option("--quiet", dest="quiet", action="store_true",
help="do not output anything but just errors on console")
parser.add_option("--skip-addons", dest="skipaddons", action="store_true",
parser.add_option("--quiet", dest="quiet", action="store_true",
help="do not output anything but just errors on console")
parser.add_option("--skip-addons", dest="skipaddons", action="store_true",
menuentry "%(grml_flavour)s (default)" {
set root=(hd0,%(install_partition)s)
menuentry "%(grml_flavour)s (default)" {
set root=(hd0,%(install_partition)s)
menuentry "%(grml_flavour)s-failsafe" {
set root=(hd0,%(install_partition)s)
linux /boot/release/%(grml_flavour)s/linux26
menuentry "%(grml_flavour)s-failsafe" {
set root=(hd0,%(install_partition)s)
linux /boot/release/%(grml_flavour)s/linux26
- initrd /boot/release/%(grml_flavour)s/initrd.gz apm=power-off boot=live nomce quiet live-media-path=/live/%(grml_flavour)s/ vga=normal lang=us boot=live noautoconfig atapicd noacpi acpi=off nomodules nofirewire noudev nousb nohotplug noapm nopcmcia maxcpus=1 noscsi noagp nodma ide=nodma noswap nofstab nosound nogpm nosyslog nodhcp nocpu nodisc nomodem xmodule=vesa noraid nolvm %(bootoptions)s
+ initrd /boot/release/%(grml_flavour)s/initrd.gz apm=power-off boot=live nomce quiet live-media-path=/live/%(grml_flavour)s/ vga=normal boot=live 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 %(bootoptions)s
## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
title %(grml_flavour)s-failsafe
## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
title %(grml_flavour)s-failsafe
-kernel (hd0,%(install_partition)s)/boot/release/%(grml_flavour)s/linux26 apm=power-off boot=live nomce quiet live-media-path=/live/%(grml_flavour)s/ vga=normal lang=us boot=live noautoconfig atapicd noacpi acpi=off nomodules nofirewire noudev nousb nohotplug noapm nopcmcia maxcpus=1 noscsi noagp nodma ide=nodma noswap nofstab nosound nogpm nosyslog nodhcp nocpu nodisc nomodem xmodule=vesa noraid nolvm %(bootoptions)s
+kernel (hd0,%(install_partition)s)/boot/release/%(grml_flavour)s/linux26 apm=power-off boot=live nomce quiet live-media-path=/live/%(grml_flavour)s/ vga=normal boot=live 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 %(bootoptions)s
initrd (hd0,%(install_partition)s)/boot/release/%(grml_flavour)s/initrd.gz
## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
initrd (hd0,%(install_partition)s)/boot/release/%(grml_flavour)s/initrd.gz
## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
initrd (hd0,%(install_partition)s)/boot/release/%(grml_flavour)s/initrd.gz
title Memory test (memtest86+)
initrd (hd0,%(install_partition)s)/boot/release/%(grml_flavour)s/initrd.gz
title Memory test (memtest86+)
# flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
LABEL %(grml_flavour)s-failsafe
KERNEL /boot/release/%(grml_flavour)s/linux26
# flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
LABEL %(grml_flavour)s-failsafe
KERNEL /boot/release/%(grml_flavour)s/linux26
-APPEND initrd=/boot/release/%(grml_flavour)s/initrd.gz apm=power-off boot=live nomce quiet live-media-path=/live/%(grml_flavour)s/ vga=normal lang=us boot=live noautoconfig atapicd noacpi acpi=off nomodules nofirewire noudev nousb nohotplug noapm nopcmcia maxcpus=1 noscsi noagp nodma ide=nodma noswap nofstab nosound nogpm nosyslog nodhcp nocpu nodisc nomodem xmodule=vesa noraid nolvm %(bootoptions)s
+APPEND initrd=/boot/release/%(grml_flavour)s/initrd.gz apm=power-off boot=live nomce quiet live-media-path=/live/%(grml_flavour)s/ vga=normal boot=live 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 %(bootoptions)s
# flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
LABEL %(grml_flavour)s-forensic
# flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
LABEL %(grml_flavour)s-forensic
def install_mir_mbr(mbrtemplate, device, partition, ismirbsdmbr=True):
"""install 'mbr' master boot record (MBR) on a device
def install_mir_mbr(mbrtemplate, device, partition, ismirbsdmbr=True):
"""install 'mbr' master boot record (MBR) on a device
- Retrieve the partition table from "device", install an MBR from
- the "mbrtemplate" file, set the "partition" (0..3) active, and
- install the result back to "device".
+ Retrieve the partition table from "device", install an MBR from the
+ "mbrtemplate" file, set the "partition" (0..3) active, and install the
+ result back to "device".
- @device: name of a file assumed to be a hard disc (or USB stick) image,
- or something like "/dev/sdb"
+ @device: name of a file assumed to be a hard disc (or USB stick) image, or
+ something like "/dev/sdb"
+
- @ismirbsdmbr: if set the partitions' active flags are not changed.
- Instead, the MBR's default value is set accordingly."""
+ @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
+ active flags to 0 and set the active flag of the partition to 80h. Note:
+ behaviour of mirbsdmbr: if flag = 0/1/2/3 then use it, otherwise search for
+ the active flag."""
else:
logging.debug("cp %s %s" % (allinoneimg, addons + '/allinone.img'))
proc = subprocess.Popen(["cp", allinoneimg, addons + 'allinone.img'])
else:
logging.debug("cp %s %s" % (allinoneimg, addons + '/allinone.img'))
proc = subprocess.Popen(["cp", allinoneimg, addons + 'allinone.img'])
else:
logging.debug("cp -a %s %s" % (bsdimg, addons + '/'))
proc = subprocess.Popen(["cp", "-a", bsdimg, addons + '/'])
else:
logging.debug("cp -a %s %s" % (bsdimg, addons + '/'))
proc = subprocess.Popen(["cp", "-a", bsdimg, addons + '/'])
else:
logging.debug("cp %s %s" % (balderimg, addons + '/balder10.imz'))
proc = subprocess.Popen(["cp", balderimg, addons + 'balder10.imz'])
else:
logging.debug("cp %s %s" % (balderimg, addons + '/balder10.imz'))
proc = subprocess.Popen(["cp", balderimg, addons + 'balder10.imz'])
else:
logging.debug("cp %s %s" % (memdiskimg, addons + '/memdisk'))
proc = subprocess.Popen(["cp", memdiskimg, addons + 'memdisk'])
else:
logging.debug("cp %s %s" % (memdiskimg, addons + '/memdisk'))
proc = subprocess.Popen(["cp", memdiskimg, addons + 'memdisk'])
else:
logging.debug("cp %s %s" % (memtestimg, addons + '/memtest'))
proc = subprocess.Popen(["cp", memtestimg, addons + 'memtest'])
else:
logging.debug("cp %s %s" % (memtestimg, addons + '/memtest'))
proc = subprocess.Popen(["cp", memtestimg, addons + 'memtest'])
if grub_flavour_config:
grub1_config_file = open(grub1_cfg, 'a')
grub1_config_file.write(generate_flavour_specific_grub1_config(grml_flavour, install_partition, bootopt))
if grub_flavour_config:
grub1_config_file = open(grub1_cfg, 'a')
grub1_config_file.write(generate_flavour_specific_grub1_config(grml_flavour, install_partition, bootopt))
def handle_grub2_config(grml_flavour, install_partition, grub_target, bootopt):
def handle_grub2_config(grml_flavour, install_partition, grub_target, bootopt):
logging.debug("Creating grub2 configuration file (grub.lst)")
# install main configuration only *once*, no matter how many ISOs we have:
logging.debug("Creating grub2 configuration file (grub.lst)")
# install main configuration only *once*, no matter how many ISOs we have:
if os.path.isfile(grub2_cfg):
string = open(grub2_cfg).readline()
main_identifier = re.compile(".*main config generated at: %s.*" % re.escape(str(DATESTAMP)))
if os.path.isfile(grub2_cfg):
string = open(grub2_cfg).readline()
main_identifier = re.compile(".*main config generated at: %s.*" % re.escape(str(DATESTAMP)))
else:
grub2_config_file = open(grub2_cfg, 'w')
logging.info("Note: grml flavour %s is being installed as the default booting system." % grml_flavour)
else:
grub2_config_file = open(grub2_cfg, 'w')
logging.info("Note: grml flavour %s is being installed as the default booting system." % grml_flavour)
grub2_config_file.write(generate_main_grub2_config(grml_flavour, install_partition, bootopt))
grub2_config_file.close()
grub2_config_file.write(generate_main_grub2_config(grml_flavour, install_partition, bootopt))
grub2_config_file.close()
grub_flavour_config = True
if os.path.isfile(grub2_cfg):
string = open(grub2_cfg).readlines()
grub_flavour_config = True
if os.path.isfile(grub2_cfg):
string = open(grub2_cfg).readlines()
if not grub_flavour_is_default:
logging.info("Note: you can boot flavour %s using '%s' on the commandline." % (grml_flavour, grml_flavour))
grub2_config_file.write(generate_flavour_specific_grub2_config(grml_flavour, install_partition, bootopt))
if not grub_flavour_is_default:
logging.info("Note: you can boot flavour %s using '%s' on the commandline." % (grml_flavour, grml_flavour))
grub2_config_file.write(generate_flavour_specific_grub2_config(grml_flavour, install_partition, bootopt))
syslinux_cfg = syslinux_target + 'syslinux.cfg'
# install main configuration only *once*, no matter how many ISOs we have:
syslinux_cfg = syslinux_target + 'syslinux.cfg'
# install main configuration only *once*, no matter how many ISOs we have:
if os.path.isfile(syslinux_cfg):
string = open(syslinux_cfg).readline()
main_identifier = re.compile(".*main config generated at: %s.*" % re.escape(str(DATESTAMP)))
if not re.match(main_identifier, string):
syslinux_config_file = open(syslinux_cfg, 'w')
logging.info("Note: grml flavour %s is being installed as the default booting system." % grml_flavour)
if os.path.isfile(syslinux_cfg):
string = open(syslinux_cfg).readline()
main_identifier = re.compile(".*main config generated at: %s.*" % re.escape(str(DATESTAMP)))
if not re.match(main_identifier, string):
syslinux_config_file = open(syslinux_cfg, 'w')
logging.info("Note: grml flavour %s is being installed as the default booting system." % grml_flavour)
syslinux_config_file.write(generate_main_syslinux_config(grml_flavour, bootopt))
syslinux_config_file.close()
else:
syslinux_config_file = open(syslinux_cfg, 'w')
syslinux_config_file.write(generate_main_syslinux_config(grml_flavour, bootopt))
syslinux_config_file.close()
else:
syslinux_config_file = open(syslinux_cfg, 'w')
syslinux_config_file.write(generate_main_syslinux_config(grml_flavour, bootopt))
syslinux_config_file.close()
# install flavour specific configuration only *once* as well
syslinux_config_file.write(generate_main_syslinux_config(grml_flavour, bootopt))
syslinux_config_file.close()
# install flavour specific configuration only *once* as well
syslinux_flavour_config = True
if os.path.isfile(syslinux_cfg):
string = open(syslinux_cfg).readlines()
syslinux_flavour_config = True
if os.path.isfile(syslinux_cfg):
string = open(syslinux_cfg).readlines()
if syslinux_flavour_config:
syslinux_config_file = open(syslinux_cfg, 'a')
if syslinux_flavour_config:
syslinux_config_file = open(syslinux_cfg, 'a')
logging.debug("Generating isolinux/syslinux splash %s" % syslinux_target + 'boot.msg')
isolinux_splash = open(syslinux_target + 'boot.msg', 'w')
isolinux_splash.write(generate_isolinux_splash(grml_flavour))
logging.debug("Generating isolinux/syslinux splash %s" % syslinux_target + 'boot.msg')
isolinux_splash = open(syslinux_target + 'boot.msg', 'w')
isolinux_splash.write(generate_isolinux_splash(grml_flavour))
- unmount(device_mountpoint, "")
- if os.path.isdir(device_mountpoint):
- os.rmdir(device_mountpoint)
- unregister_tmpfile(device_mountpoint)
+ try:
+ unmount(device_mountpoint, "")
+ if os.path.isdir(device_mountpoint):
+ os.rmdir(device_mountpoint)
+ unregister_tmpfile(device_mountpoint)
+ except CriticalException, error:
+ logging.critical("Fatal: %s" % error)
+ cleanup()
install_mir_mbr('/usr/share/grml2usb/mbr/mbrmgr', mbr_device, partition_number, True)
else:
install_mir_mbr('/usr/share/grml2usb/mbr/mbrmgr', mbr_device, partition_number, True)
else:
- install_mir_mbr('/usr/share/grml2usb/mbr/mbrldr', mbr_device, partition_number, True)
+ install_mir_mbr('/usr/share/grml2usb/mbr/mbrldr', mbr_device, partition_number, False)