예제 #1
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
예제 #2
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
예제 #3
0
 def mount_volumes(self, print_progress=False):
     """ Mount the /etc/fstab and device volumes into the chroot root dir """
     self.debug_action(action="MOUNT ALL VOLUMES")
     # Mount the root volume
     debug("Collect the ordered mount options")
     ordered_mount_opts = self.get_ordered_mount_opts()  # unmounts root
     debug(f"Mounting root volume {self.root_volume} to {self.ROOT_MOUNT}")
     mount(self.root_volume, self.ROOT_MOUNT)
     if print_progress:
         print(f"mount {self.root_volume} {self.ROOT_MOUNT}")
     # Mount the other volumes
     for mount_opts in ordered_mount_opts:
         if mount_opts["mnt_to"] == self.ROOT_MOUNT:
             continue
         if print_progress:
             bind = "--bind" if mount_opts["bind"] else ""
             print(
                 f"mount {mount_opts['mnt_from']} {mount_opts['mnt_to']} {bind}"
             )
         mount(mount_opts["mnt_from"],
               mount_opts["mnt_to"],
               bind=mount_opts["bind"])
     self.debug_action(end=True)
예제 #4
0
 def mount_root(self):
     """ Mount the root device if it isn't mounted """
     mount(self.root_volume, self.ROOT_MOUNT)