+ # pylint: disable=no-self-use
+ def _grub_serial_console(self, rootdir):
+ cmdline = 'GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=tty1 console=ttyS0,38400n8"'
+ terminal = 'GRUB_TERMINAL="serial gfxterm"'
+ command = 'GRUB_SERIAL_COMMAND="serial --speed=38400 --unit=0 --parity=no --stop=1"'
+ grub_cfg = os.path.join(rootdir, 'etc', 'default', 'grub')
+ logging.debug("Allowing serial output in grub config %s", grub_cfg)
+ with open(grub_cfg, 'a+') as cfg:
+ cfg.write("# %s serial support\n" % os.path.basename(__file__))
+ cfg.write("%s\n" % cmdline)
+ cfg.write("%s\n" % terminal)
+ cfg.write("%s\n" % command)
+
+ def _mount_wrapper(self, rootdir):
+ self.runcmd(['mount', '/dev', '-t', 'devfs', '-obind',
+ '%s' % os.path.join(rootdir, 'dev')])
+ self.runcmd(['mount', '/proc', '-t', 'proc', '-obind',
+ '%s' % os.path.join(rootdir, 'proc')])
+ self.runcmd(['mount', '/sys', '-t', 'sysfs', '-obind',
+ '%s' % os.path.join(rootdir, 'sys')])
+
+ def _umount_wrapper(self, rootdir):
+ self.runcmd(['umount', os.path.join(rootdir, 'sys')])
+ self.runcmd(['umount', os.path.join(rootdir, 'proc')])
+ self.runcmd(['umount', os.path.join(rootdir, 'dev')])
+
+ def install_grub_uefi(self, rootdir):
+ self.message("Configuring grub-uefi")
+ target = self.efi_arch_table[self.settings['arch']]['target']
+ grub_opts = "--target=%s" % target
+ logging.debug("Running grub-install with options: %s", grub_opts)
+ self._mount_wrapper(rootdir)
+ try:
+ self.runcmd(['chroot', rootdir, 'update-grub'])
+ self.runcmd(['chroot', rootdir, 'grub-install', grub_opts])
+ except cliapp.AppException as exc:
+ logging.warning(exc)
+ self.message(
+ "Failed to configure grub-uefi for %s" %
+ self.settings['arch'])
+ self._umount_wrapper(rootdir)
+ self.configure_efi()
+ extra = str(self.efi_arch_table[self.settings['arch']]['extra'])
+ if extra:
+ target = self.efi_arch_table[extra]['target']
+ grub_opts = "--target=%s" % target
+ try:
+ self.runcmd(['chroot', rootdir, 'update-grub'])
+ self.runcmd(['chroot', rootdir, 'grub-install', grub_opts])
+ except cliapp.AppException as exc:
+ logging.warning(exc)
+ self.message(
+ "Failed to configure grub-uefi for %s" % extra)
+ self.configure_extra_efi()
+ self._umount_wrapper(rootdir)
+
+ def install_grub2(self, rootdev, rootdir):
+ self.message("Configuring grub2")
+ # rely on kpartx using consistent naming to map loop0p1 to loop0
+ grub_opts = os.path.join('/dev', os.path.basename(rootdev)[:-2])
+ if self.settings['serial-console']:
+ self._grub_serial_console(rootdir)
+ logging.debug("Running grub-install with options: %s", grub_opts)
+ self._mount_wrapper(rootdir)
+ try:
+ self.runcmd(['chroot', rootdir, 'update-grub'])
+ self.runcmd(['chroot', rootdir, 'grub-install', grub_opts])
+ except cliapp.AppException as exc:
+ logging.warning(exc)
+ self.message("Failed. Is grub2-common installed? Using extlinux.")
+ self.install_extlinux(rootdev, rootdir)
+ self._umount_wrapper(rootdir)
+