当前位置: 首页>>代码示例>>Python>>正文


Python util.getSysroot函数代码示例

本文整理汇总了Python中pyanaconda.core.util.getSysroot函数的典型用法代码示例。如果您正苦于以下问题:Python getSysroot函数的具体用法?Python getSysroot怎么用?Python getSysroot使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了getSysroot函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: prepare_mount_targets

    def prepare_mount_targets(self, storage):
        """ Prepare the ostree root """
        ostreesetup = self.data.ostreesetup

        # Currently, blivet sets up mounts in the physical root.
        # We used to unmount them and remount them in the sysroot, but
        # since 664ef7b43f9102aa9332d0db5b7d13f8ece436f0 we now just set up
        # bind mounts.

        # Make /usr readonly like ostree does at runtime normally
        self._setup_internal_bindmount('/usr', bind_ro=True, src_physical=False)

        # Explicitly do API mounts; some of these may be tracked by blivet, but
        # we'll skip them below.
        api_mounts = ["/dev", "/proc", "/run", "/sys"]
        for path in api_mounts:
            self._setup_internal_bindmount(path)

        # Handle /var; if the admin didn't specify a mount for /var, we need
        # to do the default ostree one.
        # https://github.com/ostreedev/ostree/issues/855
        var_root = '/ostree/deploy/' + ostreesetup.osname + '/var'
        if storage.mountpoints.get("/var") is None:
            self._setup_internal_bindmount(var_root, dest='/var', recurse=False)
        else:
            # Otherwise, bind it
            self._setup_internal_bindmount('/var', recurse=False)

        # Now that we have /var, start filling in any directories that may be
        # required later there. We explicitly make /var/lib, since
        # systemd-tmpfiles doesn't have a --prefix-only=/var/lib. We rely on
        # 80-setfilecons.ks to set the label correctly.
        util.mkdirChain(util.getSysroot() + '/var/lib')
        # Next, run tmpfiles to make subdirectories of /var. We need this for
        # both mounts like /home (really /var/home) and %post scripts might
        # want to write to e.g. `/srv`, `/root`, `/usr/local`, etc. The
        # /var/lib/rpm symlink is also critical for having e.g. `rpm -qa` work
        # in %post. We don't iterate *all* tmpfiles because we don't have the
        # matching NSS configuration inside Anaconda, and we can't "chroot" to
        # get it because that would require mounting the API filesystems in the
        # target.
        for varsubdir in ('home', 'roothome', 'lib/rpm', 'opt', 'srv',
                          'usrlocal', 'mnt', 'media', 'spool', 'spool/mail'):
            self._safe_exec_with_redirect("systemd-tmpfiles",
                                          ["--create", "--boot", "--root=" + util.getSysroot(),
                                           "--prefix=/var/" + varsubdir])

        # Handle mounts like /boot (except avoid /boot/efi; we just need the
        # toplevel), and any admin-specified points like /home (really
        # /var/home). Note we already handled /var above. Avoid recursion since
        # sub-mounts will be in the list too.  We sort by length as a crude
        # hack to try to simulate the tree relationship; it looks like this
        # is handled in blivet in a different way.
        for mount in sorted(storage.mountpoints, key=len):
            if mount in ('/', '/var') or mount in api_mounts:
                continue
            self._setup_internal_bindmount(mount, recurse=False)

        # And finally, do a nonrecursive bind for the sysroot
        self._setup_internal_bindmount("/", dest="/sysroot", recurse=False)
开发者ID:rvykydal,项目名称:anaconda,代码行数:60,代码来源:rpmostreepayload.py

示例2: setup_kexec

def setup_kexec():
    """ Setup kexec to use the new kernel and default bootloader entry

        This uses grubby to determine the bootloader arguments from the default entry,
        and then sets up kexec so that reboot will use the new kernel and initrd instead
        of doing a full reboot.

        .. note::
            Once kexec is called there is nothing else to do, the reboot code already handles
            having kexec setup.
    """
    try:
        boot_info = run_grubby()
    except GrubbyInfoError:
        # grubby couldn't find a default entry, use the first one instead
        try:
            boot_info = run_grubby(["--info", "ALL"])
        except GrubbyInfoError:
            # Grubby can't get the bootloader's info, kexec won't work.
            log.error("kexec reboot setup failed, grubby could not get bootloader info.")
            return

    # Copy the kernel and initrd to /tmp/
    shutil.copy2(getSysroot() + boot_info.kernel, "/tmp/vmlinuz-kexec-reboot")
    shutil.copy2(getSysroot() + boot_info.initrd, "/tmp/initrd-kexec-reboot")

    append = "root=%s %s" % (boot_info.root, boot_info.args)
    args = ["--initrd", "/tmp/initrd-kexec-reboot", "--append", append, "-l", "/tmp/vmlinuz-kexec-reboot"]
    try:
        rc = execWithRedirect("kexec", args)
    except OSError as e:
        log.error("setup_kexec failed: %s", e)
    if rc != 0:
        log.error("setup_kexec failed with rc=%d: See program.log for output", rc)
