diff --git a/src/modules/grubcfg/main.py b/src/modules/grubcfg/main.py index 1cf40e721..b6d06d0a8 100644 --- a/src/modules/grubcfg/main.py +++ b/src/modules/grubcfg/main.py @@ -4,6 +4,7 @@ # === This file is part of Calamares - === # # Copyright 2014-2015, Philip Müller +# Copyright 2015, Teo Mrnjavac # # Calamares is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,6 +21,7 @@ import libcalamares import os +import re def modify_grub_default(partitions, root_mount_point, distributor): @@ -46,10 +48,11 @@ def modify_grub_default(partitions, root_mount_point, distributor): if partition["fs"] == "linuxswap": swap_uuid = partition["uuid"] - if swap_uuid != "": - kernel_cmd = "GRUB_CMDLINE_LINUX_DEFAULT=\"resume=UUID={!s} quiet {!s}\"".format(swap_uuid, use_splash) - else: - kernel_cmd = "GRUB_CMDLINE_LINUX_DEFAULT=\"quiet {!s}\"".format(use_splash) + kernel_params = ["quiet"] + if use_splash: + kernel_params.append(use_splash) + if swap_uuid: + kernel_params.append("resume=UUID={!s}".format(swap_uuid)) distributor_line = "GRUB_DISTRIBUTOR=\"{!s}\"".format(distributor_replace) @@ -70,9 +73,24 @@ def modify_grub_default(partitions, root_mount_point, distributor): for i in range(len(lines)): if lines[i].startswith("#GRUB_CMDLINE_LINUX_DEFAULT"): + kernel_cmd = "GRUB_CMDLINE_LINUX_DEFAULT=\"{!s}\"".format(" ".join(kernel_params)) lines[i] = kernel_cmd have_kernel_cmd = True elif lines[i].startswith("GRUB_CMDLINE_LINUX_DEFAULT"): + regex = re.compile(r"^GRUB_CMDLINE_LINUX_DEFAULT.*=") + line = regex.sub("", lines[i]) + line.lstrip() + line.lstrip("\"") + line.rstrip() + line.rstrip("\"") + existing_params = line.split() + + for existing_param in existing_params: + existing_param_name = existing_param.split("=")[0] + if existing_param_name not in ["quiet", "resume", "splash"]: #the only ones we ever add + kernel_params.append(existing_param) + + kernel_cmd = "GRUB_CMDLINE_LINUX_DEFAULT=\"{!s}\"".format(" ".join(kernel_params)) lines[i] = kernel_cmd have_kernel_cmd = True elif lines[i].startswith("#GRUB_DISTRIBUTOR") or lines[i].startswith("GRUB_DISTRIBUTOR"):