예제 #1
0
def uefi_reorder_loaders(grubcfg, target):
    """Reorders the UEFI BootOrder to place BootCurrent first.

    The specifically doesn't try to do to much. The order in which grub places
    a new EFI loader is up to grub. This only moves the BootCurrent to the
    front of the BootOrder.
    """
    if grubcfg.get('reorder_uefi', True):
        efi_output = util.get_efibootmgr(target)
        currently_booted = efi_output.get('current', None)
        boot_order = efi_output.get('order', [])
        if currently_booted:
            if currently_booted in boot_order:
                boot_order.remove(currently_booted)
            boot_order = [currently_booted] + boot_order
            new_boot_order = ','.join(boot_order)
            LOG.debug(
                "Setting currently booted %s as the first "
                "UEFI loader.", currently_booted)
            LOG.debug("New UEFI boot order: %s", new_boot_order)
            with util.ChrootableTarget(target) as in_chroot:
                in_chroot.subp(['efibootmgr', '-o', new_boot_order])
    else:
        LOG.debug("Skipped reordering of UEFI boot methods.")
        LOG.debug("Currently booted UEFI loader might no longer boot.")
예제 #2
0
def uefi_remove_old_loaders(grubcfg, target):
    """Removes the old UEFI loaders from efibootmgr."""
    efi_output = util.get_efibootmgr(target)
    current_uefi_boot = efi_output.get('current', None)
    old_efi_entries = {
        entry: info
        for entry, info in efi_output['entries'].items()
        if re.match(r'^.*File\(\\EFI.*$', info['path'])
    }
    old_efi_entries.pop(current_uefi_boot, None)
    remove_old_loaders = grubcfg.get('remove_old_uefi_loaders', True)
    if old_efi_entries:
        if remove_old_loaders:
            with util.ChrootableTarget(target) as in_chroot:
                for entry, info in old_efi_entries.items():
                    LOG.debug("removing old UEFI entry: %s" % info['name'])
                    in_chroot.subp(['efibootmgr', '-B', '-b', entry],
                                   capture=True)
        else:
            LOG.debug("Skipped removing %d old UEFI entrie%s.",
                      len(old_efi_entries),
                      '' if len(old_efi_entries) == 1 else 's')
            for info in old_efi_entries.values():
                LOG.debug(
                    "UEFI entry '%s' might no longer exist and "
                    "should be removed.", info['name'])
예제 #3
0
 def test_parses_output_filter_missing(self):
     """ensure parsing ignores items in order that don't have entries"""
     self.in_chroot_subp_output.append((dedent("""\
         BootCurrent: 0000
         Timeout: 1 seconds
         BootOrder: 0000,0002,0001,0003,0004,0005,0006,0007
         Boot0000* ubuntu	HD(1,GPT)/File(\\EFI\\ubuntu\\shimx64.efi)
         Boot0001* CD/DVD Drive 	BBS(CDROM,,0x0)
         Boot0002* Hard Drive 	BBS(HD,,0x0)
         Boot0003* UEFI:CD/DVD Drive	BBS(129,,0x0)
         Boot0004* UEFI:Removable Device	BBS(130,,0x0)
         Boot0005* UEFI:Network Device	BBS(131,,0x0)
         """), ''))
     observed = util.get_efibootmgr('target')
     self.assertEquals(
         {
             'current': '0000',
             'timeout': '1 seconds',
             'order': ['0000', '0002', '0001', '0003', '0004', '0005'],
             'entries': {
                 '0000': {
                     'name': 'ubuntu',
                     'path': 'HD(1,GPT)/File(\\EFI\\ubuntu\\shimx64.efi)',
                 },
                 '0001': {
                     'name': 'CD/DVD Drive',
                     'path': 'BBS(CDROM,,0x0)',
                 },
                 '0002': {
                     'name': 'Hard Drive',
                     'path': 'BBS(HD,,0x0)',
                 },
                 '0003': {
                     'name': 'UEFI:CD/DVD Drive',
                     'path': 'BBS(129,,0x0)',
                 },
                 '0004': {
                     'name': 'UEFI:Removable Device',
                     'path': 'BBS(130,,0x0)',
                 },
                 '0005': {
                     'name': 'UEFI:Network Device',
                     'path': 'BBS(131,,0x0)',
                 },
             }
         }, observed)
예제 #4
0
 def test_calls_efibootmgr_verbose(self):
     self.in_chroot_subp_output.append(('', ''))
     util.get_efibootmgr('target')
     self.assertEquals((['efibootmgr', '-v'], ),
                       self.mock_in_chroot_subp.call_args_list[0][0])