Beispiel #1
0
 def check_for_grub(self):
     """Check for grub multiboot boot loader and install its required packages if needed."""
     if sysfs_info.has_efi():
         _required_packages = ['shim-signed', 'grub-efi-amd64-signed']
         if self.install_packages(_required_packages):
             raise GeneralPostTargetError(
                 'Error installing required packages for grub2')
Beispiel #2
0
    def install_grub(self):
        if not self.bootloader_configuration:
            log.warn('Bootloader configuration is missing')
            return

        self.update_kernel_parameters()

        log.info('Generating grub configuration')
        # TODO(mdraid): We may need run grub2-mkconfig on all targets?
        root_partition = deployment.find_root(self.layout)
        root_uuid = root_partition.file_system.fs_uuid
        log.info('Configuring mtab')
        self.chroot('grep -v rootfs /proc/mounts > /etc/mtab')

        kernels = os.listdir(self.join_root('/lib/modules'))
        for kernel in kernels:
            self.chroot('{} --args=root=UUID={} '
                        '--update-kernel=/boot/vmlinuz-{}'.format(
                            self.grubby_path, root_uuid, kernel))
        for disk in self.disk_targets:
            log.info('Installing grub on {}'.format(disk))
            self.chroot('{} {} {}'.format(self.grub_install_path,
                                          self.grub_install_opts, disk))
            if sysfs_info.has_efi():
                log.info('Configuring bootloader for EFI')
                # For EFI kick to work we have to copy grub.conf from /boot/grub
                self.chroot('cp /boot/grub/grub.conf /boot/efi/EFI/redhat/')
                self.chroot('efibootmgr -c -d {} -L "{}"'.format(
                    disk, self.grub_efi_bootloader_name))
Beispiel #3
0
def set_disk_labels(layout, layout_config):
    """
    Read into configuration and set label to gpt or msdos based on size.
    If label is present in the configuration and is gpt but not efi,
    make sure bios boot partition is present.
    """
    # TODO: Trace disk generator and inject this
    partition_tables = layout_config.get('partition_tables')
    for partition_table in partition_tables:
        label = partition_table.get('label')
        if label:
            LOG.info('Table: %s is set as %s in configuration' %
                     (partition_table.get('disk', 'undefined'),
                      partition_table['label']))

        # 'first' and 'any' are valid disk references in the configuration
        # 'first' indicates the first unallocated disk
        #       (as sorted by udev (subsystem->sub_id)
        # 'any' references that first disk encountered
        #       that is large enough to hold the partitions
        # 'any' is slated for removal in v0.4.0 roadmap

        if partition_table['disk'] == 'first':
            disk = layout.unallocated[0]
        elif partition_table['disk'] == 'any':
            size = Size(0)
            for partition in partition_table.get('partitions'):
                # Percent strings are relative and
                # cannot be used to calculate total size
                if '%' not in partition['size']:
                    size += Size(partition['size'])
            disk = layout.find_device_by_size(size)
        else:
            disk = layout.find_device_by_ref(partition_table['disk'])

        if not sysfs_info.has_efi():
            if disk.size.over_2t:
                LOG.info('%s is over 2.2TiB, using gpt' % disk.devname)
                label = 'gpt'
                if not layout_config.get('no_bios_boot_partition'):
                    # TODO: Add config option to disks,
                    # allowing user to specify the boot disk
                    # if disk == the first disk or presumed boot disk
                    if list(layout.disks.keys()).index(disk.devname) == 0:
                        add_bios_boot_partition(partition_table)
            elif label == 'gpt':
                add_bios_boot_partition(partition_table)
            else:
                LOG.info('%s is under 2.2TiB, using msdos' % disk.devname)
                label = 'msdos'
        else:
            LOG.info('Booting in UEFI mode, using gpt')
            label = 'gpt'
            # Only install boot partition on "first" drive
            # TODO: Allow the user to specifygit
            if list(layout.disks.keys()).index(disk.devname) == 0:
                add_efi_boot_partition(partition_table)

        partition_table['label'] = label
    def check_for_grub(self):
        _required_packages = ['grub', 'grubby']
        if sysfs_info.has_efi():
            os_id, os_label = self.get_efi_label()
            self.grub_efi_bootloader_name = os_label

        if not self.packages_exist(_required_packages):
            if not self.install_packages(_required_packages):
                raise GeneralPostTargetError(
                    'Error installing required packages for grub')
