def write_grub_config(target, grubcfg, grub_conf, new_params): replace_default = config.value_as_boolean( grubcfg.get('replace_linux_default', True)) if replace_default: replace_grub_cmdline_linux_default(target, new_params) probe_os = config.value_as_boolean( grubcfg.get('probe_additional_os', False)) if not probe_os: probe_content = [ ('# Curtin disable grub os prober that might find other ' 'OS installs.'), 'GRUB_DISABLE_OS_PROBER="true"', '' ] util.write_file(target_path(target, grub_conf), "\n".join(probe_content), omode='a+') # if terminal is present in config, but unset, then don't grub_terminal = grubcfg.get('terminal', 'console') if not isinstance(grub_terminal, str): raise ValueError("Unexpected value %s for 'terminal'. " "Value must be a string" % grub_terminal) if not grub_terminal.lower() == "unmodified": terminal_content = [ '# Curtin configured GRUB_TERMINAL value', 'GRUB_TERMINAL="%s"' % grub_terminal ] util.write_file(target_path(target, grub_conf), "\n".join(terminal_content), omode='a+')
def install_grub(devices, target, uefi=None, grubcfg=None): """Install grub to devices inside target chroot. :param: devices: List of block device paths to install grub upon. :param: target: A string specifying the path to the chroot mountpoint. :param: uefi: A boolean set to True if system is UEFI bootable otherwise False. :param: grubcfg: An config dict with grub config options. """ if not devices: raise ValueError("Invalid parameter 'devices': %s" % devices) if not target: raise ValueError("Invalid parameter 'target': %s" % target) LOG.debug("installing grub to target=%s devices=%s [replace_defaults=%s]", target, devices, grubcfg.get('replace_default')) update_nvram = config.value_as_boolean(grubcfg.get('update_nvram', True)) distroinfo = distro.get_distroinfo(target=target) target_arch = distro.get_architecture(target=target) rhel_ver = (distro.rpm_get_dist_id(target) if distroinfo.family == distro.DISTROS.redhat else None) check_target_arch_machine(target, arch=target_arch, uefi=uefi) grub_name, grub_target = get_grub_package_name(target_arch, uefi, rhel_ver) grub_conf = get_grub_config_file(target, distroinfo.family) new_params = get_carryover_params(distroinfo) prepare_grub_dir(target, grub_conf) write_grub_config(target, grubcfg, grub_conf, new_params) grub_cmd = get_grub_install_command(uefi, distroinfo, target) if uefi: install_cmds, post_cmds = gen_uefi_install_commands( grub_name, grub_target, grub_cmd, update_nvram, distroinfo, devices, target) else: install_cmds, post_cmds = gen_install_commands(grub_name, grub_cmd, distroinfo, devices, rhel_ver) env = os.environ.copy() env['DEBIAN_FRONTEND'] = 'noninteractive' LOG.debug('Grub install cmds:\n%s', str(install_cmds + post_cmds)) with util.ChrootableTarget(target) as in_chroot: for cmd in install_cmds + post_cmds: in_chroot.subp(cmd, env=env, capture=True)
def system_upgrade(cfg, target): """run system-upgrade (apt-get dist-upgrade) or other in target. config: system_upgrade: enabled: False """ mycfg = {'system_upgrade': {'enabled': False}} config.merge_config(mycfg, cfg) mycfg = mycfg.get('system_upgrade') if not isinstance(mycfg, dict): LOG.debug("system_upgrade disabled by config. entry not a dict.") return if not config.value_as_boolean(mycfg.get('enabled', True)): LOG.debug("system_upgrade disabled by config.") return util.system_upgrade(target=target)
def handle_apt(cfg, target=None): """ handle_apt process the config for apt_config. This can be called from curthooks if a global apt config was provided or via the "apt" standalone command. """ release = distro.lsb_release(target=target)['codename'] arch = distro.get_architecture(target) mirrors = find_apt_mirror_info(cfg, arch) LOG.debug("Apt Mirror info: %s", mirrors) apply_debconf_selections(cfg, target) if not config.value_as_boolean(cfg.get('preserve_sources_list', True)): generate_sources_list(cfg, release, mirrors, target) apply_preserve_sources_list(target) rename_apt_lists(mirrors, target) try: apply_apt_proxy_config(cfg, target + APT_PROXY_FN, target + APT_CONFIG_FN) except (IOError, OSError): LOG.exception("Failed to apply proxy or apt config info:") # Process 'apt_source -> sources {dict}' if 'sources' in cfg: params = mirrors params['RELEASE'] = release params['MIRROR'] = mirrors["MIRROR"] matcher = None matchcfg = cfg.get('add_apt_repo_match', ADD_APT_REPO_MATCH) if matchcfg: matcher = re.compile(matchcfg).search add_apt_sources(cfg['sources'], target, template_params=params, aa_repo_match=matcher)
def translate_old_apt_features(cfg): """translate the few old apt related features into the new config format""" predef_apt_cfg = cfg.get("apt") if predef_apt_cfg is None: cfg['apt'] = {} predef_apt_cfg = cfg.get("apt") if cfg.get('apt_proxy') is not None: if predef_apt_cfg.get('proxy') is not None: msg = ("Error in apt_proxy configuration: " "old and new format of apt features " "are mutually exclusive") LOG.error(msg) raise ValueError(msg) cfg['apt']['proxy'] = cfg.get('apt_proxy') LOG.debug("Transferred %s into new format: %s", cfg.get('apt_proxy'), cfg.get('apte')) del cfg['apt_proxy'] if cfg.get('apt_mirrors') is not None: if predef_apt_cfg.get('mirrors') is not None: msg = ("Error in apt_mirror configuration: " "old and new format of apt features " "are mutually exclusive") LOG.error(msg) raise ValueError(msg) old = cfg.get('apt_mirrors') cfg['apt']['primary'] = [{ "arches": ["default"], "uri": old.get('ubuntu_archive') }] cfg['apt']['security'] = [{ "arches": ["default"], "uri": old.get('ubuntu_security') }] LOG.debug("Transferred %s into new format: %s", cfg.get('apt_mirror'), cfg.get('apt')) del cfg['apt_mirrors'] # to work this also needs to disable the default protection psl = predef_apt_cfg.get('preserve_sources_list') if psl is not None: if config.value_as_boolean(psl) is True: msg = ("Error in apt_mirror configuration: " "apt_mirrors and preserve_sources_list: True " "are mutually exclusive") LOG.error(msg) raise ValueError(msg) cfg['apt']['preserve_sources_list'] = False if cfg.get('debconf_selections') is not None: if predef_apt_cfg.get('debconf_selections') is not None: msg = ("Error in debconf_selections configuration: " "old and new format of apt features " "are mutually exclusive") LOG.error(msg) raise ValueError(msg) selsets = cfg.get('debconf_selections') cfg['apt']['debconf_selections'] = selsets LOG.info("Transferred %s into new format: %s", cfg.get('debconf_selections'), cfg.get('apt')) del cfg['debconf_selections'] return cfg