def doConfiguration(storage, payload, ksdata, instClass): from pyanaconda.kickstart import runPostScripts step_count = 6 # if a realm was discovered, # increment the counter as the # real joining step will be executed if ksdata.realm.discovered: step_count += 1 progressQ.send_init(step_count) # Now run the execute methods of ksdata that require an installed system # to be present first. with progress_report(_("Configuring installed system")): if 0: # sabayon # authconfig causes massive breakage to Gentoo's pambase file ksdata.authconfig.execute(storage, ksdata, instClass) ksdata.selinux.execute(storage, ksdata, instClass) ksdata.firstboot.execute(storage, ksdata, instClass) ksdata.services.execute(storage, ksdata, instClass) ksdata.keyboard.execute(storage, ksdata, instClass) ksdata.timezone.execute(storage, ksdata, instClass) ksdata.lang.execute(storage, ksdata, instClass) ksdata.firewall.execute(storage, ksdata, instClass) ksdata.xconfig.execute(storage, ksdata, instClass) if not flags.flags.imageInstall and not flags.flags.dirInstall: with progress_report(_("Writing network configuration")): ksdata.network.execute(storage, ksdata, instClass) # Creating users and groups requires some pre-configuration. with progress_report(_("Creating users")): createLuserConf(ROOT_PATH, algoname=getPassAlgo(ksdata.authconfig.authconfig)) u = Users() ksdata.rootpw.execute(storage, ksdata, instClass, u) ksdata.group.execute(storage, ksdata, instClass, u) ksdata.user.execute(storage, ksdata, instClass, u) with progress_report(_("Configuring addons")): ksdata.addons.execute(storage, ksdata, instClass, u) ksdata.configured_spokes.execute(storage, ksdata, instClass, u) with progress_report(_("Configuring system")): payload.configure() with progress_report(_("Generating initramfs")): payload.recreateInitrds(force=True) if ksdata.realm.discovered: with progress_report(_("Joining realm: %s") % ksdata.realm.discovered): ksdata.realm.execute(storage, ksdata, instClass) with progress_report(_("Running post-installation scripts")): runPostScripts(ksdata.scripts) # Write the kickstart file to the installed system (or, copy the input # kickstart file over if one exists). _writeKS(ksdata) progressQ.send_complete()
def mount_root(self): """Mounts selected root and runs scripts.""" # mount root fs try: mount_existing_system(self._storage.fsset, self.root.device, read_only=self.ro) log.info("System has been mounted under: %s", util.getSysroot()) except StorageError as e: log.error("Mounting system under %s failed: %s", util.getSysroot(), e) self.status = RescueModeStatus.MOUNT_FAILED return False # turn on swap if not flags.imageInstall or not self.ro: try: self._storage.turn_on_swap() except StorageError: log.error("Error enabling swap.") # turn on selinux also if flags.selinux: # we have to catch the possible exception, because we # support read-only mounting try: fd = open("%s/.autorelabel" % util.getSysroot(), "w+") fd.close() except IOError as e: log.warning("Error turning on selinux: %s", e) # set a libpath to use mounted fs libdirs = os.environ.get("LD_LIBRARY_PATH", "").split(":") mounted = ["/mnt/sysimage%s" % ldir for ldir in libdirs] util.setenv("LD_LIBRARY_PATH", ":".join(libdirs + mounted)) # do we have bash? try: if os.access("/usr/bin/bash", os.R_OK): os.symlink("/usr/bin/bash", "/bin/bash") except OSError as e: log.error("Error symlinking bash: %s", e) # make resolv.conf in chroot if not self.ro: self._storage.make_mtab() try: makeResolvConf(util.getSysroot()) except (OSError, IOError) as e: log.error("Error making resolv.conf: %s", e) # create /etc/fstab in ramdisk so it's easier to work with RO mounted fs makeFStab() # run %post if we've mounted everything if not self.ro and self._scripts: runPostScripts(self._scripts) self.status = RescueModeStatus.MOUNTED return True
def mount_root(self, root): """Mounts selected root and runs scripts.""" # mount root fs try: mount_existing_system(self._storage.fsset, root.device, read_only=self.ro) log.info("System has been mounted under: %s", util.getSysroot()) except StorageError as e: log.error("Mounting system under %s failed: %s", util.getSysroot(), e) self.status = RescueModeStatus.MOUNT_FAILED return False # turn on swap if not conf.target.is_image or not self.ro: try: self._storage.turn_on_swap() except StorageError: log.error("Error enabling swap.") # turn on selinux also if conf.security.selinux: # we have to catch the possible exception, because we # support read-only mounting try: fd = open("%s/.autorelabel" % util.getSysroot(), "w+") fd.close() except IOError as e: log.warning("Error turning on selinux: %s", e) # set a libpath to use mounted fs libdirs = os.environ.get("LD_LIBRARY_PATH", "").split(":") mounted = ["/mnt/sysimage%s" % ldir for ldir in libdirs] util.setenv("LD_LIBRARY_PATH", ":".join(libdirs + mounted)) # do we have bash? try: if os.access("/usr/bin/bash", os.R_OK): os.symlink("/usr/bin/bash", "/bin/bash") except OSError as e: log.error("Error symlinking bash: %s", e) # make resolv.conf in chroot if not self.ro: self._storage.make_mtab() try: makeResolvConf(util.getSysroot()) except(OSError, IOError) as e: log.error("Error making resolv.conf: %s", e) # create /etc/fstab in ramdisk so it's easier to work with RO mounted fs makeFStab() # run %post if we've mounted everything if not self.ro and self._scripts: runPostScripts(self._scripts) self.status = RescueModeStatus.MOUNTED return True
def doConfiguration(storage, payload, ksdata, instClass): from pyanaconda.kickstart import runPostScripts step_count = 6 # if a realm was discovered, # increment the counter as the # real joining step will be executed if ksdata.realm.discovered: step_count += 1 progressQ.send_init(step_count) # Now run the execute methods of ksdata that require an installed system # to be present first. with progress_report(_("Configuring installed system")): ksdata.authconfig.execute(storage, ksdata, instClass) ksdata.selinux.execute(storage, ksdata, instClass) ksdata.firstboot.execute(storage, ksdata, instClass) ksdata.services.execute(storage, ksdata, instClass) ksdata.keyboard.execute(storage, ksdata, instClass) ksdata.timezone.execute(storage, ksdata, instClass) ksdata.lang.execute(storage, ksdata, instClass) ksdata.firewall.execute(storage, ksdata, instClass) ksdata.xconfig.execute(storage, ksdata, instClass) ksdata.skipx.execute(storage, ksdata, instClass) if not flags.flags.imageInstall and not flags.flags.dirInstall: with progress_report(_("Writing network configuration")): ksdata.network.execute(storage, ksdata, instClass) # Creating users and groups requires some pre-configuration. with progress_report(_("Creating users")): createLuserConf(ROOT_PATH, algoname=getPassAlgo(ksdata.authconfig.authconfig)) u = Users() ksdata.rootpw.execute(storage, ksdata, instClass, u) ksdata.group.execute(storage, ksdata, instClass, u) ksdata.user.execute(storage, ksdata, instClass, u) with progress_report(_("Configuring addons")): ksdata.addons.execute(storage, ksdata, instClass, u) ksdata.configured_spokes.execute(storage, ksdata, instClass, u) with progress_report(_("Generating initramfs")): payload.recreateInitrds(force=True) if ksdata.realm.discovered: with progress_report(_("Joining realm: %s") % ksdata.realm.discovered): ksdata.realm.execute(storage, ksdata, instClass) with progress_report(_("Running post-installation scripts")): runPostScripts(ksdata.scripts) # Write the kickstart file to the installed system (or, copy the input # kickstart file over if one exists). _writeKS(ksdata) progressQ.send_complete()
def mount_root(self, root): """Mounts selected root and runs scripts.""" # mount root fs try: task_path = self._device_tree_proxy.MountExistingSystemWithTask( root.get_root_device(), self.ro ) task_proxy = STORAGE.get_proxy(task_path) sync_run_task(task_proxy) log.info("System has been mounted under: %s", conf.target.system_root) except MountFilesystemError as e: log.error("Mounting system under %s failed: %s", conf.target.system_root, e) self.status = RescueModeStatus.MOUNT_FAILED self.error = e return False # turn on selinux also if conf.security.selinux: # we have to catch the possible exception, because we # support read-only mounting try: fd = open("%s/.autorelabel" % conf.target.system_root, "w+") fd.close() except IOError as e: log.warning("Error turning on selinux: %s", e) # set a libpath to use mounted fs libdirs = os.environ.get("LD_LIBRARY_PATH", "").split(":") mounted = ["/mnt/sysimage%s" % ldir for ldir in libdirs] util.setenv("LD_LIBRARY_PATH", ":".join(libdirs + mounted)) # do we have bash? try: if os.access("/usr/bin/bash", os.R_OK): os.symlink("/usr/bin/bash", "/bin/bash") except OSError as e: log.error("Error symlinking bash: %s", e) # make resolv.conf in chroot if not self.ro: try: makeResolvConf(conf.target.system_root) except(OSError, IOError) as e: log.error("Error making resolv.conf: %s", e) # create /etc/fstab in ramdisk so it's easier to work with RO mounted fs makeFStab() # run %post if we've mounted everything if not self.ro and self._scripts: runPostScripts(self._scripts) self.status = RescueModeStatus.MOUNTED return True
def refresh(self, args=None): NormalTUISpoke.refresh(self, args) if self._root: try: mountExistingSystem(self.storage.fsset, self._root.device, readOnly=self.readOnly) if flags.automatedInstall: log.info("System has been mounted under: %s", iutil.getSysroot()) else: text = TextWidget(_("Your system has been mounted under %(mountpoint)s.\n\nIf " "you would like to make your system the root " "environment, run the command:\n\n\tchroot %(mountpoint)s\n") % {"mountpoint": iutil.getSysroot()} ) self._window.append(text) rootmounted = True # now turn on swap if not flags.imageInstall or not self.readOnly: try: self.storage.turnOnSwap() except StorageError: log.error("Error enabling swap.") # turn on selinux also if flags.selinux: # we have to catch the possible exception, because we # support read-only mounting try: fd = open("%s/.autorelabel" % iutil.getSysroot(), "w+") fd.close() except IOError: log.warning("Cannot touch %s/.autorelabel", iutil.getSysroot()) # set a libpath to use mounted fs libdirs = os.environ.get("LD_LIBRARY_PATH", "").split(":") mounted = list(map(lambda dir: "/mnt/sysimage%s" % dir, libdirs)) iutil.setenv("LD_LIBRARY_PATH", ":".join(libdirs + mounted)) # do we have bash? try: if os.access("/usr/bin/bash", os.R_OK): os.symlink("/usr/bin/bash", "/bin/bash") except OSError: pass except (ValueError, LookupError, SyntaxError, NameError): pass except Exception as e: # pylint: disable=broad-except if flags.automatedInstall: msg = _("Run %s to unmount the system when you are finished.\n") % ANACONDA_CLEANUP text = TextWidget(_("An error occurred trying to mount some or all of " "your system. Some of it may be mounted under %s\n\n") + iutil.getSysroot() + msg) self._window.append(text) return True else: if flags.automatedInstall and self.data.reboot.action in [KS_REBOOT, KS_SHUTDOWN]: log.info("No Linux partitions found.") text = TextWidget(_("You don't have any Linux partitions. Rebooting.\n")) self._window.append(text) # should probably wait a few seconds to show the message time.sleep(5) iutil.execWithRedirect("systemctl", ["--no-wall", "reboot"]) else: if not flags.imageInstall: msg = _("The system will reboot automatically when you exit" " from the shell.\n") else: msg = "" text = TextWidget(_("You don't have any Linux partitions. %s\n") % msg) self._window.append(text) return True if rootmounted and not self.readOnly: self.storage.makeMtab() try: makeResolvConf(iutil.getSysroot()) except(OSError, IOError) as e: log.error("Error making resolv.conf: %s", e) text = TextWidget(_("Your system is mounted under the %s directory.") % iutil.getSysroot()) self._window.append(text) # create /etc/fstab in ramdisk so it's easier to work with RO mounted fs makeFStab() # run %post if we've mounted everything if rootmounted and not self.readOnly and flags.automatedInstall: runPostScripts(self.data.scripts) return True
def refresh(self, args=None): NormalTUISpoke.refresh(self, args) if self._root: try: mount_existing_system(self.storage.fsset, self._root.device, read_only=self.readOnly) if flags.automatedInstall: log.info("System has been mounted under: %s", iutil.getSysroot()) else: text = TextWidget( _("Your system has been mounted under %(mountpoint)s.\n\n" "If you would like to make the root of your system the " "root of the active system, run the command:\n\n" "\tchroot %(mountpoint)s\n") % {"mountpoint": iutil.getSysroot()}) self._window.append(text) rootmounted = True # now turn on swap if not flags.imageInstall or not self.readOnly: try: self.storage.turn_on_swap() except StorageError: log.error("Error enabling swap.") # turn on selinux also if flags.selinux: # we have to catch the possible exception, because we # support read-only mounting try: fd = open("%s/.autorelabel" % iutil.getSysroot(), "w+") fd.close() except IOError: log.warning("Cannot touch %s/.autorelabel", iutil.getSysroot()) # set a libpath to use mounted fs libdirs = os.environ.get("LD_LIBRARY_PATH", "").split(":") mounted = list( map(lambda dir: "/mnt/sysimage%s" % dir, libdirs)) iutil.setenv("LD_LIBRARY_PATH", ":".join(libdirs + mounted)) # do we have bash? try: if os.access("/usr/bin/bash", os.R_OK): os.symlink("/usr/bin/bash", "/bin/bash") except OSError: pass except (ValueError, LookupError, SyntaxError, NameError): pass except (OSError, StorageError) as e: if flags.automatedInstall: msg = _( "Run %s to unmount the system when you are finished.\n" ) % ANACONDA_CLEANUP text = TextWidget( _("An error occurred trying to mount some or all of " "your system. Some of it may be mounted under %s\n\n") + iutil.getSysroot() + msg) self._window.append(text) return True else: if flags.automatedInstall and self.data.reboot.action in [ KS_REBOOT, KS_SHUTDOWN ]: log.info("No Linux partitions found.") text = TextWidget( _("You don't have any Linux partitions. Rebooting.\n")) self._window.append(text) # should probably wait a few seconds to show the message time.sleep(5) iutil.execWithRedirect("systemctl", ["--no-wall", "reboot"]) else: if not flags.imageInstall: msg = _( "The system will reboot automatically when you exit" " from the shell.\n") else: msg = "" text = TextWidget( _("You don't have any Linux partitions. %s\n") % msg) self._window.append(text) return True if rootmounted and not self.readOnly: self.storage.make_mtab() try: makeResolvConf(iutil.getSysroot()) except (OSError, IOError) as e: log.error("Error making resolv.conf: %s", e) text = TextWidget( _("Your system is mounted under the %s directory.") % iutil.getSysroot()) self._window.append(text) # create /etc/fstab in ramdisk so it's easier to work with RO mounted fs makeFStab() # run %post if we've mounted everything if rootmounted and not self.readOnly and flags.automatedInstall: runPostScripts(self.data.scripts) return True
def doConfiguration(storage, payload, ksdata, instClass): willWriteNetwork = not flags.flags.imageInstall and not flags.flags.dirInstall willRunRealmd = ksdata.realm.discovered # configure base, create users, configure addons, initramfs, post-install step_count = 5 # network, maybe if willWriteNetwork: step_count += 1 # if a realm was discovered, # increment the counter as the # real joining step will be executed if willRunRealmd: step_count += 1 progress_init(step_count) # Now run the execute methods of ksdata that require an installed system # to be present first. with progress_report(N_("Configuring installed system")): ksdata.authconfig.execute(storage, ksdata, instClass) ksdata.selinux.execute(storage, ksdata, instClass) ksdata.firstboot.execute(storage, ksdata, instClass) ksdata.services.execute(storage, ksdata, instClass) ksdata.keyboard.execute(storage, ksdata, instClass) ksdata.timezone.execute(storage, ksdata, instClass) ksdata.lang.execute(storage, ksdata, instClass) ksdata.firewall.execute(storage, ksdata, instClass) ksdata.xconfig.execute(storage, ksdata, instClass) ksdata.skipx.execute(storage, ksdata, instClass) if willWriteNetwork: with progress_report(N_("Writing network configuration")): ksdata.network.execute(storage, ksdata, instClass) # Creating users and groups requires some pre-configuration. with progress_report(N_("Creating users")): u = Users() ksdata.rootpw.execute(storage, ksdata, instClass, u) ksdata.group.execute(storage, ksdata, instClass, u) ksdata.user.execute(storage, ksdata, instClass, u) ksdata.sshkey.execute(storage, ksdata, instClass, u) with progress_report(N_("Configuring addons")): ksdata.addons.execute(storage, ksdata, instClass, u) with progress_report(N_("Generating initramfs")): payload.recreateInitrds() # Work around rhbz#1200539, grubby doesn't handle grub2 missing initrd with /boot on btrfs # So rerun writing the bootloader if this is live and /boot is on btrfs boot_on_btrfs = isinstance(storage.mountpoints.get("/boot", storage.mountpoints.get("/")), BTRFSDevice) if flags.flags.livecdInstall and boot_on_btrfs \ and (not ksdata.bootloader.disabled and ksdata.bootloader != "none"): writeBootLoader(storage, payload, instClass, ksdata) if willRunRealmd: with progress_report(N_("Joining realm: %s") % ksdata.realm.discovered): ksdata.realm.execute(storage, ksdata, instClass) with progress_report(N_("Running post-installation scripts")): runPostScripts(ksdata.scripts) # setup kexec reboot if requested if flags.flags.kexec: setup_kexec() # Write the kickstart file to the installed system (or, copy the input # kickstart file over if one exists). if flags.flags.nosave_output_ks: # don't write the kickstart file to the installed system if this has # been disabled by the nosave option log.warning("Writing of the output kickstart to installed system has been disabled" " by the copy_kickstarts option.") else: _writeKS(ksdata) progress_complete()
def doConfiguration(storage, payload, ksdata, instClass): willWriteNetwork = not flags.flags.imageInstall and not flags.flags.dirInstall willRunRealmd = ksdata.realm.discovered # configure base, create users, configure addons, initramfs, post-install step_count = 5 # network, maybe if willWriteNetwork: step_count += 1 # if a realm was discovered, # increment the counter as the # real joining step will be executed if willRunRealmd: step_count += 1 progress_init(step_count) # Now run the execute methods of ksdata that require an installed system # to be present first. with progress_report(_("Configuring installed system")): ksdata.authconfig.execute(storage, ksdata, instClass) ksdata.selinux.execute(storage, ksdata, instClass) ksdata.firstboot.execute(storage, ksdata, instClass) ksdata.services.execute(storage, ksdata, instClass) ksdata.keyboard.execute(storage, ksdata, instClass) ksdata.timezone.execute(storage, ksdata, instClass) ksdata.lang.execute(storage, ksdata, instClass) ksdata.firewall.execute(storage, ksdata, instClass) ksdata.xconfig.execute(storage, ksdata, instClass) ksdata.skipx.execute(storage, ksdata, instClass) if willWriteNetwork: with progress_report(_("Writing network configuration")): ksdata.network.execute(storage, ksdata, instClass) # Creating users and groups requires some pre-configuration. with progress_report(_("Creating users")): createLuserConf(iutil.getSysroot(), algoname=getPassAlgo(ksdata.authconfig.authconfig)) u = Users() ksdata.rootpw.execute(storage, ksdata, instClass, u) ksdata.group.execute(storage, ksdata, instClass, u) ksdata.user.execute(storage, ksdata, instClass, u) ksdata.sshkey.execute(storage, ksdata, instClass, u) with progress_report(_("Configuring addons")): ksdata.addons.execute(storage, ksdata, instClass, u) with progress_report(_("Generating initramfs")): payload.recreateInitrds() # Work around rhbz#1200539, grubby doesn't handle grub2 missing initrd with /boot on btrfs # So rerun writing the bootloader if this is live and /boot is on btrfs boot_on_btrfs = isinstance( storage.mountpoints.get("/boot", storage.mountpoints.get("/")), BTRFSDevice) if flags.flags.livecdInstall and boot_on_btrfs \ and (not ksdata.bootloader.disabled and ksdata.bootloader != "none"): writeBootLoader(storage, payload, instClass, ksdata) if willRunRealmd: with progress_report(_("Joining realm: %s") % ksdata.realm.discovered): ksdata.realm.execute(storage, ksdata, instClass) with progress_report(_("Running post-installation scripts")): runPostScripts(ksdata.scripts) # setup kexec reboot if requested if flags.flags.kexec: setup_kexec() # Write the kickstart file to the installed system (or, copy the input # kickstart file over if one exists). _writeKS(ksdata) progress_complete()
def doConfiguration(storage, payload, ksdata, instClass): from pyanaconda.kickstart import runPostScripts willWriteNetwork = not flags.flags.imageInstall and not flags.flags.dirInstall willRunRealmd = ksdata.realm.discovered # configure base, create users, configure addons, initramfs, post-install step_count = 5 # network, maybe if willWriteNetwork: step_count += 1 # if a realm was discovered, # increment the counter as the # real joining step will be executed if willRunRealmd: step_count += 1 progress_init(step_count) # Now run the execute methods of ksdata that require an installed system # to be present first. with progress_report(_("Configuring installed system")): ksdata.authconfig.execute(storage, ksdata, instClass) ksdata.selinux.execute(storage, ksdata, instClass) ksdata.firstboot.execute(storage, ksdata, instClass) ksdata.services.execute(storage, ksdata, instClass) ksdata.keyboard.execute(storage, ksdata, instClass) ksdata.timezone.execute(storage, ksdata, instClass) ksdata.lang.execute(storage, ksdata, instClass) ksdata.firewall.execute(storage, ksdata, instClass) ksdata.xconfig.execute(storage, ksdata, instClass) ksdata.skipx.execute(storage, ksdata, instClass) if willWriteNetwork: with progress_report(_("Writing network configuration")): ksdata.network.execute(storage, ksdata, instClass) # Creating users and groups requires some pre-configuration. with progress_report(_("Creating users")): createLuserConf(iutil.getSysroot(), algoname=getPassAlgo(ksdata.authconfig.authconfig)) u = Users() ksdata.rootpw.execute(storage, ksdata, instClass, u) ksdata.group.execute(storage, ksdata, instClass, u) ksdata.user.execute(storage, ksdata, instClass, u) with progress_report(_("Configuring addons")): ksdata.addons.execute(storage, ksdata, instClass, u) with progress_report(_("Generating initramfs")): payload.recreateInitrds(force=True) if willRunRealmd: with progress_report(_("Joining realm: %s") % ksdata.realm.discovered): ksdata.realm.execute(storage, ksdata, instClass) with progress_report(_("Running post-installation scripts")): runPostScripts(ksdata.scripts) # setup kexec reboot if requested if flags.flags.kexec: setup_kexec() # Write the kickstart file to the installed system (or, copy the input # kickstart file over if one exists). _writeKS(ksdata) progress_complete()
def doRescue(intf, rescue_mount, ksdata): import blivet # XXX: hook the exception handler wrapper that turns off snack first orig_hook = sys.excepthook sys.excepthook = lambda ty, val, tb: _exception_handler_wrapper( orig_hook, intf.screen, ty, val, tb) for f in [ "services", "protocols", "group", "joe", "man.config", "nsswitch.conf", "selinux", "mke2fs.conf" ]: try: os.symlink('/mnt/runtime/etc/' + f, '/etc/' + f) except OSError: pass # Early shell access with no disk access attempts if not rescue_mount: # the %post should be responsible for mounting all needed file systems # NOTE: 1st script must be bash or simple python as nothing else might be available in the rescue image if flags.automatedInstall and ksdata.scripts: runPostScripts(ksdata.scripts) else: runShell() sys.exit(0) if flags.automatedInstall: readOnly = ksdata.rescue.romount else: # prompt to see if we should try and find root filesystem and mount # everything in /etc/fstab on that root while True: rc = ButtonChoiceWindow( intf.screen, _("Rescue"), _("The rescue environment will now attempt to find your " "Linux installation and mount it under the directory " "%s. You can then make any changes required to your " "system. If you want to proceed with this step choose " "'Continue'. You can also choose to mount your file systems " "read-only instead of read-write by choosing 'Read-Only'. " "\n\n" "If for some reason this process fails you can choose 'Skip' " "and this step will be skipped and you will go directly to a " "command shell.\n\n") % (ROOT_PATH, ), [_("Continue"), _("Read-Only"), _("Skip")]) if rc == _("Skip").lower(): runShell(intf.screen) sys.exit(0) else: readOnly = rc == _("Read-Only").lower() break sto = blivet.Blivet(ksdata=ksdata) blivet.storageInitialize(sto, ksdata, []) _unlock_devices(intf, sto) roots = blivet.findExistingInstallations(sto.devicetree) if not roots: root = None elif len(roots) == 1: root = roots[0] else: height = min(len(roots), 12) if height == 12: scroll = 1 else: scroll = 0 lst = [] for root in roots: lst.append("%s" % root.name) (button, choice) = \ ListboxChoiceWindow(intf.screen, _("System to Rescue"), _("Which device holds the root partition " "of your installation?"), lst, [ _("OK"), _("Exit") ], width = 30, scroll = scroll, height = height, help = "multipleroot") if button == _("Exit").lower(): root = None else: root = roots[choice] rootmounted = False if root: try: # TODO: add a callback to warn about dirty filesystems mountExistingSystem(sto.fsset, root.device, allowDirty=True, readOnly=readOnly) if not flags.imageInstall: msg = _("The system will reboot automatically when you exit " "from the shell.") else: msg = _("Run %s to unmount the system " "when you are finished.") % ANACONDA_CLEANUP if rc == -1: if flags.automatedInstall: log.error( "System had dirty file systems which you chose not to mount" ) else: ButtonChoiceWindow( intf.screen, _("Rescue"), _("Your system had dirty file systems which you chose not " "to mount. Press return to get a shell from which " "you can fsck and mount your partitions. %s") % msg, [_("OK")], width=50) rootmounted = False else: if flags.automatedInstall: log.info("System has been mounted under: %s", ROOT_PATH) else: ButtonChoiceWindow( intf.screen, _("Rescue"), _("Your system has been mounted under %(rootPath)s.\n\n" "Press <return> to get a shell. If you would like to " "make your system the root environment, run the command:\n\n" "\tchroot %(rootPath)s\n\n%(msg)s") % { 'rootPath': ROOT_PATH, 'msg': msg }, [_("OK")]) rootmounted = True # now turn on swap if not readOnly: try: sto.turnOnSwap() except StorageError: log.error("Error enabling swap") # and selinux too if flags.selinux: # we have to catch the possible exception # because we support read-only mounting try: fd = open("%s/.autorelabel" % ROOT_PATH, "w+") fd.close() except IOError: log.warning("cannot touch /.autorelabel") # set a library path to use mounted fs libdirs = os.environ.get("LD_LIBRARY_PATH", "").split(":") mounted = map(lambda dir: "/mnt/sysimage%s" % dir, libdirs) os.environ["LD_LIBRARY_PATH"] = ":".join(libdirs + mounted) # find groff data dir gversion = None try: glst = os.listdir("/mnt/sysimage/usr/share/groff") except OSError: pass else: # find a directory which is a numeral, its where # data files are for gdir in glst: if re.match(r'\d[.\d]+\d$', gdir): gversion = gdir break if gversion is not None: gpath = "/mnt/sysimage/usr/share/groff/" + gversion os.environ["GROFF_FONT_PATH"] = gpath + '/font' os.environ[ "GROFF_TMAC_PATH"] = "%s:/mnt/sysimage/usr/share/groff/site-tmac" % ( gpath + '/tmac', ) # do we have bash? try: if os.access("/usr/bin/bash", os.R_OK): os.symlink("/usr/bin/bash", "/bin/bash") except OSError: pass except (ValueError, LookupError, SyntaxError, NameError): raise except Exception as e: log.error("doRescue caught exception: %s", e) if flags.automatedInstall: log.error( "An error occurred trying to mount some or all of your system" ) else: if not flags.imageInstall: msg = _("The system will reboot automatically when you " "exit from the shell.") else: msg = _("Run %s to unmount the system " "when you are finished.") % ANACONDA_CLEANUP ButtonChoiceWindow( intf.screen, _("Rescue"), _("An error occurred trying to mount some or all of your " "system. Some of it may be mounted under %s.\n\n" "Press <return> to get a shell.") % ROOT_PATH + msg, [_("OK")]) else: if flags.automatedInstall and ksdata.reboot.action in [ KS_REBOOT, KS_SHUTDOWN ]: log.info("No Linux partitions found") intf.screen.finish() print(_("You don't have any Linux partitions. Rebooting.\n")) sys.exit(0) else: if not flags.imageInstall: msg = _(" The system will reboot automatically when you exit " "from the shell.") else: msg = "" ButtonChoiceWindow(intf.screen, _("Rescue Mode"), _("You don't have any Linux partitions. Press " "return to get a shell.%s") % msg, [_("OK")], width=50) msgStr = "" if rootmounted and not readOnly: sto.makeMtab() try: makeResolvConf(ROOT_PATH) except (OSError, IOError) as e: log.error("error making a resolv.conf: %s", e) msgStr = _("Your system is mounted under the %s directory.") % ( ROOT_PATH, ) ButtonChoiceWindow(intf.screen, _("Rescue"), msgStr, [_("OK")]) # we do not need ncurses anymore, shut them down intf.shutdown() #create /etc/fstab in ramdisk, so it is easier to work with RO mounted filesystems makeFStab() # run %post if we've mounted everything if rootmounted and not readOnly and flags.automatedInstall: runPostScripts(ksdata.scripts) # start shell if reboot wasn't requested if not flags.automatedInstall or not ksdata.reboot.action in [ KS_REBOOT, KS_SHUTDOWN ]: runShell(msg=msgStr) sys.exit(0)
def doConfiguration(storage, payload, ksdata, instClass): willWriteNetwork = not flags.flags.imageInstall and not flags.flags.dirInstall willRunRealmd = ksdata.realm.discovered # configure base, create users, configure addons, initramfs, post-install step_count = 5 # network, maybe if willWriteNetwork: step_count += 1 # if a realm was discovered, # increment the counter as the # real joining step will be executed if willRunRealmd: step_count += 1 if ksdata.snapshot and ksdata.snapshot.has_snapshot(SNAPSHOT_WHEN_POST_INSTALL): step_count += 1 progress_init(step_count) # Now run the execute methods of ksdata that require an installed system # to be present first. with progress_report(_("Configuring installed system")): ksdata.authconfig.execute(storage, ksdata, instClass) ksdata.selinux.execute(storage, ksdata, instClass) ksdata.firstboot.execute(storage, ksdata, instClass) ksdata.services.execute(storage, ksdata, instClass) ksdata.keyboard.execute(storage, ksdata, instClass) ksdata.timezone.execute(storage, ksdata, instClass) ksdata.lang.execute(storage, ksdata, instClass) ksdata.firewall.execute(storage, ksdata, instClass) ksdata.xconfig.execute(storage, ksdata, instClass) ksdata.skipx.execute(storage, ksdata, instClass) if willWriteNetwork: with progress_report(_("Writing network configuration")): ksdata.network.execute(storage, ksdata, instClass) # Creating users and groups requires some pre-configuration. with progress_report(_("Creating users")): createLuserConf(iutil.getSysroot(), algoname=getPassAlgo(ksdata.authconfig.authconfig)) u = Users() ksdata.rootpw.execute(storage, ksdata, instClass, u) ksdata.group.execute(storage, ksdata, instClass, u) ksdata.user.execute(storage, ksdata, instClass, u) ksdata.sshkey.execute(storage, ksdata, instClass, u) with progress_report(_("Configuring addons")): ksdata.addons.execute(storage, ksdata, instClass, u, payload) with progress_report(_("Generating initramfs")): payload.recreateInitrds(force=True) if willRunRealmd: with progress_report(_("Joining realm: %s") % ksdata.realm.discovered): ksdata.realm.execute(storage, ksdata, instClass) with progress_report(_("Running post-installation scripts")): runPostScripts(ksdata.scripts) # setup kexec reboot if requested if flags.flags.kexec: setup_kexec() # Write the kickstart file to the installed system (or, copy the input # kickstart file over if one exists). if flags.flags.nosave_output_ks: # don't write the kickstart file to the installed system if this has # been disabled by the nosave option log.warning("Writing of the output kickstart to installed system has been disabled" " by the nosave option.") else: _writeKS(ksdata) # write out the user interaction config file screen_access.sam.write_out_config_file() if ksdata.snapshot and ksdata.snapshot.has_snapshot(SNAPSHOT_WHEN_POST_INSTALL): with progress_report(N_("Creating snapshots")): ksdata.snapshot.execute(storage, ksdata, instClass) progress_complete()
def doRescue(intf, rescue_mount, ksdata): import blivet # XXX: hook the exception handler wrapper that turns off snack first orig_hook = sys.excepthook sys.excepthook = lambda ty, val, tb: _exception_handler_wrapper(orig_hook, intf.screen, ty, val, tb) for f in [ "services", "protocols", "group", "joe", "man.config", "nsswitch.conf", "selinux", "mke2fs.conf" ]: try: os.symlink('/mnt/runtime/etc/' + f, '/etc/' + f) except OSError: pass # Early shell access with no disk access attempts if not rescue_mount: # the %post should be responsible for mounting all needed file systems # NOTE: 1st script must be bash or simple python as nothing else might be available in the rescue image if flags.automatedInstall and ksdata.scripts: runPostScripts(ksdata.scripts) else: runShell() sys.exit(0) if flags.automatedInstall: readOnly = ksdata.rescue.romount else: # prompt to see if we should try and find root filesystem and mount # everything in /etc/fstab on that root while True: rc = ButtonChoiceWindow(intf.screen, _("Rescue"), _("The rescue environment will now attempt to find your " "Linux installation and mount it under the directory " "%s. You can then make any changes required to your " "system. If you want to proceed with this step choose " "'Continue'. You can also choose to mount your file systems " "read-only instead of read-write by choosing 'Read-Only'. " "\n\n" "If for some reason this process fails you can choose 'Skip' " "and this step will be skipped and you will go directly to a " "command shell.\n\n") % (ROOT_PATH,), [_("Continue"), _("Read-Only"), _("Skip")] ) if rc == _("Skip").lower(): runShell(intf.screen) sys.exit(0) else: readOnly = rc == _("Read-Only").lower() break sto = blivet.Blivet(ksdata=ksdata) blivet.storageInitialize(sto, ksdata, []) _unlock_devices(intf, sto) roots = blivet.findExistingInstallations(sto.devicetree) if not roots: root = None elif len(roots) == 1: root = roots[0] else: height = min (len (roots), 12) if height == 12: scroll = 1 else: scroll = 0 lst = [] for root in roots: lst.append("%s" % root.name) (button, choice) = \ ListboxChoiceWindow(intf.screen, _("System to Rescue"), _("Which device holds the root partition " "of your installation?"), lst, [ _("OK"), _("Exit") ], width = 30, scroll = scroll, height = height, help = "multipleroot") if button == _("Exit").lower(): root = None else: root = roots[choice] rootmounted = False if root: try: # TODO: add a callback to warn about dirty filesystems mountExistingSystem(sto.fsset, root.device, allowDirty = True, readOnly = readOnly) if not flags.imageInstall: msg = _("The system will reboot automatically when you exit " "from the shell.") else: msg = _("Run %s to unmount the system " "when you are finished.") % ANACONDA_CLEANUP if rc == -1: if flags.automatedInstall: log.error("System had dirty file systems which you chose not to mount") else: ButtonChoiceWindow(intf.screen, _("Rescue"), _("Your system had dirty file systems which you chose not " "to mount. Press return to get a shell from which " "you can fsck and mount your partitions. %s") % msg, [_("OK")], width = 50) rootmounted = False else: if flags.automatedInstall: log.info("System has been mounted under: %s", ROOT_PATH) else: ButtonChoiceWindow(intf.screen, _("Rescue"), _("Your system has been mounted under %(rootPath)s.\n\n" "Press <return> to get a shell. If you would like to " "make your system the root environment, run the command:\n\n" "\tchroot %(rootPath)s\n\n%(msg)s") % {'rootPath': ROOT_PATH, 'msg': msg}, [_("OK")] ) rootmounted = True # now turn on swap if not readOnly: try: sto.turnOnSwap() except StorageError: log.error("Error enabling swap") # and selinux too if flags.selinux: # we have to catch the possible exception # because we support read-only mounting try: fd = open("%s/.autorelabel" % ROOT_PATH, "w+") fd.close() except IOError: log.warning("cannot touch /.autorelabel") # set a library path to use mounted fs libdirs = os.environ.get("LD_LIBRARY_PATH", "").split(":") mounted = map(lambda dir: "/mnt/sysimage%s" % dir, libdirs) os.environ["LD_LIBRARY_PATH"] = ":".join(libdirs + mounted) # find groff data dir gversion = None try: glst = os.listdir("/mnt/sysimage/usr/share/groff") except OSError: pass else: # find a directory which is a numeral, its where # data files are for gdir in glst: if re.match(r'\d[.\d]+\d$', gdir): gversion = gdir break if gversion is not None: gpath = "/mnt/sysimage/usr/share/groff/"+gversion os.environ["GROFF_FONT_PATH"] = gpath + '/font' os.environ["GROFF_TMAC_PATH"] = "%s:/mnt/sysimage/usr/share/groff/site-tmac" % (gpath + '/tmac',) # do we have bash? try: if os.access("/usr/bin/bash", os.R_OK): os.symlink ("/usr/bin/bash", "/bin/bash") except OSError: pass except (ValueError, LookupError, SyntaxError, NameError): raise except Exception as e: log.error("doRescue caught exception: %s", e) if flags.automatedInstall: log.error("An error occurred trying to mount some or all of your system") else: if not flags.imageInstall: msg = _("The system will reboot automatically when you " "exit from the shell.") else: msg = _("Run %s to unmount the system " "when you are finished.") % ANACONDA_CLEANUP ButtonChoiceWindow(intf.screen, _("Rescue"), _("An error occurred trying to mount some or all of your " "system. Some of it may be mounted under %s.\n\n" "Press <return> to get a shell.") % ROOT_PATH + msg, [_("OK")] ) else: if flags.automatedInstall and ksdata.reboot.action in [KS_REBOOT, KS_SHUTDOWN]: log.info("No Linux partitions found") intf.screen.finish() print(_("You don't have any Linux partitions. Rebooting.\n")) sys.exit(0) else: if not flags.imageInstall: msg = _(" The system will reboot automatically when you exit " "from the shell.") else: msg = "" ButtonChoiceWindow(intf.screen, _("Rescue Mode"), _("You don't have any Linux partitions. Press " "return to get a shell.%s") % msg, [ _("OK") ], width = 50) msgStr = "" if rootmounted and not readOnly: sto.makeMtab() try: makeResolvConf(ROOT_PATH) except (OSError, IOError) as e: log.error("error making a resolv.conf: %s", e) msgStr = _("Your system is mounted under the %s directory.") % (ROOT_PATH,) ButtonChoiceWindow(intf.screen, _("Rescue"), msgStr, [_("OK")] ) # we do not need ncurses anymore, shut them down intf.shutdown() #create /etc/fstab in ramdisk, so it is easier to work with RO mounted filesystems makeFStab() # run %post if we've mounted everything if rootmounted and not readOnly and flags.automatedInstall: runPostScripts(ksdata.scripts) # start shell if reboot wasn't requested if not flags.automatedInstall or not ksdata.reboot.action in [KS_REBOOT, KS_SHUTDOWN]: runShell(msg=msgStr) sys.exit(0)
def doConfiguration(storage, payload, ksdata, instClass): willWriteNetwork = not flags.flags.imageInstall and not flags.flags.dirInstall willRunRealmd = ksdata.realm.discovered # configure base, create users, configure addons, initramfs, post-install step_count = 5 # network, maybe if willWriteNetwork: step_count += 1 # if a realm was discovered, # increment the counter as the # real joining step will be executed if willRunRealmd: step_count += 1 progress_init(step_count) # Now run the execute methods of ksdata that require an installed system # to be present first. with progress_report(N_("Configuring installed system")): ksdata.authconfig.execute(storage, ksdata, instClass) ksdata.selinux.execute(storage, ksdata, instClass) ksdata.firstboot.execute(storage, ksdata, instClass) ksdata.services.execute(storage, ksdata, instClass) ksdata.keyboard.execute(storage, ksdata, instClass) ksdata.timezone.execute(storage, ksdata, instClass) ksdata.lang.execute(storage, ksdata, instClass) ksdata.firewall.execute(storage, ksdata, instClass) ksdata.xconfig.execute(storage, ksdata, instClass) ksdata.skipx.execute(storage, ksdata, instClass) if willWriteNetwork: with progress_report(N_("Writing network configuration")): ksdata.network.execute(storage, ksdata, instClass) # Creating users and groups requires some pre-configuration. with progress_report(N_("Creating users")): u = Users() ksdata.rootpw.execute(storage, ksdata, instClass, u) ksdata.group.execute(storage, ksdata, instClass, u) ksdata.user.execute(storage, ksdata, instClass, u) ksdata.sshkey.execute(storage, ksdata, instClass, u) with progress_report(N_("Configuring addons")): ksdata.addons.execute(storage, ksdata, instClass, u, payload) with progress_report(N_("Generating initramfs")): payload.recreateInitrds() # This works around 2 problems, /boot on BTRFS and BTRFS installations where the initrd is # recreated after the first writeBootLoader call. This reruns it after the new initrd has # been created, fixing the kernel root and subvol args and adding the missing initrd entry. boot_on_btrfs = isinstance(storage.mountpoints.get("/"), BTRFSDevice) if flags.flags.livecdInstall and boot_on_btrfs \ and (not ksdata.bootloader.disabled and ksdata.bootloader != "none"): writeBootLoader(storage, payload, instClass, ksdata) if willRunRealmd: with progress_report( N_("Joining realm: %s") % ksdata.realm.discovered): ksdata.realm.execute(storage, ksdata, instClass) with progress_report(N_("Running post-installation scripts")): runPostScripts(ksdata.scripts) # setup kexec reboot if requested if flags.flags.kexec: setup_kexec() # Write the kickstart file to the installed system (or, copy the input # kickstart file over if one exists). if flags.flags.nosave_output_ks: # don't write the kickstart file to the installed system if this has # been disabled by the nosave option log.warning( "Writing of the output kickstart to installed system has been disabled" " by the nosave option.") else: _writeKS(ksdata) # Write out the user interaction config file. # # But make sure it's not written out in the image and directory installation mode, # as that might result in spokes being inadvertedly hidden when the actual installation # startes from the generate image or directory contents. if flags.flags.imageInstall: log.info( "Not writing out user interaction config file due to image install mode." ) elif flags.flags.dirInstall: log.info( "Not writing out user interaction config file due to directory install mode." ) else: screen_access.sam.write_out_config_file() progress_complete()
def doConfiguration(storage, payload, ksdata, instClass): willWriteNetwork = not flags.flags.imageInstall and not flags.flags.dirInstall willRunRealmd = ksdata.realm.discovered # configure base, create users, configure addons, initramfs, post-install step_count = 5 # network, maybe if willWriteNetwork: step_count += 1 # if a realm was discovered, # increment the counter as the # real joining step will be executed if willRunRealmd: step_count += 1 progress_init(step_count) # Now run the execute methods of ksdata that require an installed system # to be present first. with progress_report(N_("Configuring installed system")): ksdata.authconfig.execute(storage, ksdata, instClass) ksdata.selinux.execute(storage, ksdata, instClass) ksdata.firstboot.execute(storage, ksdata, instClass) ksdata.services.execute(storage, ksdata, instClass) ksdata.keyboard.execute(storage, ksdata, instClass) ksdata.timezone.execute(storage, ksdata, instClass) ksdata.lang.execute(storage, ksdata, instClass) ksdata.firewall.execute(storage, ksdata, instClass) ksdata.xconfig.execute(storage, ksdata, instClass) ksdata.skipx.execute(storage, ksdata, instClass) if willWriteNetwork: with progress_report(N_("Writing network configuration")): ksdata.network.execute(storage, ksdata, instClass) # Creating users and groups requires some pre-configuration. with progress_report(N_("Creating users")): u = Users() ksdata.rootpw.execute(storage, ksdata, instClass, u) ksdata.group.execute(storage, ksdata, instClass, u) ksdata.user.execute(storage, ksdata, instClass, u) ksdata.sshkey.execute(storage, ksdata, instClass, u) with progress_report(N_("Configuring addons")): ksdata.addons.execute(storage, ksdata, instClass, u, payload) with progress_report(N_("Generating initramfs")): payload.recreateInitrds() # This works around 2 problems, /boot on BTRFS and BTRFS installations where the initrd is # recreated after the first writeBootLoader call. This reruns it after the new initrd has # been created, fixing the kernel root and subvol args and adding the missing initrd entry. boot_on_btrfs = isinstance(storage.mountpoints.get("/"), BTRFSDevice) if flags.flags.livecdInstall and boot_on_btrfs \ and (not ksdata.bootloader.disabled and ksdata.bootloader != "none"): writeBootLoader(storage, payload, instClass, ksdata) if willRunRealmd: with progress_report(N_("Joining realm: %s") % ksdata.realm.discovered): ksdata.realm.execute(storage, ksdata, instClass) with progress_report(N_("Running post-installation scripts")): runPostScripts(ksdata.scripts) # setup kexec reboot if requested if flags.flags.kexec: setup_kexec() # Write the kickstart file to the installed system (or, copy the input # kickstart file over if one exists). if flags.flags.nosave_output_ks: # don't write the kickstart file to the installed system if this has # been disabled by the nosave option log.warning("Writing of the output kickstart to installed system has been disabled" " by the nosave option.") else: _writeKS(ksdata) # Write out the user interaction config file. # # But make sure it's not written out in the image and directory installation mode, # as that might result in spokes being inadvertedly hidden when the actual installation # startes from the generate image or directory contents. if flags.flags.imageInstall: log.info("Not writing out user interaction config file due to image install mode.") elif flags.flags.dirInstall: log.info("Not writing out user interaction config file due to directory install mode.") else: screen_access.sam.write_out_config_file() progress_complete()