def _probe_stage2_for_cdrom(device_tree): # TODO: This is temporary method which should be moved closer to the inst.repo logic log.debug("Testing if inst.stage2 is a CDROM device") stage2_string = kernel_arguments.get("stage2") if not stage2_string: return None try: source = SourceFactory.parse_repo_cmdline_string(stage2_string) except PayloadSourceTypeUnrecognized: log.warning("Unknown stage2 method: %s", stage2_string) return None # We have HDD here because DVD ISO has inst.stage2=hd:LABEL=.... # TODO: Let's return back support of inst.cdrom=<device> which should work based on the # documentation and use that as inst.stage2 parameter for Pungi if not source.is_harddrive: log.debug("Stage2 can't be used as source %s", stage2_string) return None # We can ignore source.path here because DVD ISOs are not using that. stage2_device = device_tree.ResolveDevice(source.partition) log.debug("Found possible stage2 default installation source %s", stage2_device) return stage2_device
def _set_console(self): """ Set console options based on boot arguments. """ console = kernel_arguments.get("console") if not console: return console = os.path.basename(console) self.console, _x, self.console_options = console.partition(",") log.debug("Console is set to %s with options '%s'", self.console, self.console_options)
def execute(self, storage, ksdata, users, payload): # the KdumpSpoke should run only if requested if kernel_arguments.get("kdump_addon", default=True) in [ "0", "off", False ] or not self.enabled: return action = "enable" util.execWithRedirect("systemctl", [action, "kdump.service"], root=conf.target.system_root)
def _preserve_some_boot_args(self): """Preserve some of the boot args.""" for opt in conf.bootloader.preserved_arguments: if opt not in kernel_arguments: continue arg = kernel_arguments.get(opt) new_arg = opt if arg: new_arg += "=%s" % arg self.boot_args.add(new_arg)
def recreate_initrds(sysroot, kernel_versions): """Recreate the initrds by calling new-kernel-pkg or dracut. This needs to be done after all configuration files have been written, since dracut depends on some of them. :param sysroot: a path to the root of the installed system :param kernel_versions: a list of kernel versions """ if os.path.exists(sysroot + "/usr/sbin/new-kernel-pkg"): use_dracut = False else: log.debug("new-kernel-pkg does not exist, using dracut instead") use_dracut = True for kernel in kernel_versions: log.info("Recreating initrd for %s", kernel) if conf.target.is_image: # Dracut runs in the host-only mode by default, so we need to # turn it off by passing the -N option, because the mode is not # sensible for disk image installations. Using /dev/disk/by-uuid/ # is necessary due to disk image naming. execWithRedirect("dracut", [ "-N", "--persistent-policy", "by-uuid", "-f", "/boot/initramfs-%s.img" % kernel, kernel ], root=sysroot) else: if use_dracut: execWithRedirect("depmod", ["-a", kernel], root=sysroot) execWithRedirect( "dracut", ["-f", "/boot/initramfs-%s.img" % kernel, kernel], root=sysroot) else: execWithRedirect( "new-kernel-pkg", ["--mkinitrd", "--dracut", "--depmod", "--update", kernel], root=sysroot) # if the installation is running in fips mode then make sure # fips is also correctly enabled in the installed system if kernel_arguments.get("fips") == "1": # We use the --no-bootcfg option as we don't want fips-mode-setup # to modify the bootloader configuration. Anaconda already does # everything needed & it would require grubby to be available on # the system. execWithRedirect("fips-mode-setup", ["--enable", "--no-bootcfg"], root=sysroot)
def write_module_blacklist(sysroot): """Create module blacklist based on the user preference. Copy modules from modprobe.blacklist=<module> on cmdline to /etc/modprobe.d/anaconda-blacklist.conf so that modules will continue to be blacklisted when the system boots. """ if "modprobe.blacklist" not in kernel_arguments: return mkdirChain(os.path.join(sysroot, "etc/modprobe.d")) with open(os.path.join(sysroot, "etc/modprobe.d/anaconda-blacklist.conf"), "w") as f: f.write("# Module blacklists written by anaconda\n") for module in kernel_arguments.get("modprobe.blacklist").split(): f.write("blacklist %s\n" % module)
def recreate_initrds(self): """Recreate the initrds by calling new-kernel-pkg or dracut This needs to be done after all configuration files have been written, since dracut depends on some of them. :returns: None """ if os.path.exists(conf.target.system_root + "/usr/sbin/new-kernel-pkg"): use_dracut = False else: log.warning( "new-kernel-pkg does not exist - grubby wasn't installed? " " using dracut instead.") use_dracut = True for kernel in self.kernel_version_list: log.info("recreating initrd for %s", kernel) if not conf.target.is_image: if use_dracut: util.execInSysroot("depmod", ["-a", kernel]) util.execInSysroot( "dracut", ["-f", "/boot/initramfs-%s.img" % kernel, kernel]) else: util.execInSysroot("new-kernel-pkg", [ "--mkinitrd", "--dracut", "--depmod", "--update", kernel ]) # if the installation is running in fips mode then make sure # fips is also correctly enabled in the installed system if kernel_arguments.get("fips") == "1": # We use the --no-bootcfg option as we don't want fips-mode-setup to # modify the bootloader configuration. # Anaconda already does everything needed & it would require grubby to # be available on the system. util.execInSysroot("fips-mode-setup", ["--enable", "--no-bootcfg"]) else: # hostonly is not sensible for disk image installations # using /dev/disk/by-uuid/ is necessary due to disk image naming util.execInSysroot("dracut", [ "-N", "--persistent-policy", "by-uuid", "-f", "/boot/initramfs-%s.img" % kernel, kernel ])
def setup(self, storage, ksdata, payload): # the kdump addon should run only if requested if kernel_arguments.get("kdump_addon", default=True) in ["0", "off", False]: return # Update the package list. if self.enabled: ksdata.packages.packageList.append("kexec-tools") # Update the bootloader arguments. bootloader_proxy = STORAGE.get_proxy(BOOTLOADER) # Clear any existing crashkernel bootloader arguments extra_args = bootloader_proxy.ExtraArguments new_args = [ arg for arg in extra_args if not arg.startswith('crashkernel=') ] # Copy our reserved amount to the bootloader arguments if self.enabled: # Ensure that the amount is "auto" or an amount in MB if self.reserveMB != "auto" and self.reserveMB[-1] != 'M': self.reserveMB += 'M' new_args.append('crashkernel=%s' % self.reserveMB) if self.enablefadump and os.path.exists(FADUMP_CAPABLE_FILE): new_args.append('fadump=on') bootloader_proxy.SetExtraArguments(new_args) # If the local storage object is not available, skip. # FIXME: This is a temporary workaround. if not storage: return # Do the same thing with the storage.bootloader.boot_args set if storage.bootloader.boot_args: crashargs = [arg for arg in storage.bootloader.boot_args \ if arg.startswith('crashkernel=')] storage.bootloader.boot_args -= set(crashargs) if self.enabled: storage.bootloader.boot_args.add('crashkernel=%s' % self.reserveMB) if self.enablefadump and os.path.exists(FADUMP_CAPABLE_FILE): storage.bootloader.boot_args.add('fadump=on')
def _set_console(self): """ Set console options based on boot arguments. """ console = kernel_arguments.get("console", "") console = os.path.basename(console) self.console, _x, self.console_options = console.partition(",")
def _set_storage_boot_args(self, storage): """Set the storage boot args.""" fcoe_proxy = STORAGE.get_proxy(FCOE) iscsi_proxy = STORAGE.get_proxy(ISCSI) # FIPS boot_device = storage.mountpoints.get("/boot") if kernel_arguments.get("fips") == "1" and boot_device: self.boot_args.add("boot=%s" % self.stage2_device.fstab_spec) # Storage dracut_devices = [storage.root_device] if self.stage2_device != storage.root_device: dracut_devices.append(self.stage2_device) swap_devices = storage.fsset.swap_devices dracut_devices.extend(swap_devices) # Add resume= option to enable hibernation on x86. # Choose the largest swap device for that. if blivet.arch.is_x86() and swap_devices: resume_device = max(swap_devices, key=lambda x: x.size) self.boot_args.add("resume=%s" % resume_device.fstab_spec) # Does /usr have its own device? If so, we need to tell dracut usr_device = storage.mountpoints.get("/usr") if usr_device: dracut_devices.extend([usr_device]) netdevs = [d for d in storage.devices \ if (getattr(d, "complete", True) and isinstance(d, NetworkStorageDevice))] rootdev = storage.root_device if any(rootdev.depends_on(netdev) for netdev in netdevs): dracut_devices = set(dracut_devices) # By this time this thread should be the only one running, and also # mountpoints is a property function that returns a new dict every # time, so iterating over the values is safe. for dev in storage.mountpoints.values(): if any(dev.depends_on(netdev) for netdev in netdevs): dracut_devices.add(dev) done = [] for device in dracut_devices: for dep in storage.devices: if dep in done: continue if device != dep and not device.depends_on(dep): continue if isinstance(dep, blivet.devices.FcoeDiskDevice): setup_args = fcoe_proxy.GetDracutArguments(dep.nic) elif isinstance(dep, blivet.devices.iScsiDiskDevice): # (partial) offload devices do not need setup in dracut if not dep.offload: node = _get_iscsi_node_from_device(dep) setup_args = iscsi_proxy.GetDracutArguments( Node.to_structure(node)) else: setup_args = dep.dracut_setup_args() if not setup_args: continue self.boot_args.update(setup_args) self.dracut_args.update(setup_args) done.append(dep) # network configuration arguments if isinstance(dep, NetworkStorageDevice): network_proxy = NETWORK.get_proxy() network_args = [] ibft = False nic = "" if isinstance(dep, blivet.devices.iScsiDiskDevice): if dep.iface == "default" or ":" in dep.iface: node = _get_iscsi_node_from_device(dep) if iscsi_proxy.IsNodeFromIbft( Node.to_structure(node)): ibft = True else: nic = iface_for_host_ip(dep.host_address) else: nic = iscsi_proxy.GetInterface(dep.iface) else: nic = dep.nic if nic or ibft: network_args = network_proxy.GetDracutArguments( nic, dep.host_address, "", ibft) self.boot_args.update(network_args) self.dracut_args.update(network_args) # This is needed for FCoE, bug #743784. The case: # We discover LUN on an iface which is part of multipath setup. # If the iface is disconnected after discovery anaconda doesn't # write dracut ifname argument for the disconnected iface path # (in NETWORK.GetDracutArguments). # Dracut needs the explicit ifname= because biosdevname # fails to rename the iface (because of BFS booting from it). for nic in fcoe_proxy.GetNics(): hwaddr = get_interface_hw_address(nic) if hwaddr: self.boot_args.add("ifname=%s:%s" % (nic, hwaddr.lower())) # Add rd.iscsi.firmware to trigger dracut running iscsistart # See rhbz#1099603 and rhbz#1185792 if len(glob("/sys/firmware/iscsi_boot*")) > 0: self.boot_args.add("rd.iscsi.firmware")
def should_run(cls, environment, data): # the KdumpSpoke should run only if requested return kernel_arguments.get("kdump_addon", default=True) not in ["0", "off", False]