开发者ID:zhangsju,项目名称:anaconda,代码行数:34,代码来源:kexec.py

示例3: write_defaults

    def write_defaults(self):
        defaults_file = "%s%s" % (util.getSysroot(), self.defaults_file)
        defaults = open(defaults_file, "w+")
        defaults.write("GRUB_TIMEOUT=%d\n" % self.timeout)
        defaults.write("GRUB_DISTRIBUTOR=\"$(sed 's, release .*$,,g' /etc/system-release)\"\n")
        defaults.write("GRUB_DEFAULT=saved\n")
        defaults.write("GRUB_DISABLE_SUBMENU=true\n")
        if self.console and self.has_serial_console:
            defaults.write("GRUB_TERMINAL=\"serial console\"\n")
            defaults.write("GRUB_SERIAL_COMMAND=\"%s\"\n" % self.serial_command)
        else:
            defaults.write("GRUB_TERMINAL_OUTPUT=\"%s\"\n" % self.terminal_type)

        # this is going to cause problems for systems containing multiple
        # linux installations or even multiple boot entries with different
        # boot arguments
        log.info("bootloader.py: used boot args: %s ", self.boot_args)
        defaults.write("GRUB_CMDLINE_LINUX=\"%s\"\n" % self.boot_args)
        defaults.write("GRUB_DISABLE_RECOVERY=\"true\"\n")
        #defaults.write("GRUB_THEME=\"/boot/grub2/themes/system/theme.txt\"\n")

        if self.use_bls and os.path.exists(util.getSysroot() + "/usr/sbin/new-kernel-pkg"):
            log.warning("BLS support disabled due new-kernel-pkg being present")
            self.use_bls = False

        if self.use_bls:
            defaults.write("GRUB_ENABLE_BLSCFG=true\n")
        defaults.close()
开发者ID:rvykydal,项目名称:anaconda,代码行数:28,代码来源:grub2.py

示例4: execute

    def execute(self):
        unit_name = "initial-setup.service"
        services_proxy = SERVICES.get_proxy()
        setup_on_boot = services_proxy.SetupOnBoot

        if setup_on_boot == SETUP_ON_BOOT_DISABLED:
            log.debug("The %s service will be disabled.", unit_name)
            util.disable_service(unit_name)
            # Also tell the screen access manager, so that the fact that post installation tools
            # should be disabled propagates to the user interaction config file.
            screen_access.sam.post_install_tools_disabled = True
            return

        if not os.path.exists(os.path.join(util.getSysroot(), "lib/systemd/system/", unit_name)):
            log.debug("The %s service will not be started on first boot, because "
                      "it's unit file is not installed.", unit_name)
            return

        if setup_on_boot == SETUP_ON_BOOT_RECONFIG:
            log.debug("The %s service will run in the reconfiguration mode.", unit_name)
            # write the reconfig trigger file
            f = open(os.path.join(util.getSysroot(), "etc/reconfigSys"), "w+")
            f.close()

        log.debug("The %s service will be enabled.", unit_name)
        util.enable_service(unit_name)
开发者ID:rvykydal,项目名称:anaconda,代码行数:26,代码来源:kickstart.py

示例5: _set_default_boot_target

    def _set_default_boot_target(self):
        """Set the default systemd target for the system."""
        if not os.path.exists(util.getSysroot() + "/etc/systemd/system"):
            log.error("systemd is not installed -- can't set default target")
            return

        # If the target was already set, we don't have to continue.
        services_proxy = SERVICES.get_proxy()
        if services_proxy.DefaultTarget:
            log.debug("The default target is already set.")
            return

        try:
            import rpm
        except ImportError:
            log.info("failed to import rpm -- not adjusting default runlevel")
        else:
            ts = rpm.TransactionSet(util.getSysroot())

            # XXX one day this might need to account for anaconda's display mode
            if ts.dbMatch("provides", 'service(graphical-login)').count() and \
               not flags.usevnc:
                # We only manipulate the ksdata.  The symlink is made later
                # during the config write out.
                services_proxy.SetDefaultTarget(GRAPHICAL_TARGET)
            else:
                services_proxy.SetDefaultTarget(TEXT_ONLY_TARGET)
