def mount_filesystems(self): root_path = util.getTargetPhysicalRoot() # Mount the root and the filesystems. self.fsset.mount_filesystems(root_path=root_path) # Set up the sysroot. util.setSysroot(root_path)
def sysroot_test(self): self.assertEqual(util.getTargetPhysicalRoot(), "/mnt/sysimage") self.assertEqual(util.getSysroot(), "/mnt/sysimage") util.setSysroot("/what/ever") self.assertEqual(util.getTargetPhysicalRoot(), "/mnt/sysimage") self.assertEqual(util.getSysroot(), "/what/ever") util.setSysroot(None) self.assertEqual(util.getTargetPhysicalRoot(), "/mnt/sysimage") self.assertEqual(util.getSysroot(), "/mnt/sysimage")
def mount_existing_system(storage, root_device, read_only=None, sysroot=None): """Mount filesystems specified in root_device's /etc/fstab file.""" root_path = sysroot or util.getTargetPhysicalRoot() read_only = "ro" if read_only else "" # Mount the root device. if root_device.protected and os.path.ismount("/mnt/install/isodir"): blivet_util.mount("/mnt/install/isodir", root_path, fstype=root_device.format.type, options="bind") else: root_device.setup() root_device.format.mount(chroot=root_path, mountpoint="/", options="%s,%s" % (root_device.format.options, read_only)) # Set up the sysroot. util.setSysroot(root_path) # Mount the filesystems. storage.fsset.parse_fstab(chroot=root_path) storage.fsset.mount_filesystems(root_path=root_path, read_only=read_only, skip_root=True) # Turn on swap. if not conf.target.is_image or not read_only: try: storage.fsset.turn_on_swap(root_path=sysroot) except StorageError as e: log.error("Error enabling swap: %s", str(e)) # Generate mtab. if not read_only: storage.make_mtab(chroot=root_path)
def install(self): mainctx = create_new_context() mainctx.push_thread_default() cancellable = None gi.require_version("OSTree", "1.0") gi.require_version("RpmOstree", "1.0") from gi.repository import OSTree, RpmOstree ostreesetup = self.data.ostreesetup log.info("executing ostreesetup=%r", ostreesetup) # Initialize the filesystem - this will create the repo as well self._safeExecWithRedirect("ostree", [ "admin", "--sysroot=" + util.getTargetPhysicalRoot(), "init-fs", util.getTargetPhysicalRoot() ]) # Here, we use the physical root as sysroot, because we haven't # yet made a deployment. sysroot_file = Gio.File.new_for_path(util.getTargetPhysicalRoot()) sysroot = OSTree.Sysroot.new(sysroot_file) sysroot.load(cancellable) repo = sysroot.get_repo(None)[1] # We don't support resuming from interrupted installs repo.set_disable_fsync(True) self._remoteOptions = {} if hasattr(ostreesetup, 'nogpg') and ostreesetup.nogpg: self._remoteOptions['gpg-verify'] = Variant('b', False) if flags.noverifyssl: self._remoteOptions['tls-permissive'] = Variant('b', True) repo.remote_change(None, OSTree.RepoRemoteChange.ADD_IF_NOT_EXISTS, ostreesetup.remote, ostreesetup.url, Variant('a{sv}', self._remoteOptions), cancellable) # Variable substitute the ref: https://pagure.io/atomic-wg/issue/299 ref = RpmOstree.varsubst_basearch(ostreesetup.ref) progressQ.send_message(_("Starting pull of %(branchName)s from %(source)s") % \ {"branchName": ref, "source": ostreesetup.remote}) progress = OSTree.AsyncProgress.new() progress.connect('changed', self._pullProgressCb) pull_opts = {'refs': Variant('as', [ref])} # If we're doing a kickstart, we can at least use the content as a reference: # See <https://github.com/rhinstaller/anaconda/issues/1117> # The first path here is used by <https://pagure.io/fedora-lorax-templates> # and the second by <https://github.com/projectatomic/rpm-ostree-toolbox/> if OSTree.check_version(2017, 8): for path in ['/ostree/repo', '/install/ostree/repo']: if os.path.isdir(path + '/objects'): pull_opts['localcache-repos'] = Variant('as', [path]) break try: repo.pull_with_options(ostreesetup.remote, Variant('a{sv}', pull_opts), progress, cancellable) except GError as e: exn = PayloadInstallError("Failed to pull from repository: %s" % e) log.error(str(exn)) if errors.errorHandler.cb(exn) == errors.ERROR_RAISE: progressQ.send_quit(1) util.ipmi_abort(scripts=self.data.scripts) sys.exit(1) log.info("ostree pull: " + (progress.get_status() or "")) progressQ.send_message(_("Preparing deployment of %s") % (ref, )) # Now that we have the data pulled, delete the remote for now. # This will allow a remote configuration defined in the tree # (if any) to override what's in the kickstart. Otherwise, # we'll re-add it in post. Ideally, ostree would support a # pull without adding a remote, but that would get quite # complex. repo.remote_delete(self.data.ostreesetup.remote, None) self._safeExecWithRedirect("ostree", [ "admin", "--sysroot=" + util.getTargetPhysicalRoot(), "os-init", ostreesetup.osname ]) admin_deploy_args = [ "admin", "--sysroot=" + util.getTargetPhysicalRoot(), "deploy", "--os=" + ostreesetup.osname ] admin_deploy_args.append(ostreesetup.remote + ':' + ref) log.info("ostree admin deploy starting") progressQ.send_message(_("Deployment starting: %s") % (ref, )) self._safeExecWithRedirect("ostree", admin_deploy_args) log.info("ostree admin deploy complete") progressQ.send_message(_("Deployment complete: %s") % (ref, )) # Reload now that we've deployed, find the path to the new deployment sysroot.load(None) deployments = sysroot.get_deployments() assert len(deployments) > 0 deployment = deployments[0] deployment_path = sysroot.get_deployment_directory(deployment) util.setSysroot(deployment_path.get_path()) try: self._copyBootloaderData() except (OSError, RuntimeError) as e: exn = PayloadInstallError("Failed to copy bootloader data: %s" % e) log.error(str(exn)) if errors.errorHandler.cb(exn) == errors.ERROR_RAISE: progressQ.send_quit(1) util.ipmi_abort(scripts=self.data.scripts) sys.exit(1) mainctx.pop_thread_default()
util.ipmi_report(constants.IPMI_STARTED) if (opts.images or opts.dirinstall) and opts.liveinst: stdout_log.error("--liveinst cannot be used with --images or --dirinstall") util.ipmi_report(constants.IPMI_ABORTED) sys.exit(1) if opts.images and opts.dirinstall: stdout_log.error("--images and --dirinstall cannot be used at the same time") util.ipmi_report(constants.IPMI_ABORTED) sys.exit(1) elif opts.dirinstall: root_path = opts.dirinstall util.setTargetPhysicalRoot(root_path) util.setSysroot(root_path) from pyanaconda import vnc from pyanaconda import kickstart from pyanaconda import ntp from pyanaconda import keyboard # we are past the --version and --help shortcut so we can import display & # startup_utils, which import Blivet, without slowing down anything critical from pyanaconda import display from pyanaconda import startup_utils from pyanaconda import rescue from pyanaconda import geoloc from pyanaconda.core.util import ProxyString, ProxyStringError # Print the usual "startup note" that contains Anaconda version # and short usage & bug reporting instructions.
SUPPORTED_KICKSTART_COMMANDS = ["user", "group", "keyboard", "lang", "rootpw", "timezone", "logging", "selinux", "firewall"] # set the environment so that spokes can behave accordingly flags.environs = [FIRSTBOOT_ENVIRON] # set root to "/", we are now in the installed system util.setSysroot("/") signal.signal(signal.SIGINT, signal.SIG_IGN) # setup logging log = logging.getLogger("initial-setup") logging_initialized = False def log_to_journal(message, priority=3): """A quick-and-dirty direct Journal logger. A quick-and-dirty direct Journal logger used to log errors that occur before the normal Python logging system is setup and connected to Journal. :param str message: message to send to Journal
def umount_filesystems(self, swapoff=True): # Unmount the root and the filesystems. self.fsset.umount_filesystems(swapoff=swapoff) # Unmount the sysroot. util.setSysroot(None)
def install(self): mainctx = create_new_context() mainctx.push_thread_default() cancellable = None gi.require_version("OSTree", "1.0") gi.require_version("RpmOstree", "1.0") from gi.repository import OSTree, RpmOstree ostreesetup = self.data.ostreesetup log.info("executing ostreesetup=%r", ostreesetup) # Initialize the filesystem - this will create the repo as well self._safe_exec_with_redirect("ostree", ["admin", "--sysroot=" + util.getTargetPhysicalRoot(), "init-fs", util.getTargetPhysicalRoot()]) # Here, we use the physical root as sysroot, because we haven't # yet made a deployment. sysroot_file = Gio.File.new_for_path(util.getTargetPhysicalRoot()) sysroot = OSTree.Sysroot.new(sysroot_file) sysroot.load(cancellable) repo = sysroot.get_repo(None)[1] # We don't support resuming from interrupted installs repo.set_disable_fsync(True) self._remoteOptions = {} if hasattr(ostreesetup, 'nogpg') and ostreesetup.nogpg: self._remoteOptions['gpg-verify'] = Variant('b', False) if flags.noverifyssl: self._remoteOptions['tls-permissive'] = Variant('b', True) repo.remote_change(None, OSTree.RepoRemoteChange.ADD_IF_NOT_EXISTS, ostreesetup.remote, ostreesetup.url, Variant('a{sv}', self._remoteOptions), cancellable) # Variable substitute the ref: https://pagure.io/atomic-wg/issue/299 ref = RpmOstree.varsubst_basearch(ostreesetup.ref) progressQ.send_message(_("Starting pull of %(branchName)s from %(source)s") % {"branchName": ref, "source": ostreesetup.remote}) progress = OSTree.AsyncProgress.new() progress.connect('changed', self._pull_progress_cb) pull_opts = {'refs': Variant('as', [ref])} # If we're doing a kickstart, we can at least use the content as a reference: # See <https://github.com/rhinstaller/anaconda/issues/1117> # The first path here is used by <https://pagure.io/fedora-lorax-templates> # and the second by <https://github.com/projectatomic/rpm-ostree-toolbox/> if OSTree.check_version(2017, 8): for path in ['/ostree/repo', '/install/ostree/repo']: if os.path.isdir(path + '/objects'): pull_opts['localcache-repos'] = Variant('as', [path]) break try: repo.pull_with_options(ostreesetup.remote, Variant('a{sv}', pull_opts), progress, cancellable) except GError as e: exn = PayloadInstallError("Failed to pull from repository: %s" % e) log.error(str(exn)) if errors.errorHandler.cb(exn) == errors.ERROR_RAISE: progressQ.send_quit(1) util.ipmi_abort(scripts=self.data.scripts) sys.exit(1) log.info("ostree pull: %s", progress.get_status() or "") progressQ.send_message(_("Preparing deployment of %s") % (ref, )) # Now that we have the data pulled, delete the remote for now. # This will allow a remote configuration defined in the tree # (if any) to override what's in the kickstart. Otherwise, # we'll re-add it in post. Ideally, ostree would support a # pull without adding a remote, but that would get quite # complex. repo.remote_delete(self.data.ostreesetup.remote, None) self._safe_exec_with_redirect("ostree", ["admin", "--sysroot=" + util.getTargetPhysicalRoot(), "os-init", ostreesetup.osname]) admin_deploy_args = ["admin", "--sysroot=" + util.getTargetPhysicalRoot(), "deploy", "--os=" + ostreesetup.osname] admin_deploy_args.append(ostreesetup.remote + ':' + ref) log.info("ostree admin deploy starting") progressQ.send_message(_("Deployment starting: %s") % (ref, )) self._safe_exec_with_redirect("ostree", admin_deploy_args) log.info("ostree admin deploy complete") progressQ.send_message(_("Deployment complete: %s") % (ref, )) # Reload now that we've deployed, find the path to the new deployment sysroot.load(None) deployments = sysroot.get_deployments() assert len(deployments) > 0 deployment = deployments[0] deployment_path = sysroot.get_deployment_directory(deployment) util.setSysroot(deployment_path.get_path()) try: self._copy_bootloader_data() except (OSError, RuntimeError) as e: exn = PayloadInstallError("Failed to copy bootloader data: %s" % e) log.error(str(exn)) if errors.errorHandler.cb(exn) == errors.ERROR_RAISE: progressQ.send_quit(1) util.ipmi_abort(scripts=self.data.scripts) sys.exit(1) mainctx.pop_thread_default()