def run(self): """Run the task.""" mount_existing_system( storage=self._storage, root_device=self._device, read_only=self._read_only )
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 run(self): """Run the task. :raise: MountFilesystemError in case of failure """ try: mount_existing_system(storage=self._storage, root_device=self._device, read_only=self._read_only) except StorageError as e: log.error("Failed to mount the system: %s", e) raise MountFilesystemError(str(e)) from e