aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-installer/anaconda/files/0012-bootloader.py-Change-grub2-settings-to-match-oe-core.patch
blob: 26f062ba66d24087b9a0d0ef4efe44dd5d15d8a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
From 3dfed14d879e3e42aa988c410c0b5628cfa8ded6 Mon Sep 17 00:00:00 2001
From: Hongxu Jia <hongxu.jia@windriver.com>
Date: Tue, 25 Jun 2019 14:41:55 +0800
Subject: [PATCH] bootloader.py: Change 'grub2' settings to match oe-core

There is no 'grub2' package in oe-core, it's called 'grub'.  Adjust settings
to match this naming.  Also before writing out a variety of configuration
files, as necessary -- create the directories required.

Signed-off-by: Mark Hatle <mark.hatle@windriver.com>

- tweak grub config file for OE

Upstream-Status: Inappropriate [oe specific]
Rebase to f30-release
Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>

Rebase for anaconda 34.

Signed-off-by: Kai Kang <kai.kang@windriver.com>

Set GRUB_DISTRIBUTOR with target system rather than installer image.

Signed-off-by: Kai Kang <kai.kang@windriver.com>

Rebase for anaconda 37 on 20221020.

Signed-off-by: Kai Kang <kai.kang@windriver.com>
---
 pyanaconda/modules/storage/bootloader/base.py  |  4 +++
 pyanaconda/modules/storage/bootloader/grub2.py | 40 ++++++++++++++++++++------
 pyanaconda/modules/storage/bootloader/utils.py |  7 +++--
 3 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/pyanaconda/modules/storage/bootloader/base.py b/pyanaconda/modules/storage/bootloader/base.py
index da8272b7f3..fb9c588846 100644
--- a/pyanaconda/modules/storage/bootloader/base.py
+++ b/pyanaconda/modules/storage/bootloader/base.py
@@ -996,6 +996,10 @@ class BootLoader(object):
             raise BootLoaderError("no config file defined for this boot loader")
 
         config_path = os.path.normpath(conf.target.system_root + self.config_file)
+        config_dir = os.path.dirname(config_path)
+        if not os.path.isdir(config_dir):
+            os.mkdir(config_dir, 755)
+
         if os.access(config_path, os.R_OK):
             os.rename(config_path, config_path + ".anacbak")
 
diff --git a/pyanaconda/modules/storage/bootloader/grub2.py b/pyanaconda/modules/storage/bootloader/grub2.py
index 74249a9507..2163a19e9d 100644
--- a/pyanaconda/modules/storage/bootloader/grub2.py
+++ b/pyanaconda/modules/storage/bootloader/grub2.py
@@ -101,9 +101,9 @@ class GRUB2(BootLoader):
     name = "GRUB2"
     # grub2 is a virtual provides that's provided by grub2-pc, grub2-ppc64le,
     # and all of the primary grub components that aren't grub2-efi-${EFIARCH}
-    packages = ["grub2", "grub2-tools"]
+    packages = ["grub"]
     _config_file = "grub.cfg"
-    _config_dir = "grub2"
+    _config_dir = "grub"
     _passwd_file = "user.cfg"
     defaults_file = "/etc/default/grub"
     terminal_type = "console"
@@ -227,6 +227,10 @@ class GRUB2(BootLoader):
     def write_device_map(self):
         """Write out a device map containing all supported devices."""
         map_path = os.path.normpath(conf.target.system_root + self.device_map_file)
+        map_dir = os.path.dirname(map_path)
+        if not os.path.isdir(map_dir):
+            os.mkdir(map_dir, 755)
+
         if os.access(map_path, os.R_OK):
             os.rename(map_path, map_path + ".anacbak")
 
@@ -254,9 +258,23 @@ class GRUB2(BootLoader):
         defaults_file = "%s%s" % (conf.target.system_root, self.defaults_file)
         defaults = open(defaults_file, "w+")
         defaults.write("GRUB_TIMEOUT=%d\n" % self.timeout)
-        defaults.write("GRUB_DISTRIBUTOR=\"$(sed 's, release .*$,,g' /etc/system-release)\"\n")
+
+        targetProductName = ''
+        try:
+            with open(conf.target.system_root + '/etc/issue') as f:
+                for line in f:
+                    strippedline = line.strip().replace(r' \n \l', '')
+                    if strippedline:
+                        targetProductName = strippedline
+                        break
+        except FileNotFoundError:
+            pass
+
+        defaults.write("GRUB_DISTRIBUTOR=\"%s\"\n" % targetProductName
+                       if targetProductName else productName)
+
         defaults.write("GRUB_DEFAULT=saved\n")
