Example #1
0
def guess_kernel(chroot=''):
    for filename in sorted(os.listdir(chroot + '/boot'), reverse=True):
        # We assume kernel name is always starts with vmlinuz.
        # We use the newest one.
        if filename.startswith('vmlinuz'):
            return filename
    raise errors.GrubUtilsError('Error while trying to find kernel: not found')
Example #2
0
def guess_initrd(chroot=''):
    for filename in sorted(os.listdir(chroot + '/boot'), reverse=True):
        # We assume initrd starts either with initramfs or initrd.
        if filename.startswith('initramfs') or \
                filename.startswith('initrd'):
            return filename
    raise errors.GrubUtilsError('Error while trying to find initrd: not found')
Example #3
0
def guess_grub(chroot=''):
    for grub in ('/sbin/grub', '/usr/sbin/grub'):
        LOG.debug('Looking for grub: trying %s' % grub)
        if os.path.isfile(chroot + grub):
            LOG.debug('grub found: %s' % grub)
            return grub
    raise errors.GrubUtilsError('grub not found')
Example #4
0
def guess_grub2_mkconfig(chroot=''):
    for grub_mkconfig in \
            ('/sbin/grub-mkconfig', '/sbin/grub2-mkconfig',
             '/usr/sbin/grub-mkconfig', '/usr/sbin/grub2-mkconfig'):
        if os.path.isfile(chroot + grub_mkconfig):
            return grub_mkconfig
    raise errors.GrubUtilsError('grub2 mkconfig binary not found')
Example #5
0
def guess_grub_install(chroot=''):
    for grub_install in ('/sbin/grub-install', '/sbin/grub2-install',
                         '/usr/sbin/grub-install', '/usr/sbin/grub2-install'):
        LOG.debug('Looking for grub-install: trying %s' % grub_install)
        if os.path.isfile(chroot + grub_install):
            LOG.debug('grub-install found: %s' % grub_install)
            return grub_install
    raise errors.GrubUtilsError('grub-install not found')
Example #6
0
def guess_grub1_datadir(chroot='', arch='x86_64'):
    LOG.debug('Looking for grub data directory')
    for d in os.listdir(chroot + '/usr/share/grub'):
        if arch in d:
            LOG.debug('Looks like grub data directory '
                      'is /usr/share/grub/%s' % d)
            return '/usr/share/grub/' + d
    raise errors.GrubUtilsError('grub data directory not found for arch %s' %
                                arch)
Example #7
0
def grub1_install(install_devices, boot_device, chroot=''):
    match = re.search(r'(.+?)(p?)(\d*)$', boot_device)
    # Checking whether boot device is a partition
    # !!! It must be a partition not a whole disk. !!!
    if not match.group(3):
        raise errors.GrubUtilsError('Error while installing legacy grub: '
                                    'boot device must be a partition')
    boot_disk = match.group(1)
    boot_part = str(int(match.group(3)) - 1)
    grub1_stage1(chroot=chroot)
    for install_device in install_devices:
        grub1_mbr(install_device, boot_disk, boot_part, chroot=chroot)
Example #8
0
def guess_kernel(chroot='', regexp=None):
    """Tries to guess kernel by regexp

    :param chroot: Path to chroot
    :param regexp: (String) Regular expression (must have python syntax).
    Default is r'^vmlinuz.*'
    """
    kernel = utils.guess_filename(path=os.path.join(chroot, 'boot'),
                                  regexp=(regexp or r'^vmlinuz.*'))

    if kernel:
        return kernel

    raise errors.GrubUtilsError('Error while trying to find kernel: '
                                'regexp=%s' % regexp)
Example #9
0
def guess_initrd(chroot='', regexp=None):
    """Tries to guess initrd by regexp

    :param chroot: Path to chroot
    :param regexp: (String) Regular expression (must have python syntax).
    Default is r'^(initrd|initramfs).*'
    """
    initrd = utils.guess_filename(path=os.path.join(chroot, 'boot'),
                                  regexp=(regexp or r'^(initrd|initramfs).*'))

    if initrd:
        return initrd

    raise errors.GrubUtilsError('Error while trying to find initrd: '
                                'regexp=%s' % regexp)
Example #10
0
def guess_grub2_default(chroot=''):
    for filename in ('/etc/default/grub', '/etc/sysconfig/grub'):
        if os.path.isfile(chroot + filename):
            return filename
    raise errors.GrubUtilsError('grub2 defaul config file not found')
Example #11
0
def guess_grub2_conf(chroot=''):
    for filename in ('/boot/grub/grub.cfg', '/boot/grub2/grub.cfg'):
        if os.path.isdir(os.path.dirname(chroot + filename)):
            return filename
    raise errors.GrubUtilsError('grub2 config file not found')