Example #1
0
    def _setup_NFS(mountpoint, server, path, options):
        """Prepare an NFS directory for use as an install source."""
        log.info("mounting %s:%s:%s on %s", server, path, options, mountpoint)
        device_path = payload_utils.get_mount_device_path(mountpoint)

        # test if the mountpoint is occupied already
        if device_path:
            _server, colon, _path = device_path.partition(":")
            if colon == ":" and server == _server and path == _path:
                log.debug("%s:%s already mounted on %s", server, path,
                          mountpoint)
                return
            else:
                log.debug("%s already has something mounted on it", mountpoint)
                payload_utils.unmount(mountpoint)

        # mount the specified directory
        url = "%s:%s" % (server, path)

        if not options:
            options = "nolock"
        elif "nolock" not in options:
            options += ",nolock"

        payload_utils.mount(url, mountpoint, fstype="nfs", options=options)
Example #2
0
    def run(self):
        """Set up the installation source."""
        log.debug("Setting up NFS source: %s", self._url)

        for mount_point in [self._device_mount, self._iso_mount]:
            if os.path.ismount(mount_point):
                raise SourceSetupError("The mount point {} is already in use.".format(
                    mount_point
                ))

        options, host, path = parse_nfs_url(self._url)
        path, image = self._split_iso_from_path(path)
        try:
            self._mount_nfs(host, options, path)
        except PayloadSetupError:
            raise SourceSetupError("Could not mount NFS url '{}'".format(self._url))

        iso_source_path = join_paths(self._device_mount, image) if image else self._device_mount

        iso_name = find_and_mount_iso_image(iso_source_path, self._iso_mount)

        if iso_name:
            log.debug("Using the ISO '%s' mounted at '%s'.", iso_name, self._iso_mount)
            return self._iso_mount

        if verify_valid_repository(self._device_mount):
            log.debug("Using the directory at '%s'.", self._device_mount)
            return self._device_mount

        # nothing found unmount the existing device
        unmount(self._device_mount)
        raise SourceSetupError(
            "Nothing useful found for NFS source at {}".format(self._url))
Example #3
0
    def _setup_device(device, mountpoint):
        """Prepare an install CD/DVD for use as a package source."""
        log.info("setting up device %s and mounting on %s", device.name,
                 mountpoint)
        # Is there a symlink involved?  If so, let's get the actual path.
        # This is to catch /run/install/isodir vs. /mnt/install/isodir, for
        # instance.
        real_mountpoint = os.path.realpath(mountpoint)
        mount_device_path = payload_utils.get_mount_device_path(
            real_mountpoint)

        if mount_device_path:
            log.warning("%s is already mounted on %s", mount_device_path,
                        mountpoint)

            if mount_device_path == device.path:
                return
            else:
                payload_utils.unmount(real_mountpoint)

        try:
            payload_utils.setup_device(device)
            payload_utils.mount_device(device, mountpoint)
        except StorageError as e:
            log.error("mount failed: %s", e)
            payload_utils.teardown_device(device)
            raise PayloadSetupError(str(e))
Example #4
0
    def reset_install_device(self):
        """Unmount the previous base repo and reset the install_device."""
        # cdrom: install_device.teardown (INSTALL_TREE)
        # hd: umount INSTALL_TREE, install_device.teardown (ISO_DIR)
        # nfs: umount INSTALL_TREE
        # nfsiso: umount INSTALL_TREE, umount ISO_DIR
        if os.path.ismount(INSTALL_TREE):
            if self.install_device and \
               payload_utils.get_mount_device(INSTALL_TREE) == self.install_device.path:
                self.install_device.teardown(recursive=True)
            else:
                payload_utils.unmount(INSTALL_TREE, raise_exc=True)

        if os.path.ismount(ISO_DIR):
            if self.install_device and \
               payload_utils.get_mount_device(ISO_DIR) == self.install_device.path:
                self.install_device.teardown(recursive=True)
            # The below code will fail when nfsiso is the stage2 source
            # But if we don't do this we may not be able to switch from
            # one nfsiso repo to another nfsiso repo.  We need to have a
            # way to detect the stage2 state and work around it.
            # Commenting out the below is a hack for F18.  FIXME
            # else:
            #     # NFS
            #     blivet.util.umount(ISO_DIR)

        self.install_device = None
