Ejemplo n.º 1
0
 def unmount_volumes(self, prompt=False, print_progress=False):
     """ Unmount the /etc/fstab and device volumes from the chroot root dir """
     self.debug_action(action="UNMOUNT ALL VOLUMES")
     for mount_opts in self.get_ordered_mount_opts(reverse=True):
         debug(f"Unmount: {mount_opts['mnt_to']}")
         if print_progress:
             print(f"umount {mount_opts['mnt_to']}")
         unmount(mount_opts["mnt_to"], prompt=prompt, fail=prompt)
     self.debug_action(end=True)
Ejemplo n.º 2
0
 def has_run_dir(self):
     """ Return bool does this system have a /run dir? Old OS's like RHEL 6 sometimes do not """
     if self._has_run_dir != None:
         return self._has_run_dir
     try:
         if not self.was_root_vol_mounted:
             mount(self.root_volume, self.ROOT_MOUNT)
         self._has_run_dir = Path(f"{self.ROOT_MOUNT}/run").exists()
     finally:
         if not self.was_root_vol_mounted:
             unmount(self.ROOT_MOUNT)
     return self._has_run_dir
Ejemplo n.º 3
0
 def root_volume(self):
     """ Return the path to the volume: the volume that contains /etc/fstab """
     if self._root_volume:
         # self._root_volume can be set here or during __init__()
         return self._root_volume
     self.debug_action(action="FIND ROOT VOLUME")
     fstab_path = f"{self.ROOT_MOUNT}/etc/fstab"
     if is_mounted(self.ROOT_MOUNT):
         # something's already mounted to ROOT_MOUNT, validate it
         fstab_contents = get_file_contents(fstab_path)
         if not fstab_contents:
             error("ERROR: Mounted root volume has no /etc/fstab",
                   exit=True)
         device = get_mount(self.ROOT_MOUNT)["device"]
         self._root_volume = device
         debug(device)
         self.debug_action(end=True)
         return device
     if self.devices is None:
         error(
             f"ERROR: Failed to find root partition - no devices specified",
             exit=True)
     _root_volume = None
     # root volume wasn't mounted, mount each data volume until you find /etc/fstab
     for vol_path in self.data_volumes:
         debug(f"Checking for /etc/fstab in {vol_path}")
         try:
             mount(vol_path, self.ROOT_MOUNT)
             if get_file_contents(fstab_path):
                 self._root_volume = vol_path
                 unmount(self.ROOT_MOUNT)
                 _root_volume = vol_path
                 break
         finally:
             unmount(self.ROOT_MOUNT)
     debug(f"> root volume =  {_root_volume}")
     self.debug_action(end=True)
     if _root_volume is None:
         error(
             f"ERROR: Failed to find a root volume on devices: {self.devices}",
             exit=True)
     self._root_volume = _root_volume
     return _root_volume
Ejemplo n.º 4
0
 def unmount_root(self):
     """ Unmount the root device """
     unmount(self.ROOT_MOUNT, fail=False)