summaryrefslogtreecommitdiffstats
path: root/build_tools/l7/larch0/cli/boot_iso.py
diff options
context:
space:
mode:
authorCecil Hugh Watson <knoppmyth@gmail.com>2010-08-28 21:23:23 (GMT)
committerCecil Hugh Watson <knoppmyth@gmail.com>2010-08-28 21:23:23 (GMT)
commitf83117d46d8fc1f6192783371a68607a192c3276 (patch)
tree21bf30aeb943fe6cb23eb9c62a0ba899de2af0d7 /build_tools/l7/larch0/cli/boot_iso.py
parent69a0137390be9816d5ec5dc9e81d48817a817758 (diff)
downloadlinhes_dev-f83117d46d8fc1f6192783371a68607a192c3276.zip
Larch 7
Diffstat (limited to 'build_tools/l7/larch0/cli/boot_iso.py')
-rwxr-xr-xbuild_tools/l7/larch0/cli/boot_iso.py154
1 files changed, 154 insertions, 0 deletions
diff --git a/build_tools/l7/larch0/cli/boot_iso.py b/build_tools/l7/larch0/cli/boot_iso.py
new file mode 100755
index 0000000..19c3510
--- /dev/null
+++ b/build_tools/l7/larch0/cli/boot_iso.py
@@ -0,0 +1,154 @@
+#!/usr/bin/env python
+#
+# live_part.py
+#
+# (c) Copyright 2009 - 2010 Michael Towers (larch42 at googlemail dot com)
+#
+# This file is part of the larch project.
+#
+# larch is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# larch is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with larch; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+#----------------------------------------------------------------------------
+# 2010.07.12
+
+"""This is a command line script to prepare a boot 'iso' for a USB larch
+device, to make this bootable via CD on systems which cannot boot from USB
+devices.
+Parameters are passed as options and arguments.
+"""
+
+import os
+from config import *
+from backend import *
+from media_common import *
+
+def build_bootiso(options, devicename):
+ """Create a boot iso for the specified medium.
+ 'devicename' is the name (e.g. 'sdb1', without '/dev/') of the
+ source partition.
+ """
+ # Check device
+ device = '/dev/' + devicename
+ if not os.path.exists(device):
+ errout(_("Invalid device: %s") % device)
+ options.source = device
+ medium = Medium(options)
+ ipath = medium.chrootpath
+ build = medium.build
+
+ # Need to get the label
+ label = medium.get_device_label(device)
+
+ # Write bootloader configuration file
+ bootconfig(build, options.syslinux, label, device, options.detection)
+
+ # Select bootloader
+ if options.syslinux:
+ # Get fresh isolinux.bin
+ runcmd('cp %s/boot/isolinux/isolinux.bin0 %s/boot/isolinux/isolinux.bin'
+ % (build, build))
+ parms = '-b boot/isolinux/isolinux.bin -c boot/isolinux/isolinux.boot'
+ # Select bootloader
+ else:
+ parms = '-b boot/grub/stage2_eltorito'
+
+ # Need to adjust paths to cater for chroot!
+ source0 = medium.chroot_medium_dir()
+ isopath0 = medium.iso_path()
+
+ # Actually the volume label can be 32 bytes, but 16 is compatible
+ # with ext2 (though a little longer than vfat)
+ label = check_label(options.label, 16)
+ # Build iso
+ if not chroot(ipath, ('mkisofs -R -l %s -no-emul-boot -boot-load-size 4'
+ ' -boot-info-table -input-charset=UTF-8'
+ ' -V "%s"'
+ ' -o "%s"'
+ ' "%s"') % (parms, label, isopath0, BUILD0),
+ filter=mkisofs_filter_gen()):
+
+ errout(_("iso build failed"))
+
+ medium.unmount()
+ runcmd('rm -rf %s' % build)
+
+ comment(" *** %s ***" % (_("%s was successfully created")
+ % (options.isofile)))
+
+
+
+if __name__ == '__main__':
+ start_translator()
+
+ from optparse import OptionParser, OptionGroup
+ parser = OptionParser(usage=_("usage: %prog [options] partition"
+ " (e.g. sdb1)"))
+
+ parser.add_option("-o", "--isofile", action="store", type="string",
+ default=BOOTISO, dest="isofile",
+ help=_("Specify the output file (default '%s'). It will be"
+ " generated to the current directory.") % BOOTISO)
+ parser.add_option("-D", "--setdir", action="store", type="string",
+ dest='setdir', default='',
+ help=_("Set current directory,"
+ " so that the 'iso' can be placed there"))
+ parser.add_option("-d", "--detect", action="store", type="string",
+ default="label", dest="detection",
+ help=(_("Method for boot partition detection: %s (default: label)")
+ % detection_methods))
+ parser.add_option("-b", "--syslinux", action="store_true", dest="syslinux",
+ default=False, help=_("Use the syslinux bootloader"
+ " (the default is GRUB)"))
+
+ parser.add_option("-i", "--installation-dir", action="store", type="string",
+ default="", dest="idir",
+ help=_("Path to larchified directory (default %s)") % INSTALLATION)
+ parser.add_option("-s", "--slave", action="store_true", dest="slave",
+ default=False, help=_("Run as a slave from a controlling program"
+ " (e.g. from a gui)"))
+ parser.add_option("-q", "--quiet", action="store_true", dest="quiet",
+ default=False, help=_("Suppress output messages, except errors"
+ " (no effect if -s specified)"))
+
+ parser.add_option("-f", "--force", action="store_true", dest="force",
+ default=False, help=_("Don't ask for confirmation"))
+
+ parser.add_option("-l", "--label", action="store", type="string",
+ default=ISOLABEL, dest="label",
+ help=_("Volume label for boot iso (default %s)")
+ % ISOLABEL)
+ parser.add_option("-C", "--chroot", action="store_true",
+ dest="chroot", default=False,
+ help=_("Use chroot for build"))
+
+
+ (options, args) = parser.parse_args()
+ if not args:
+ print _("You must specify the source partition\n")
+ parser.print_help()
+ sys.exit(1)
+
+ if os.getuid() != 0:
+ print _("This application must be run as root")
+ sys.exit(1)
+
+ init('live_part', options)
+
+ # To avoid error messages
+ options.profile = None
+ options.nochroot = None
+ options.testmedium = False
+
+ build_bootiso(options, devicename=args[0])