Example #5
0
    def _setup_device(device, mountpoint):
        """Prepare an install CD/DVD for use as a package source."""
        log.info("setting up device %s and mounting on %s", device.name, mountpoint)
        # Is there a symlink involved?  If so, let's get the actual path.
        # This is to catch /run/install/isodir vs. /mnt/install/isodir, for
        # instance.
        real_mountpoint = os.path.realpath(mountpoint)

        mdev = payload_utils.get_mount_device(real_mountpoint)
        if mdev:
            if mdev:
                log.warning("%s is already mounted on %s", mdev, mountpoint)

            if mdev == device.path:
                return
            else:
                payload_utils.unmount(real_mountpoint)

        try:
            device.setup()
            device.format.setup(mountpoint=mountpoint)
        except StorageError as e:
            log.error("mount failed: %s", e)
            device.teardown(recursive=True)
            raise PayloadSetupError(str(e))
Example #6
0
    def reset_install_device(self):
        """Unmount the previous base repo and reset the install_device."""
        # cdrom: install_device.teardown (INSTALL_TREE)
        # hd: umount INSTALL_TREE, install_device.teardown (ISO_DIR)
        # nfs: umount INSTALL_TREE
        # nfsiso: umount INSTALL_TREE, umount ISO_DIR
        if os.path.ismount(INSTALL_TREE):
            if self.install_device and \
               payload_utils.get_mount_device_path(INSTALL_TREE) == self.install_device.path:
                payload_utils.teardown_device(self.install_device)
            else:
                payload_utils.unmount(INSTALL_TREE, raise_exc=True)

        if os.path.ismount(ISO_DIR):
            if self.install_device and \
               payload_utils.get_mount_device_path(ISO_DIR) == self.install_device.path:
                payload_utils.teardown_device(self.install_device)
            # The below code will fail when nfsiso is the stage2 source
            # But if we don't do this we may not be able to switch from
            # one nfsiso repo to another nfsiso repo.  We need to have a
            # way to detect the stage2 state and work around it.
            # Commenting out the below is a hack for F18.  FIXME
            # else:
            #     # NFS
            #     blivet.util.umount(ISO_DIR)

        self.install_device = None
Example #7
0
    def _do_mount(self):
        """Run CD-ROM installation source setup."""
        log.debug("Trying to detect CD-ROM automatically")

        device_tree = STORAGE.get_proxy(DEVICE_TREE)
        device_name = ""

        for dev_name in device_tree.FindOpticalMedia():
            try:
                device_data = DeviceData.from_structure(
                    device_tree.GetDeviceData(dev_name))
                mount(device_data.path, self._target_mount, "iso9660", "ro")
            except PayloadSetupError:
                continue

            if is_valid_install_disk(self._target_mount):
                device_name = dev_name
                log.info("using CD-ROM device %s mounted at %s", dev_name,
                         self._target_mount)
                break
            else:
                unmount(self._target_mount)

        if not device_name:
            raise SourceSetupError("Found no CD-ROM")
Example #8
0
    def post_install(self):
        """ Perform post-installation tasks. """
        progressQ.send_message(_("Performing post-installation setup tasks"))
        payload_utils.unmount(INSTALL_TREE, raise_exc=True)

        super().post_install()

        # Not using BLS configuration, skip it
        if os.path.exists(conf.target.system_root +
                          "/usr/sbin/new-kernel-pkg"):
            return

        # Remove any existing BLS entries, they will not match the new system's
        # machine-id or /boot mountpoint.
        for file in glob.glob(conf.target.system_root +
                              "/boot/loader/entries/*.conf"):
            log.info("Removing old BLS entry: %s", file)
            os.unlink(file)

        # Create new BLS entries for this system
        for kernel in self.kernel_version_list:
            log.info("Regenerating BLS info for %s", kernel)
            util.execInSysroot(
                "kernel-install",
                ["add", kernel, "/lib/modules/{0}/vmlinuz".format(kernel)])
Example #9
0
    def run(self):
        """Set up the installation source."""
        log.debug("Setting up NFS source: %s", self._url)

        for mount_point in [self._device_mount, self._iso_mount]:
            if os.path.ismount(mount_point):
                raise SourceSetupError(
                    "The mount point {} is already in use.".format(
                        mount_point))

        try:
            self._mount_nfs()
        except PayloadSetupError:
            raise SourceSetupError("Could not mount NFS url '{}'".format(
                self._url))

        iso_name = find_and_mount_iso_image(self._device_mount,
                                            self._iso_mount)

        if iso_name:
            log.debug("Using the ISO '%s' mounted at '%s'.", iso_name,
                      self._iso_mount)
            return self._iso_mount

        if verify_valid_installtree(self._device_mount):
            log.debug("Using the directory at '%s'.", self._device_mount)
            return self._device_mount

        # nothing found unmount the existing device
        unmount(self._device_mount)
        raise SourceSetupError(
            "Nothing useful found for NFS source at {}".format(self._url))
