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, 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 == payload_utils.get_device_path(device): return else: payload_utils.unmount(real_mountpoint) try: payload_utils.setup_device(device) payload_utils.mount_device(device, mountpoint) except (DeviceSetupError, MountFilesystemError) as e: log.error("mount failed: %s", e) payload_utils.teardown_device(device) raise PayloadSetupError(str(e)) from e
def setup(self): super().setup() # Mount the live device and copy from it instead of the overlay at / osimg = payload_utils.resolve_device(self.data.method.partition) if not osimg: raise PayloadInstallError("Unable to find osimg for %s" % self.data.method.partition) osimg_path = payload_utils.get_device_path(osimg) if not stat.S_ISBLK(os.stat(osimg_path)[stat.ST_MODE]): exn = PayloadSetupError("%s is not a valid block device" % (self.data.method.partition, )) if errorHandler.cb(exn) == ERROR_RAISE: raise exn rc = payload_utils.mount(osimg_path, INSTALL_TREE, fstype="auto", options="ro") if rc != 0: raise PayloadInstallError("Failed to mount the install tree") # Grab the kernel version list now so it's available after umount self._update_kernel_version_list() source = os.statvfs(INSTALL_TREE) self.source_size = source.f_frsize * (source.f_blocks - source.f_bfree)
def run(self, device_name): retval = None device_path = payload_utils.get_device_path(device_name) # FIXME: Use a unique mount point. mounts = payload_utils.get_mount_paths(device_path) mountpoint = None # We have to check both ISO_DIR and the DRACUT_ISODIR because we # still reference both, even though /mnt/install is a symlink to # /run/install. Finding mount points doesn't handle the symlink if constants.ISO_DIR not in mounts and constants.DRACUT_ISODIR not in mounts: # We're not mounted to either location, so do the mount mountpoint = constants.ISO_DIR payload_utils.mount_device(device_name, mountpoint) # If any directory was chosen, return that. Otherwise, return None. rc = self.window.run() if rc == Gtk.ResponseType.OK: f = self._chooser.get_filename() if f: retval = f.replace(constants.ISO_DIR, "") if not mounts: payload_utils.unmount_device(device_name, mountpoint) self.window.destroy() return retval
def setup(self): super().setup() # Mount the live device and copy from it instead of the overlay at / osimg_spec = self._get_live_os_image() if not osimg_spec: raise PayloadSetupError("No live image found!") osimg = payload_utils.resolve_device(osimg_spec) if not osimg: raise PayloadSetupError( "Unable to find osimg for {}".format(osimg_spec)) osimg_path = payload_utils.get_device_path(osimg) if not stat.S_ISBLK(os.stat(osimg_path)[stat.ST_MODE]): raise PayloadSetupError( "{} is not a valid block device".format(osimg_spec)) rc = payload_utils.mount(osimg_path, INSTALL_TREE, fstype="auto", options="ro") if rc != 0: raise PayloadSetupError("Failed to mount the install tree") # Grab the kernel version list now so it's available after umount self._update_kernel_version_list()
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 install_device_path = payload_utils.get_device_path( self.install_device) if os.path.ismount(INSTALL_TREE): if self.install_device and \ payload_utils.get_mount_device_path(INSTALL_TREE) == 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) == 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
def _mount_device(self): """ Mount the device so we can search it for ISOs. """ # FIXME: Use a unique mount point. device_path = get_device_path(self._device) mounts = payload_utils.get_mount_paths(device_path) # We have to check both ISO_DIR and the DRACUT_ISODIR because we # still reference both, even though /mnt/install is a symlink to # /run/install. Finding mount points doesn't handle the symlink if ISO_DIR not in mounts and DRACUT_ISODIR not in mounts: # We're not mounted to either location, so do the mount payload_utils.mount_device(self._device, ISO_DIR)
def _device_is_mounted_as_source(self, device): device_path = payload_utils.get_device_path(device) device_mounts = payload_utils.get_mount_paths(device_path) return INSTALL_TREE in device_mounts or DRACUT_REPODIR in device_mounts