Beispiel #5
0
    def update_kernel_parameters(self):
        """
        A little hacktastic
        :return:
        """

        appending = self.kernel_parameters.get('append', list())
        removing = self.kernel_parameters.get('remove', list())
        modifying = self.kernel_parameters.get('modify', list())

        if not (appending or removing):
            return

        full_path = self.join_root(self.grub_cmdline_config_path)
        if not os.path.exists(full_path):
            log.warn('Grub configuration is missing from image')
            return

        data = deployment.read(full_path, splitlines=True)

        modified = False
        for idx in range(len(data)):
            line = data[idx]
            line = line.strip()

            if line and line[0] == '#':
                continue

            # grub1 is not smart to find efi partition,
            # have to force it to find.
            if self.default_grub_root_partition in line and sysfs_info.has_efi(
            ):
                if modifying:
                    data[idx] = util.misc.replace_grub_root_partition(
                        line, self.default_grub_root_partition, modifying[0])
                    modified = True
                    continue

            if self.grub_cmdline_name in line:
                data[idx] = util.misc.opts_modifier(line,
                                                    appending,
                                                    removing,
                                                    quoted=False)
                log.debug('{} > {}'.format(line, data[idx]))
                modified = True
                continue

        if modified:
            log.info('Updating {}'.format(self.grub_cmdline_config_path))
            deployment.replace_file(full_path, '\n'.join(data) + '\n')
        else:
            log.warn('Grub configuration was not updated, no matches!')
Beispiel #6
0
 def check_for_grub(self):
     _required_packages = ['grub2', 'grub2-tools']
     if sysfs_info.has_efi():
         os_id, os_label = self.get_efi_label()
         _required_packages += ['grub2-efi', 'efibootmgr', 'shim']
         self.grub2_config_path = '/boot/efi/EFI/{}/grub.cfg'.format(os_id)
         self.grub2_efi_command = ('efibootmgr --create --gpt '
                                   '--disk {} --part 1 --write-signature '
                                   '--label "{}" '
                                   '--loader /EFI/{}/shim.efi'.format(
                                       self.disk_target, os_label, os_id))
     if not self.packages_exist(_required_packages):
         self.baseline_yum(self.proxy)
         if self.install_packages(_required_packages):
             raise GeneralPostTargetError(
                 'Error installing required packages for grub2')
         self.revert_yum(self.proxy)
Beispiel #7
0
    def install_grub2(self):
        if not self.bootloader_configuration:
            log.warn('Bootloader configuration is missing')
            return

        self.update_kernel_parameters()
        self.clear_grub_cmdline_linux_default()

        log.info('Generating grub configuration')
        self.chroot('{} -o {}'.format(self.grub2_mkconfig_path,
                                      self.grub2_config_path))

        if sysfs_info.has_efi():
            log.info("Installing EFI enabled grub")
            self.chroot(self.grub2_efi_command)
        else:
            command = '{} --target=i386-pc --recheck --debug'.format(
                self.grub2_install_path)
            for disk in self.disk_targets:
                log.info('Installing grub on {}'.format(disk))
                self.chroot("{} {}".format(command, disk))
Beispiel #8
0
 def check_for_grub(self):
     if sysfs_info.has_efi():
         _required_packages = ['shim', 'grub-efi-amd64']
         if self.install_packages(_required_packages):
             raise GeneralPostTargetError(
                 'Error installing required packages for grub2')