def _get_target_offset(self): if self.target_table_type == 'dasd': blocks = self._read_dasd_disk_geometry('blocks per track') bash_command = [ 'fdasd', '-f', '-s', '-p', self.target_device, '|', 'head', '-n', '1', '|', 'tr', '-s', '" "' ] fdasd_call = Command.run( ['bash', '-c', ' '.join(bash_command)] ) fdasd_output = fdasd_call.output try: start_track = int(fdasd_output.split(' ')[2].lstrip()) except Exception: raise KiwiDiskGeometryError( 'unknown partition format: %s' % fdasd_output ) return start_track * blocks else: blocks = self._read_msdos_disk_geometry('blocks per track') parted_call = Command.run( ['parted', '-m', self.target_device, 'unit', 's', 'print'] ) parted_output = parted_call.output.lstrip() first_partition_format = re.search('1:(.*?)s', parted_output) if not first_partition_format: raise KiwiDiskGeometryError( 'unknown partition format: %s' % parted_output ) start_track = int(first_partition_format.group(1)) return start_track * blocks
def _read_dasd_disk_geometry(self, value): fdasd = ['fdasd', '-f', '-p', self.target_device] bash_command = fdasd + ['|', 'grep', '"' + value + '"'] fdasd_call = Command.run(['bash', '-c', ' '.join(bash_command)]) fdasd_output = fdasd_call.output try: return int(fdasd_output.split(':')[1].lstrip()) except Exception: raise KiwiDiskGeometryError( 'unknown format for disk geometry: %s' % fdasd_output)
def _read_msdos_disk_geometry(self, value): sfdisk_call = Command.run(['sfdisk', '-g', self.target_device]) sfdisk_output = sfdisk_call.output.lstrip() geometry_format = re.search( '/dev.*: (.*) cylinders, (.*) heads, (.*) sectors/track', sfdisk_output) if not geometry_format: raise KiwiDiskGeometryError('unknown format for geometry: %s' % sfdisk_output) result = { 'cylinders': geometry_format.group(1), 'tracks per cylinder': geometry_format.group(2), 'blocks per track': geometry_format.group(3) } if value in result: return int(result[value])