def _get_root_cmdline_parameter(self, boot_device): cmdline = self.xml_state.build_type.get_kernelcmdline() persistency_type = self.xml_state.build_type.get_devicepersistency() if cmdline and 'root=' in cmdline: log.info( 'Kernel root device explicitly set via kernelcmdline' ) root_search = re.search(r'(root=(.*)[ ]+|root=(.*)$)', cmdline) if root_search: return root_search.group(1) if boot_device: block_operation = BlockID(boot_device) if persistency_type == 'by-label': blkid_type = 'LABEL' elif persistency_type == 'by-partuuid': blkid_type = 'PARTUUID' else: blkid_type = 'UUID' location = block_operation.get_blkid(blkid_type) if self.xml_state.build_type.get_overlayroot(): return f'root=overlay:{blkid_type}={location}' else: return f'root={blkid_type}={location}' else: log.warning( 'No explicit root= cmdline provided' )
def get_fstab(self, persistency_type='by-label', filesystem_name=None): """ Implements creation of the fstab entries. The method returns a list of fstab compatible entries :param string persistency_type: by-label | by-uuid :param string filesystem_name: unused :return: list of fstab entries :rtype: list """ fstab_entries = [] mount_options = \ self.custom_filesystem_args['mount_options'] or ['defaults'] block_operation = BlockID(self.device) blkid_type = 'LABEL' if persistency_type == 'by-label' else 'UUID' device_id = block_operation.get_blkid(blkid_type) for volume_mount in self.subvol_mount_list: subvol_name = self._get_subvol_name_from_mountpoint(volume_mount) mount_entry_options = mount_options + ['subvol=' + subvol_name] fs_check = self._is_volume_enabled_for_fs_check( volume_mount.mountpoint) fstab_entry = ' '.join([ blkid_type + '=' + device_id, subvol_name.replace('@', ''), 'btrfs', ','.join(mount_entry_options), '0 {fs_passno}'.format(fs_passno='2' if fs_check else '0') ]) fstab_entries.append(fstab_entry) return fstab_entries
def _preserve_root_filesystem_uuid(self, device_map): block_operation = BlockID( device_map['root'].get_device() ) rootfs_uuid = block_operation.get_blkid('UUID') if rootfs_uuid: self.xml_state.set_root_filesystem_uuid( rootfs_uuid )
def _preserve_root_partition_uuid(self, device_map): block_operation = BlockID( device_map['root'].get_device() ) partition_uuid = block_operation.get_blkid('PARTUUID') if partition_uuid: self.xml_state.set_root_partition_uuid( partition_uuid )
def _add_generic_fstab_entry(self, device, mount_point, options=None, check='0 0'): if not options: options = ['defaults'] block_operation = BlockID(device) blkid_type = 'LABEL' if self.persistency_type == 'by-label' else 'UUID' device_id = block_operation.get_blkid(blkid_type) fstab_entry = ' '.join([ blkid_type + '=' + device_id, mount_point, block_operation.get_filesystem(), ','.join(options), check ]) self.fstab.add_entry(fstab_entry)
def get_block_storage_filesystem(self) -> str: """ Retrieve filesystem type from image_filepath. The method only returns a value if image_filepath at construction time of the VeritySetup object is a block device containing a filesystem :rtype: blkid TYPE value or empty string :return: str """ try: return BlockID(self.image_filepath).get_filesystem() except Exception: return ''
def _add_fstab_entry(self, device: str, mount_point: str, options: List = None, check: str = '0 0') -> None: if not options: options = ['defaults'] block_operation = BlockID(device) if self.volume_manager_name and self.volume_manager_name == 'lvm' \ and (mount_point == '/' or mount_point == 'swap'): fstab_entry = ' '.join([ device, mount_point, block_operation.get_filesystem(), ','.join(options), check ]) else: blkid_type = 'LABEL' if self.persistency_type == 'by-label' \ else 'UUID' device_id = block_operation.get_blkid(blkid_type) fstab_entry = ' '.join([ blkid_type + '=' + device_id, mount_point, block_operation.get_filesystem(), ','.join(options), check ]) self.fstab.add_entry(fstab_entry)
def setup(self): self.blkid = BlockID('device')
def test_setup_with_uuid_format(self, mock_command): BlockID('UUID=uuid') mock_command.assert_called_once_with( ['blkid', '--uuid', 'uuid'] )
def set_device(self, device): self._state.set_root_partition_uuid(uuid=BlockID(device=device).get_blkid('PARTUUID')) self._device = device return True