开发者ID:rvykydal,项目名称:anaconda,代码行数:27,代码来源:__init__.py

示例6: update_bls_args

    def update_bls_args(self, image, args):
        machine_id_path = util.getSysroot() + "/etc/machine-id"
        if not os.access(machine_id_path, os.R_OK):
            log.error("failed to read machine-id file")
            return

        with open(machine_id_path, "r") as fd:
            machine_id = fd.readline().strip()

        bls_dir = "%s%s/loader/entries/" % (util.getSysroot(), self.boot_dir)

        if image.kernel == "vmlinuz-0-rescue-" + machine_id:
            bls_path = "%s%s-0-rescue.conf" % (bls_dir, machine_id)
        else:
            bls_path = "%s%s-%s.conf" % (bls_dir, machine_id, image.version)

        if not os.access(bls_path, os.W_OK):
            log.error("failed to update boot args in BLS file %s", bls_path)
            return

        with open(bls_path, "r") as bls:
            lines = bls.readlines()
            for i, line in enumerate(lines):
                if line.startswith("options "):
                    lines[i] = "options %s\n" % (args)

        with open(bls_path, "w") as bls:
            bls.writelines(lines)
开发者ID:rvykydal,项目名称:anaconda,代码行数:28,代码来源:zipl.py

示例7: mount_root

    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
开发者ID:rvykydal,项目名称:anaconda,代码行数:57,代码来源:rescue.py

示例8: sysroot_test

    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")
开发者ID:rvykydal,项目名称:anaconda,代码行数:11,代码来源:iutil_test.py