-        defaults.write("GRUB_DISABLE_SUBMENU=true\n")
+        defaults.write("GRUB_DISABLE_SUBMENU=y\n")
         if self.console and self.has_serial_console:
             defaults.write("GRUB_TERMINAL=\"serial console\"\n")
             defaults.write("GRUB_SERIAL_COMMAND=\"%s\"\n" % self.serial_command)
@@ -298,7 +316,7 @@ class GRUB2(BootLoader):
         passwords = "%s\n%s\n" % (self.password, self.password)
         os.write(pwrite, passwords.encode("utf-8"))
         os.close(pwrite)
-        buf = util.execWithCapture("grub2-mkpasswd-pbkdf2", [],
+        buf = util.execWithCapture("grub-mkpasswd-pbkdf2", [],
                                    stdin=pread,
                                    root=conf.target.system_root)
         os.close(pread)
@@ -311,6 +329,10 @@ class GRUB2(BootLoader):
             return
 
         users_file = "%s%s/%s" % (conf.target.system_root, self.config_dir, self._passwd_file)
+        users_dir = os.path.dirname(users_file)
+        if not os.path.isdir(users_dir):
+            os.mkdir(users_dir, 755)
+
         header = open_with_perm(users_file, "w", 0o600)
         # XXX FIXME: document somewhere that the username is "root"
         self._encrypt_password()
@@ -345,7 +367,7 @@ class GRUB2(BootLoader):
 
             default_entry = "%s-%s" % (machine_id, self.default.version)
             rc = util.execWithRedirect(
-                "grub2-set-default",
+                "grub-set-default",
                 [default_entry],
                 root=conf.target.system_root
             )
@@ -356,7 +378,7 @@ class GRUB2(BootLoader):
         # set boot_success so that the menu is hidden on the boot after install
         if conf.bootloader.menu_auto_hide:
             rc = util.execWithRedirect(
-                "grub2-editenv",
+                "grub-editenv",
                 ["-", "set", "menu_auto_hide=1", "boot_success=1"],
                 root=conf.target.system_root
             )
@@ -365,7 +387,7 @@ class GRUB2(BootLoader):
 
         # now tell grub2 to generate the main configuration file
         rc = util.execWithRedirect(
-            "grub2-mkconfig",
+            "grub-mkconfig",
             ["-o", self.config_file],
             root=conf.target.system_root
         )
@@ -425,7 +447,7 @@ class GRUB2(BootLoader):
                 else:
                     log.info("bootloader.py: mbr will be updated for grub2")
 
-            rc = util.execWithRedirect("grub2-install", grub_args,
+            rc = util.execWithRedirect("grub-install", grub_args,
                                        root=conf.target.system_root,
                                        env_prune=['MALLOC_PERTURB_'])
             if rc:
diff --git a/pyanaconda/modules/storage/bootloader/utils.py b/pyanaconda/modules/storage/bootloader/utils.py
index 27fc2a0058..d55db37f7c 100644
--- a/pyanaconda/modules/storage/bootloader/utils.py
+++ b/pyanaconda/modules/storage/bootloader/utils.py
@@ -180,6 +180,9 @@ def _write_sysconfig_kernel(sysroot, storage):
 
     kernel = h.name
 
+    if not os.path.isdir(conf.target.system_root + "/etc/sysconfig"):
+        os.mkdir(conf.target.system_root + "/etc/sysconfig", 755)
+
     f = open(sysroot + "/etc/sysconfig/kernel", "w+")
     f.write("# UPDATEDEFAULT specifies if kernel-install should make\n"
             "# new kernels the default\n")
@@ -245,8 +248,8 @@ def create_bls_entries(sysroot, storage, kernel_versions):
     # entries will have the correct kernel cmdline and not the value
     # taken from /proc/cmdline, that is used to boot the live image.
     rc = execWithRedirect(
-        "grub2-mkconfig",
-        ["-o", "/etc/grub2.cfg"],
+        "grub-mkconfig",
+        ["-o", "/etc/grub.cfg"],
         root=sysroot
     )
 
-- 
2.7.4