Example #10
0
    def unsetup(self):
        super().unsetup()

        for mount in reversed(self._internal_mounts):
            try:
                payload_utils.unmount(mount)
            except CalledProcessError as e:
                log.debug("unmounting %s failed: %s", mount, str(e))
Example #11
0
 def _unmount_source_directory(self, mount_point):
     if os.path.ismount(mount_point):
         device_path = payload_utils.get_mount_device(mount_point)
         device = self.storage.devicetree.get_device_by_path(device_path)
         if device:
             device.teardown(recursive=True)
         else:
             payload_utils.unmount(mount_point, raise_exc=True)
Example #12
0
    def unsetup(self):
        super().unsetup()

        for mount in reversed(self._internal_mounts):
            try:
                payload_utils.unmount(mount)
            except CalledProcessError as e:
                log.debug("unmounting %s failed: %s", mount, str(e))
Example #13
0
 def _unmount_source_directory(self, mount_point):
     if os.path.ismount(mount_point):
         device_path = payload_utils.get_mount_device_path(mount_point)
         device = payload_utils.resolve_device(self.storage, device_path)
         if device:
             payload_utils.teardown_device(device)
         else:
             payload_utils.unmount(mount_point, raise_exc=True)
Example #14
0
 def _unmount_source_directory(self, mount_point):
     if os.path.ismount(mount_point):
         device_path = payload_utils.get_mount_device(mount_point)
         device = self.storage.devicetree.get_device_by_path(device_path)
         if device:
             device.teardown(recursive=True)
         else:
             payload_utils.unmount(mount_point, raise_exc=True)
Example #15
0
    def unsetup(self):
        """Invalidate a previously setup payload."""
        super().unsetup()

        for mount in reversed(self._internal_mounts):
            try:
                payload_utils.unmount(mount)
            except CalledProcessError as e:
                log.debug("unmounting %s failed: %s", mount, str(e))

        tear_down_sources(self.proxy)
Example #16
0
    def post_install(self):
        """ Unmount and remove image

            If file:// was used, just unmount it.
        """
        super().post_install()

        if os.path.exists(IMAGE_DIR + "/LiveOS"):
            payload_utils.unmount(IMAGE_DIR, raise_exc=True)
            os.rmdir(IMAGE_DIR)

        if os.path.exists(self.image_path) and not self.data.liveimg.url.startswith("file://"):
            os.unlink(self.image_path)
Example #17
0
    def run(self):
        """Run tear down of installation source image."""
        if not url_target_is_tarfile(self._url):
            unmount(self._image_mount_point, raise_exc=True)
            # FIXME: Payload and LiveOS stuff
            # FIXME: do we need a task for this?
            if os.path.exists(IMAGE_DIR + "/LiveOS"):
                # FIXME: catch and pass the exception
                unmount(IMAGE_DIR, raise_exc=True)
                os.rmdir(IMAGE_DIR)

        if not get_local_image_path_from_url(self._url):
            if os.path.exists(self._image_path):
                os.unlink(self._image_path)
Example #18
0
    def run(self):
        """Run Hard drive installation source setup.

        Always sets up two mount points: First for the device, and second for the ISO image or a
        bind for unpacked ISO. These depend on each other, and must be destroyed in the correct
        order again.

        :raise: SourceSetupError
        :return: named tuple with path to the install tree and name of ISO if set or empty string
        :rtype: SetupHardDriveResult instance
        """
        log.debug("Setting up Hard drive source")

        for mount_point in [self._device_mount, self._iso_mount]:
            if os.path.ismount(mount_point):
                raise SourceSetupError(
                    "The mount point {} is already in use.".format(
                        mount_point))

        if not find_and_mount_device(self._partition, self._device_mount):
            raise SourceSetupError(
                "Could not mount device specified as {}".format(
                    self._partition))

        full_path_on_mounted_device = os.path.normpath("{}/{}".format(
            self._device_mount, self._directory))

        iso_name = find_and_mount_iso_image(full_path_on_mounted_device,
                                            self._iso_mount)

        if iso_name:
            log.debug("Using the ISO '%s' mounted at '%s'.", iso_name,
                      self._iso_mount)
            return SetupHardDriveResult(self._iso_mount, iso_name)

        if verify_valid_repository(full_path_on_mounted_device):
            log.debug("Using the directory at '%s'.",
                      full_path_on_mounted_device)
            return SetupHardDriveResult(full_path_on_mounted_device, "")

        # nothing found unmount the existing device
        unmount(self._device_mount)
        raise SourceSetupError(
            "Nothing useful found for Hard drive ISO source at partition={} directory={}"
            .format(self._partition, self._directory))