示例9: _write_module_blacklist

    def _write_module_blacklist(self):
        """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 flags.cmdline:
            return

        util.mkdirChain(util.getSysroot() + "/etc/modprobe.d")
        with open(util.getSysroot() + "/etc/modprobe.d/anaconda-blacklist.conf", "w") as f:
            f.write("# Module blacklists written by anaconda\n")
            for module in flags.cmdline["modprobe.blacklist"].split():
                f.write("blacklist %s\n" % module)
开发者ID:rvykydal,项目名称:anaconda,代码行数:13,代码来源:__init__.py

示例10: write

    def write(self):
        """Write the desktop & default target settings to disk."""
        if self.desktop:
            with open(util.getSysroot() + "/etc/sysconfig/desktop", "w") as f:
                f.write("DESKTOP=%s\n" % self.desktop)

        if not os.path.isdir(util.getSysroot() + '/etc/systemd/system'):
            log.warning("There is no /etc/systemd/system directory, cannot update default.target!")
            return

        default_target = util.getSysroot() + '/etc/systemd/system/default.target'
        if os.path.islink(default_target):
            os.unlink(default_target)
        os.symlink('/lib/systemd/system/%s' % self.default_target, default_target)
开发者ID:rvykydal,项目名称:anaconda,代码行数:14,代码来源:desktop.py

示例11: post_install

    def post_install(self):
        super().post_install()

        gi.require_version("OSTree", "1.0")
        from gi.repository import OSTree
        cancellable = None

        # Following up on the "remote delete" above, we removed the
        # remote from /ostree/repo/config.  But we want it in /etc, so
        # re-add it to /etc/ostree/remotes.d, using the sysroot path.
        #
        # However, we ignore the case where the remote already exists,
        # which occurs when the content itself provides the remote
        # config file.

        # Note here we use the deployment as sysroot, because it's
        # that version of /etc that we want.
        sysroot_file = Gio.File.new_for_path(util.getSysroot())
        sysroot = OSTree.Sysroot.new(sysroot_file)
        sysroot.load(cancellable)
        repo = sysroot.get_repo(None)[1]
        repo.remote_change(sysroot_file,
                           OSTree.RepoRemoteChange.ADD_IF_NOT_EXISTS,
                           self.data.ostreesetup.remote, self.data.ostreesetup.url,
                           Variant('a{sv}', self._remoteOptions),
                           cancellable)

        boot = util.getSysroot() + '/boot'

        # If we're using GRUB2, move its config file, also with a
        # compatibility symlink.
        boot_grub2_cfg = boot + '/grub2/grub.cfg'
        if os.path.isfile(boot_grub2_cfg):
            boot_loader = boot + '/loader'
            target_grub_cfg = boot_loader + '/grub.cfg'
            log.info("Moving %s -> %s", boot_grub2_cfg, target_grub_cfg)
            os.rename(boot_grub2_cfg, target_grub_cfg)
            os.symlink('../loader/grub.cfg', boot_grub2_cfg)

        # Skip kernel args setup for dirinstall, there is no bootloader or rootDevice setup.
        if not conf.target.is_directory:
            # OSTree owns the bootloader configuration, so here we give it
            # the argument list we computed from storage, architecture and
            # such.
            set_kargs_args = ["admin", "instutil", "set-kargs"]
            set_kargs_args.extend(self.storage.bootloader.boot_args)
            set_kargs_args.append("root=" + self.storage.root_device.fstab_spec)
            self._safe_exec_with_redirect("ostree", set_kargs_args, root=util.getSysroot())
开发者ID:rvykydal,项目名称:anaconda,代码行数:48,代码来源:rpmostreepayload.py

示例12: write

    def write(self):
        """Write out all config files based on the set of filesystems."""
        sysroot = util.getSysroot()
        # /etc/fstab
        fstab_path = os.path.normpath("%s/etc/fstab" % sysroot)
        fstab = self.fstab()
        open(fstab_path, "w").write(fstab)

        # /etc/crypttab
        crypttab_path = os.path.normpath("%s/etc/crypttab" % sysroot)
        crypttab = self.crypttab()
        origmask = os.umask(0o077)
        open(crypttab_path, "w").write(crypttab)
        os.umask(origmask)

        # /etc/mdadm.conf
        mdadm_path = os.path.normpath("%s/etc/mdadm.conf" % sysroot)
        mdadm_conf = self.mdadm_conf()
        if mdadm_conf:
            open(mdadm_path, "w").write(mdadm_conf)

        # /etc/multipath.conf
        if any(d for d in self.devices if d.type == "dm-multipath"):
            copy_to_system("/etc/multipath.conf")
            copy_to_system("/etc/multipath/wwids")
            copy_to_system("/etc/multipath/bindings")
        else:
            log.info("not writing out mpath configuration")
开发者ID:rvykydal,项目名称:anaconda,代码行数:28,代码来源:fsset.py

示例13: mk_dev_root

 def mk_dev_root(self):
     root = self.root_device
     sysroot = util.getSysroot()
     dev = "%s/%s" % (sysroot, root.path)
     if not os.path.exists("%s/dev/root" % (sysroot,)) and os.path.exists(dev):
         rdev = os.stat(dev).st_rdev
         os.mknod("%s/dev/root" % (sysroot,), stat.S_IFBLK | 0o600, rdev)
开发者ID:rvykydal,项目名称:anaconda,代码行数:7,代码来源:fsset.py

示例14: write_out_config_file

    def write_out_config_file(self, config_path=None):
        """Write the user interaction config file to persistent storage.
        - we always read the config file from the top level filesystem, as:
        -> on live media the file will be there
        -> on non-live media the config file (if any) will be injected to the top level
        -> filesystem by image generation tools or by an updates/product image

        - on the other hand the "output" config file needs to always end on the installed
          system, so that post installation setup tools (such as Initial Setup or
          Gnome Initial Setup) can use it
        -> therefore we always write the config file to the sysroot path
        """

        if config_path is None:
            config_path = util.getSysroot() + CONFIG_FILE_PATH

        with self._lock:
            new_config_file = not os.path.exists(config_path)
            try:
                with open(config_path, "wt") as f:
                    if new_config_file:
                        # we are creating a new file, so add a header that it was created by Anaconda,
                        # including its version number
                        f.write(self._get_new_config_header())
                    self._config.write(f)
            except OSError:
                log.exception("Can't write user interaction config file.")
开发者ID:rvykydal,项目名称:anaconda,代码行数:27,代码来源:screen_access.py

示例15: write_config_post

 def write_config_post(self):
     etc_extlinux = os.path.normpath(util.getSysroot() + "/etc/" + self._config_file)
     if not os.access(etc_extlinux, os.R_OK):
         try:
             os.symlink("../boot/%s" % self._config_file, etc_extlinux)
         except OSError as e:
             log.warning("failed to create /etc/extlinux.conf symlink: %s", e)
开发者ID:rvykydal,项目名称:anaconda,代码行数:7,代码来源:extlinux.py


注:本文中的pyanaconda.core.util.getSysroot函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。