def expanded_kargs(self): """Expands all macros found in self.kargs and returns the string with all macros expanded. Currently, only $ZFS-BOOTFS is a supported macro.""" if get_current_arch_string() != 'x86': raise BootmgmtUnsupportedPlatformError('expanded_kargs() not ' 'supported on the %s platform' % get_current_arch_string()) if self.kargs is None: return if not "$ZFS-BOOTFS" in self.kargs: return self.kargs # ZFS-BOOTFS expands to a string that contains two elements: # The zfs-bootfs element and the bootpath element. Retrieve # Them both from libzfs here, then perform the substitution. return self.kargs.replace("$ZFS-BOOTFS", self._expand_zfs_bootfs())
def expanded_kargs(self): """Expands all macros found in self.kargs and returns the string with all macros expanded. Currently, only $ZFS-BOOTFS is a supported macro.""" if get_current_arch_string() != 'x86': raise BootmgmtUnsupportedPlatformError( 'expanded_kargs() not ' 'supported on the %s platform' % get_current_arch_string()) if self.kargs is None: return if not "$ZFS-BOOTFS" in self.kargs: return self.kargs # ZFS-BOOTFS expands to a string that contains two elements: # The zfs-bootfs element and the bootpath element. Retrieve # Them both from libzfs here, then perform the substitution. return self.kargs.replace("$ZFS-BOOTFS", self._expand_zfs_bootfs())
def get(sysroot, arch, osname): """Returns an instance of bootinfo.BootVariables corresponding to the architecture and system root passed in.""" if arch is None: arch = bootutil.get_current_arch_string() if osname is None: raise BootmgmtArgumentError('osname cannot be None') bvmod = __name__ + '.' + arch + '.' + osname __import__(bvmod, level=0) ns = sys.modules[bvmod] # bootvars_backend returns the *class* return ns.bootvars_backend()(sysroot)
def probe(cls, **kwargs): """Probe for Legacy GRUB files for use with the BootConfig passed in""" if get_current_arch_string() != 'x86': cls._debug('Legacy GRUB boot loader not supported on this ' 'platform') return (None, None) bootconfig = kwargs.get('bootconfig', None) if (bootconfig is None or bootconfig.boot_class is None): return (None, None) if (bootconfig.boot_class == BootConfig.BOOT_CLASS_DISK and bootconfig.boot_fstype is not None): return LegacyGRUBBootLoader._probe_disk(**kwargs) elif bootconfig.boot_class == BootConfig.BOOT_CLASS_ODD: return LegacyGRUBBootLoader._probe_odd(**kwargs) else: raise BootmgmtUnsupportedOperationError('XXX - Fix Me')
def get(fw_name): """Returns an instance of bootinfo.SystemFirmware corresponding to the firmware name passed in. If fw_name is None, the system firmware type is autodetected and the appropriate child of SystemFirmware is returned """ if fw_name is None: curarch = get_current_arch_string() # If this is a SPARC system, the appropriate class is obp if curarch == 'sparc': from bootmgmt.backend.fw import obp return obp.firmware_backend()('obp') elif curarch == 'x86': # If this is an x86 system and the efi-systype property exists, # then this is a UEFI system and the property value specifies the # bit width. try: efisystype = pysol.di_find_root_prop('efi-systype') except IOError as e: # Problem while trying to get the property # Set efisystype to None to force BIOS efisystype = None if efisystype is None: from bootmgmt.backend.fw import bios return bios.firmware_backend()('bios') else: uefi_string = 'uefi' + efisystype fwmod = __name__ + '.' + uefi_string __import__(fwmod, level=0) ns = sys.modules[fwmod] return ns.firmware_backend()(uefi_string) else: raise BootmgmtUnsupportedPlatformError('Unknown platform ' '"%s"' % curarch) else: fwmod = __name__ + '.' + fw_name __import__(fwmod, level=0) ns = sys.modules[fwmod] return ns.firmware_backend()(fw_name)
def autogen(self, bootconfig): "The workhorse of the autogenerator" # XXX - Handle bootconfig instances that have boot_class != disk if bootconfig.boot_class != BootConfig.BOOT_CLASS_DISK: raise BootmgmtUnsupportedOperationError('XXX - Fix Me') # This is only supported on x86: if get_current_arch_string() != 'x86': self._debug('Chainloader entry autogeneration only supported on ' 'x86') return [] try: helper_cmd = ['/usr/lib/boot/bootmgmt-helper-chain'] script_output = Popen.check_call(helper_cmd, stdout=Popen.STORE, stderr=Popen.STORE) script_stdout = script_output.stdout except OSError as error_exc: self._debug('Executing helper script failed: %s' % error_exc) return [] except CalledProcessError as cpe: self._debug('Helper script returned %d' % cpe.returncode) if cpe.popen and cpe.popen.stdout: self._debug('stdout was: %s\n' % cpe.popen.stdout) if cpe.popen and cpe.popen.stderr: self._debug('stderr was: %s\n' % cpe.popen.stderr) return [] inst_list = [] lineno = 0 for line in script_stdout.splitlines(): lineno += 1 self._debug('Output line %d: "%s"' % (lineno, line)) if line.startswith('#') or line.strip() == '': continue try: title, disk, partition, active = line.split(':') disk = int(disk) # partition can be empty, an int or a comma-separated list of # strings if partition.strip() != '': if partition.find(',') != -1: partition = tuple(partition.split(',')) else: partition = int(partition) else: partition = None active = True if active == 'True' else False except ValueError: self._debug('Malformed output line from helper: "%s"' % line) continue if partition is None: chain_info = (disk,) else: chain_info = (disk, partition) bootinst = ChainDiskBootInstance(None, title=title, chaininfo=chain_info, forceactive=active) inst_list.append(bootinst) self._debug('%d line(s) read from helper script.' % lineno) self._debug('%d boot instances autogenerated.' % len(inst_list)) return inst_list
class SolarisBootInstance(BootInstance): """Abstraction for a Solaris Boot Instance. Supported attributes are: - kernel [string] [optional] [x86-only] - boot_archive [string] [optional] [x86-only] - kargs [string] [optional] [x86-only]: Kernel argument string - signature [string] [optional] [x86-only]: The "boot signature" of this boot instance. - Public Methods: - expanded_kargs(): [x86-only] Expands all macros in kargs and returns the expanded kernel argument string. """ if get_current_arch_string() == 'x86': _attributes = { 'kernel': '/platform/i86pc/kernel/amd64/unix', 'boot_archive': '/platform/i86pc/amd64/boot_archive', 'kargs': None, 'signature': None, 'splashimage': None, 'foreground': None, 'background': None } else: _attributes = {} def __init__(self, rootpath, **kwargs): # If the child class added its own set of attributes, just append to # it; overwise, set it to the default set from this class (self.__dict__.setdefault('_attributes', {}).update(SolarisBootInstance._attributes)) super(SolarisBootInstance, self).__init__(rootpath, **kwargs) def expanded_kargs(self): """Expands all macros found in self.kargs and returns the string with all macros expanded. Currently, only $ZFS-BOOTFS is a supported macro.""" if get_current_arch_string() != 'x86': raise BootmgmtUnsupportedPlatformError( 'expanded_kargs() not ' 'supported on the %s platform' % get_current_arch_string()) if self.kargs is None: return if not "$ZFS-BOOTFS" in self.kargs: return self.kargs # ZFS-BOOTFS expands to a string that contains two elements: # The zfs-bootfs element and the bootpath element. Retrieve # Them both from libzfs here, then perform the substitution. return self.kargs.replace("$ZFS-BOOTFS", self._expand_zfs_bootfs()) def _expand_zfs_bootfs(self): """Use libzfs (via ctypes) to get the zpool properties and return a string that consists of the kernel arguments needed to specify the zfs root pool and bootfs associated with this BootInstance """ lzfsh = libzfs_init() if getattr(self, 'bootfs', None) is not None: zph = zpool_open(lzfsh, self.bootfs.split('/')[0]) elif getattr(self, 'rpool', None) is not None: zph = zpool_open(lzfsh, self.rpool) else: libzfs_fini(lzfsh) self._debug('bootfs AND rpool not set in instance') return '' physpaths = zpool_get_physpath(lzfsh, zph) if self.bootfs is None: bootfs = zpool_get_prop(lzfsh, zph, ZPOOL_PROP_BOOTFS) else: bootfs = self.bootfs zpool_close(zph) libzfs_fini(lzfsh) # XXX: We're just using the first physpath for now return ('zfs-bootfs=' + bootfs + ',bootpath="' + physpaths[0] + '"')
def probe_generic(**kwargs): """Generic probe checks for OBP boot loaders""" if get_current_arch_string() != 'sparc': raise BootmgmtUnsupportedPlatformError('SPARC-only')