Example #19
0
    def post_install(self):
        """ Perform post-installation tasks. """
        progressQ.send_message(_("Performing post-installation setup tasks"))
        payload_utils.unmount(INSTALL_TREE, raise_exc=True)

        super().post_install()

        # Not using BLS configuration, skip it
        if os.path.exists(conf.target.system_root +
                          "/usr/sbin/new-kernel-pkg"):
            return

        # Remove any existing BLS entries, they will not match the new system's
        # machine-id or /boot mountpoint.
        for file in glob.glob(conf.target.system_root +
                              "/boot/loader/entries/*.conf"):
            log.info("Removing old BLS entry: %s", file)
            os.unlink(file)

        # Create new BLS entries for this system
        for kernel in self.kernel_version_list:
            log.info("Regenerating BLS info for %s", kernel)
            util.execInSysroot(
                "kernel-install",
                ["add", kernel, "/lib/modules/{0}/vmlinuz".format(kernel)])

        # Update the bootloader configuration to make sure that the BLS
        # entries will have the correct kernel cmdline and not the value
        # taken from /proc/cmdline, that is used to boot the live image.
        bootloader = STORAGE.get_proxy(BOOTLOADER)
        if bootloader.IsEFI():
            grub_cfg_path = "/etc/grub2-efi.cfg"
        else:
            grub_cfg_path = "/etc/grub2.cfg"

        # TODO: add a method to the bootloader interface that updates the
        # configuration and avoid having bootloader specific logic here.
        rc = util.execInSysroot("grub2-mkconfig", ["-o", grub_cfg_path])
        if rc:
            raise BootloaderInstallationError(
                "failed to write boot loader configuration")
Example #20
0
    def _choose_installation_device(self, device_tree, devices_candidates):
        device_name = ""

        for dev_name in devices_candidates:
            try:
                device_data = DeviceData.from_structure(
                    device_tree.GetDeviceData(dev_name))
                mount(device_data.path, self._target_mount, "iso9660", "ro")
            except OSError as e:
                log.debug("Failed to mount %s: %s", dev_name, str(e))
                continue

            if is_valid_install_disk(self._target_mount):
                device_name = dev_name
                log.info("using CD-ROM device %s mounted at %s", dev_name,
                         self._target_mount)
                break
            else:
                unmount(self._target_mount)

        return device_name
Example #21
0
    def _setup_NFS(mountpoint, server, path, options):
        """Prepare an NFS directory for use as an install source."""
        log.info("mounting %s:%s:%s on %s", server, path, options, mountpoint)
        dev = payload_utils.get_mount_device(mountpoint)

        # test if the mountpoint is occupied already
        if dev:
            _server, colon, _path = dev.partition(":")
            if colon == ":" and server == _server and path == _path:
                log.debug("%s:%s already mounted on %s", server, path, mountpoint)
                return
            else:
                log.debug("%s already has something mounted on it", mountpoint)
                payload_utils.unmount(mountpoint)

        # mount the specified directory
        url = "%s:%s" % (server, path)

        if not options:
            options = "nolock"
        elif "nolock" not in options:
            options += ",nolock"

        payload_utils.mount(url, mountpoint, fstype="nfs", options=options)
Example #22
0
 def run(self):
     """Tear down the installation source."""
     log.debug("Unmounting NFS installation source")
     unmount(self._target_mount)
Example #23
0
    def post_install(self):
        """ Perform post-installation tasks. """
        progressQ.send_message(_("Performing post-installation setup tasks"))
        payload_utils.unmount(INSTALL_TREE, raise_exc=True)

        super().post_install()
Example #24
0
 def _do_unmount(self):
     """Unmount the source."""
     unmount(self._target_mount)
Example #25
0
 def run(self):
     """Run live installation source unsetup."""
     unmount(self._target_mount)
Example #26
0
 def run(self):
     """Run source un-setup."""
     log.debug("Unmounting installation source")
     unmount(self._target_mount)
Example #27
0
 def run(self):
     """Tear down the installation source."""
     unmount(self._target_mount)
Example #28
0
    def unsetup(self):
        super().unsetup()

        # Unmount a previously mounted live tree
        payload_utils.unmount(INSTALL_TREE)