From 3dfed14d879e3e42aa988c410c0b5628cfa8ded6 Mon Sep 17 00:00:00 2001 From: Hongxu Jia 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 - tweak grub config file for OE Upstream-Status: Inappropriate [oe specific] Rebase to f30-release Signed-off-by: Hongxu Jia Rebase for anaconda 34. Signed-off-by: Kai Kang Set GRUB_DISTRIBUTOR with target system rather than installer image. Signed-off-by: Kai Kang Rebase for anaconda 37 on 20221020. Signed-off-by: Kai Kang --- 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