def __init__(self, state_name, context): super(OSEncryptionState, self).__init__() self.state_name = state_name self.context = context self.state_executed = False self.state_marker = os.path.join( self.context.encryption_environment.os_encryption_markers_path, self.state_name) self.command_executor = CommandExecutor(self.context.logger) self.disk_util = DiskUtil( hutil=self.context.hutil, patching=self.context.distro_patcher, logger=self.context.logger, encryption_environment=self.context.encryption_environment) self.bek_util = BekUtil(disk_util=self.disk_util, logger=self.context.logger) self.encryption_config = EncryptionConfig( encryption_environment=self.context.encryption_environment, logger=self.context.logger) rootfs_mountpoint = '/' if self.command_executor.Execute('mountpoint /oldroot') == 0: rootfs_mountpoint = '/oldroot' rootfs_sdx_path = self._get_fs_partition(rootfs_mountpoint)[0] self.context.logger.log("rootfs_sdx_path: {0}".format(rootfs_sdx_path)) self.rootfs_block_device = self.disk_util.query_dev_id_path_by_sdx_path( rootfs_sdx_path) if not self.rootfs_block_device.startswith('/dev'): distro_name = self.context.distro_patcher.distro_info[0] self.rootfs_block_device = '/dev/sda1' if distro_name == 'Ubuntu' else '/dev/sda2' self.context.logger.log("rootfs_block_device: {0}".format( self.rootfs_block_device))
def __init__(self, state_name, context): super(OSEncryptionState, self).__init__() self.state_name = state_name self.context = context self.state_executed = False self.state_marker = os.path.join( self.context.encryption_environment.os_encryption_markers_path, self.state_name) self.command_executor = CommandExecutor(self.context.logger) self.disk_util = DiskUtil( hutil=self.context.hutil, patching=self.context.distro_patcher, logger=self.context.logger, encryption_environment=self.context.encryption_environment) self.bek_util = BekUtil(disk_util=self.disk_util, logger=self.context.logger) self.encryption_config = EncryptionConfig( encryption_environment=self.context.encryption_environment, logger=self.context.logger) rootfs_mountpoint = '/' if self._is_in_memfs_root(): rootfs_mountpoint = '/oldroot' self.rootfs_sdx_path = self._get_fs_partition(rootfs_mountpoint)[0] if self.rootfs_sdx_path == "none": self.context.logger.log( "self.rootfs_sdx_path is none, parsing UUID from fstab") self.rootfs_sdx_path = self._parse_uuid_from_fstab('/') self.context.logger.log("rootfs_uuid: {0}".format( self.rootfs_sdx_path)) if self.rootfs_sdx_path and ( self.rootfs_sdx_path.startswith("/dev/disk/by-uuid/") or self._is_uuid(self.rootfs_sdx_path)): self.rootfs_sdx_path = self.disk_util.query_dev_sdx_path_by_uuid( self.rootfs_sdx_path) self.context.logger.log("self.rootfs_sdx_path: {0}".format( self.rootfs_sdx_path)) self.rootfs_disk = None self.rootfs_block_device = None self.bootfs_block_device = None if self.disk_util.is_os_disk_lvm(): proc_comm = ProcessCommunicator() self.command_executor.Execute('pvs', True, communicator=proc_comm) for line in proc_comm.stdout.split("\n"): if "rootvg" in line: self.rootfs_block_device = line.strip().split()[0] self.rootfs_disk = self.rootfs_block_device[:-1] self.bootfs_block_device = self.rootfs_disk + '2' elif not self.rootfs_sdx_path: self.rootfs_disk = '/dev/sda' self.rootfs_block_device = '/dev/sda2' self.bootfs_block_device = '/dev/sda1' elif self.rootfs_sdx_path == '/dev/mapper/osencrypt' or self.rootfs_sdx_path.startswith( '/dev/dm-'): self.rootfs_block_device = '/dev/mapper/osencrypt' bootfs_uuid = self._parse_uuid_from_fstab('/boot') self.context.logger.log("bootfs_uuid: {0}".format(bootfs_uuid)) self.bootfs_block_device = self.disk_util.query_dev_sdx_path_by_uuid( bootfs_uuid) else: self.rootfs_block_device = self.disk_util.query_dev_id_path_by_sdx_path( self.rootfs_sdx_path) if not self.rootfs_block_device.startswith('/dev/disk/by-id/'): self.context.logger.log("rootfs_block_device: {0}".format( self.rootfs_block_device)) raise Exception("Could not find rootfs block device") self.rootfs_disk = self.rootfs_block_device[:self. rootfs_block_device. index("-part")] self.bootfs_block_device = self.rootfs_disk + "-part2" if self._get_block_device_size( self.bootfs_block_device) > self._get_block_device_size( self.rootfs_block_device): self.context.logger.log( "Swapping partition identifiers for rootfs and bootfs") self.rootfs_block_device, self.bootfs_block_device = self.bootfs_block_device, self.rootfs_block_device self.context.logger.log("rootfs_disk: {0}".format(self.rootfs_disk)) self.context.logger.log("rootfs_block_device: {0}".format( self.rootfs_block_device)) self.context.logger.log("bootfs_block_device: {0}".format( self.bootfs_block_device))