Beispiel #1
0
def addNewKernel(grub, version, root):
    """
        Adds new kernel entry to GRUB.

        Arguments:
            grub: GRUB configuration instance
            version: Kernel version, in version-release(-suffix) format. Suffix is optional.
            root: Root device
    """

    # get version and suffix
    version, suffix = parseVersion("kernel-%s" % version)

    groups, versions = groupEntries(grub, root)
    group_name = "pardus%s" % suffix

    default_index = grub.getOption("default", 0)
    if default_index != "saved":
        try:
            default_index = int(default_index)
        except ValueError:
            default_index = 0

    if group_name in versions and any(
        [x == version for x in versions[group_name].values()]):
        # Version is already in list, do nothing
        entry_index = -1
        for i in versions[group_name]:
            if versions[group_name][i] == version:
                entry_index = i
                break
    else:
        if group_name in groups:
            entry_index = min(groups[group_name])
            # Get kernel options of first entry in group
            kernel = grub.getEntry(entry_index).getCommand("kernel")
            options = kernel.value.split(" ", 1)[1]
        else:
            entry_index = -1
            # Get kernel options from /proc/cmdline
            options = bootParameters(root)

        release = open("/etc/pardus-release", "r").readline().strip()
        title = "%s [%s%s]" % (release, version, suffix)

        entry = grubEntry(title)
        entry.setCommand("root", grubAddress(root))
        entry.setCommand("kernel",
                         "/boot/kernel-%s%s %s" % (version, suffix, options))
        entry.setCommand("initrd", "/boot/initramfs-%s%s" % (version, suffix))
        if default_index == "saved":
            entry.setCommand("savedefault", "")
        grub.addEntry(entry, entry_index)

    # update default index, if it's after last entry
    if default_index != "saved":
        if default_index > entry_index and entry_index != -1:
            default_index += 1
            grub.setOption("default", default_index)
Beispiel #2
0
def addNewKernel(grub, version, root):
    """
        Adds new kernel entry to GRUB.

        Arguments:
            grub: GRUB configuration instance
            version: Kernel version, in version-release(-suffix) format. Suffix is optional.
            root: Root device
    """

    # get version and suffix
    version, suffix = parseVersion("kernel-%s" % version)

    groups, versions = groupEntries(grub, root)
    group_name = "pardus%s" % suffix

    default_index = grub.getOption("default", 0)
    if default_index != "saved":
        try:
            default_index = int(default_index)
        except ValueError:
            default_index = 0

    if group_name in versions and any([x == version for x in versions[group_name].values()]):
        # Version is already in list, do nothing
        entry_index = -1
        for i in versions[group_name]:
            if versions[group_name][i] == version:
                entry_index = i
                break
    else:
        if group_name in groups:
            entry_index = min(groups[group_name])
            # Get kernel options of first entry in group
            kernel = grub.getEntry(entry_index).getCommand("kernel")
            options = kernel.value.split(" ", 1)[1]
        else:
            entry_index = -1
            # Get kernel options from /proc/cmdline
            options = bootParameters(root)

        release = open("/etc/pardus-release", "r").readline().strip()
        title = "%s [%s%s]" % (release, version, suffix)

        entry = grubEntry(title)
        entry.setCommand("root", grubAddress(root))
        entry.setCommand("kernel", "/boot/kernel-%s%s %s" % (version, suffix, options))
        entry.setCommand("initrd", "/boot/initramfs-%s%s" % (version, suffix))
        if default_index == "saved":
            entry.setCommand("savedefault", "")
        grub.addEntry(entry, entry_index)

    # update default index, if it's after last entry
    if default_index != "saved":
        if default_index > entry_index and entry_index != -1:
            default_index += 1
            grub.setOption("default", default_index)
Beispiel #3
0
def makeGrubEntry(title, os_type, root=None, kernel=None, initrd=None, options=None):
    if os_type not in SYSTEMS:
        fail(FAIL_NOSYSTEM)
    
    fields_req = SYSTEMS[os_type][1]
    fields_opt = SYSTEMS[os_type][2]
    fields_all = fields_req + fields_opt
    
    if "root" in fields_req:
        if not root:
            fail(FAIL_NOROOT)
    else:
        root = getRoot()
    
    try:
        linux_disk, linux_part, grub_disk, grub_part = parseLinuxDevice(root)
    except (ValueError, TypeError):
        fail(FAIL_NODEVICE % root)
    grub_device = "(%s,%s)" % (grub_disk, grub_part)
    
    if "kernel" in fields_req and not kernel:
        fail(FAIL_NOKERNEL)
    
    entry = grubEntry(title)
    
    if os_type == "windows":
        # If Windows is not on first disk...
        if grub_disk != "hd0":
            entry.setCommand("map", "(%s) (hd0)" % grub_disk)
            entry.setCommand("map", "(hd0) (%s)" % grub_disk, append=True)
        entry.setCommand("rootnoverify", grub_device)
        entry.setCommand("makeactive", "")
        entry.setCommand("chainloader", "+1")
    else:
        entry.setCommand("root", grub_device)
    if os_type == "xen":
        entry.setCommand("kernel", "/boot/xen.gz")
        if kernel and "kernel" in fields_all:
            if options and "options" in fields_all:
                entry.setCommand("module", "%s %s" % (kernel, options))
            else:
                entry.setCommand("module", kernel)
        if initrd and "initrd" in fields_all:
            entry.setCommand("module", initrd, append=True)
    elif os_type == "memtest":
        entry.setCommand("root", grub_device)
        entry.setCommand("kernel", "/boot/memtest")
    else: # linux
        if kernel and "kernel" in fields_all:
            if options and "options" in fields_all:
                entry.setCommand("kernel", "%s %s" % (kernel, options))
            else:
                entry.setCommand("kernel", kernel)
        if initrd and "initrd" in fields_all:
            entry.setCommand("initrd", initrd)
    return entry
Beispiel #4
0
    def _addLink(_grub, _file, _title):
        """
            Adds a link to specified GRUB configuration.

            Arguments:
                _grub: GRUB configuration instance
                _file: Target file
                _title: Entry title
        """
        if not any([x.getCommand("configfile") and x.getCommand("configfile").value == _file for x in _grub.entries]):
            entry = grubEntry(_title)
            entry.setCommand("configfile", _file)
            _grub.addEntry(entry)
Beispiel #5
0
    def _addLink(_grub, _file, _title):
        """
            Adds a link to specified GRUB configuration.

            Arguments:
                _grub: GRUB configuration instance
                _file: Target file
                _title: Entry title
        """
        if not any([x.getCommand("configfile") and x.getCommand("configfile").value == _file for x in _grub.entries]):
            entry = grubEntry(_title)
            entry.setCommand("configfile", _file)
            _grub.addEntry(entry)