From 41e7a9ae3c0008883fb80cd4874ed20577c2062b Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Tue, 31 Mar 2015 18:14:33 +0200 Subject: [PATCH 1/4] Preserve kernel parameters that aren't handled by grubcfg. --- src/modules/grubcfg/main.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) 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"): From a977b1ea4057989e475fcda3b0f5922cc4ea523f Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Wed, 1 Apr 2015 15:50:13 +0200 Subject: [PATCH 2/4] Make sure we write the kernel config line anyway. --- src/modules/grubcfg/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/grubcfg/main.py b/src/modules/grubcfg/main.py index b6d06d0a8..eef731bcc 100644 --- a/src/modules/grubcfg/main.py +++ b/src/modules/grubcfg/main.py @@ -87,7 +87,7 @@ def modify_grub_default(partitions, root_mount_point, distributor): 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 + 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)) @@ -110,6 +110,7 @@ def modify_grub_default(partitions, root_mount_point, distributor): lines.append("{!s}=\"{!s}\"".format(key, escaped_value)) if not have_kernel_cmd: + kernel_cmd = "GRUB_CMDLINE_LINUX_DEFAULT=\"{!s}\"".format(" ".join(kernel_params)) lines.append(kernel_cmd) if not have_distributor_line: From debd4bc352ff81c0b0bb46bad429adf1509429a7 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Thu, 2 Apr 2015 13:24:47 +0200 Subject: [PATCH 3/4] Fix regexp in grubcfg. CAL-205 #comment Done some fixing, please retest when you can. --- src/modules/grubcfg/main.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/modules/grubcfg/main.py b/src/modules/grubcfg/main.py index eef731bcc..d34f0c257 100644 --- a/src/modules/grubcfg/main.py +++ b/src/modules/grubcfg/main.py @@ -77,12 +77,12 @@ def modify_grub_default(partitions, root_mount_point, distributor): lines[i] = kernel_cmd have_kernel_cmd = True elif lines[i].startswith("GRUB_CMDLINE_LINUX_DEFAULT"): - regex = re.compile(r"^GRUB_CMDLINE_LINUX_DEFAULT.*=") + regex = re.compile(r"^GRUB_CMDLINE_LINUX_DEFAULT\s*=\s*\"") line = regex.sub("", lines[i]) - line.lstrip() - line.lstrip("\"") - line.rstrip() - line.rstrip("\"") + line = line.lstrip() + line = line.lstrip("\"") + line = line.rstrip() + line = line.rstrip("\"") existing_params = line.split() for existing_param in existing_params: From 8625b8c5a9a51f124c27fc3e51282150f0602198 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Thu, 2 Apr 2015 20:25:41 +0200 Subject: [PATCH 4/4] Fix up regex in grubcfg to work with single quotes. --- src/modules/grubcfg/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/grubcfg/main.py b/src/modules/grubcfg/main.py index d34f0c257..e7d147caf 100644 --- a/src/modules/grubcfg/main.py +++ b/src/modules/grubcfg/main.py @@ -77,12 +77,14 @@ def modify_grub_default(partitions, root_mount_point, distributor): lines[i] = kernel_cmd have_kernel_cmd = True elif lines[i].startswith("GRUB_CMDLINE_LINUX_DEFAULT"): - regex = re.compile(r"^GRUB_CMDLINE_LINUX_DEFAULT\s*=\s*\"") + regex = re.compile(r"^GRUB_CMDLINE_LINUX_DEFAULT\s*=\s*") line = regex.sub("", lines[i]) line = line.lstrip() line = line.lstrip("\"") + line = line.lstrip("'") line = line.rstrip() line = line.rstrip("\"") + line = line.rstrip("'") existing_params = line.split() for existing_param in existing_params: