From 4f4e41052308f97e1b6e9bf21549491a0b60c19c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Sch=C3=A4fer?= Date: Fri, 9 Aug 2024 12:07:48 +0200 Subject: [PATCH] Fix handling of zipl.conf in plain zipl bootloader When using the plain zipl bootloader kiwi created a /etc/zipl.conf file. However, this file was only useful during image build as it points to a loop target device and geometry but does not represent a proper config file to be used in the running system. In addition the different distributors provides their own version and layout of the zipl.conf to be used inside of the system and with their respective tools. Thus this commit changes the way how kiwi operates in a way that the zipl.conf used in the initial image only exists during the image build process. An eventual present /etc/zipl.conf will not be touched by kiwi. This Fixes #2597 --- kiwi/bootloader/config/zipl.py | 25 ++++++++++++------------ test/unit/bootloader/config/zipl_test.py | 17 ++++++++-------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/kiwi/bootloader/config/zipl.py b/kiwi/bootloader/config/zipl.py index 8147baf1..937b96d9 100644 --- a/kiwi/bootloader/config/zipl.py +++ b/kiwi/bootloader/config/zipl.py @@ -25,6 +25,7 @@ from kiwi.boot.image.base import BootImageBase from kiwi.bootloader.template.zipl import BootLoaderTemplateZipl from kiwi.bootloader.config.bootloader_spec_base import BootLoaderSpecBase from kiwi.command import Command +from kiwi.utils.temporary import Temporary from kiwi.exceptions import ( KiwiTemplateError, @@ -44,7 +45,9 @@ class BootLoaderZipl(BootLoaderSpecBase): def setup_loader(self, target: str) -> None: """ - Setup main zipl.conf and install zipl for supported targets + Setup temporary zipl config and install zipl for supported targets. + Please note we are not touching the main zipl.conf file provided + by the distributors :param str target: target identifier, one of disk, live(iso) or install(iso) @@ -72,15 +75,19 @@ class BootLoaderZipl(BootLoaderSpecBase): self.custom_args['initrd'] = \ f'{boot_path}/{kernel_info.initrd_name}' + runtime_zipl_config_file = Temporary( + path=self.root_mount.mountpoint, prefix='kiwi_zipl.conf_' + ).new_file() + BootLoaderZipl._write_config_file( BootLoaderTemplateZipl().get_loader_template(), - f'{self.root_mount.mountpoint}/etc/zipl.conf', + runtime_zipl_config_file.name, self._get_template_parameters() ) self.set_loader_entry( self.root_mount.mountpoint, self.target.disk ) - self._install_zipl(root_dir) + self._install_zipl(root_dir, runtime_zipl_config_file.name) def set_loader_entry(self, root_dir: str, target: str) -> None: """ @@ -97,26 +104,18 @@ class BootLoaderZipl(BootLoaderSpecBase): self._get_template_parameters(entry_name) ) - def _install_zipl(self, root_dir: str) -> None: + def _install_zipl(self, root_dir: str, zipl_config: str) -> None: """ Install zipl on target """ zipl = [ 'chroot', root_dir, 'zipl', '--noninteractive', - '--config', '/etc/zipl.conf', + '--config', zipl_config.replace(root_dir, ''), '--blsdir', self.entries_dir, '--verbose' ] Command.run(zipl) - # rewrite zipl.conf without loop device reference - template_parameters = self._get_template_parameters() - template_parameters['targetbase'] = '' - BootLoaderZipl._write_config_file( - BootLoaderTemplateZipl().get_loader_template(), - f'{self.root_mount.mountpoint}/etc/zipl.conf', - template_parameters - ) def _get_template_parameters( self, default_entry: str = '' diff --git a/test/unit/bootloader/config/zipl_test.py b/test/unit/bootloader/config/zipl_test.py index df8a3032..126ed244 100644 --- a/test/unit/bootloader/config/zipl_test.py +++ b/test/unit/bootloader/config/zipl_test.py @@ -56,15 +56,20 @@ class TestBootLoaderZipl: @patch('kiwi.bootloader.config.zipl.Path.create') @patch('kiwi.bootloader.config.zipl.Command.run') @patch('kiwi.bootloader.config.zipl.BootLoaderTemplateZipl') + @patch('kiwi.bootloader.config.zipl.Temporary.new_file') @patch.object(BootLoaderZipl, '_write_config_file') @patch.object(BootLoaderZipl, '_get_template_parameters') @patch.object(BootLoaderSpecBase, 'get_entry_name') def test_setup_loader( self, mock_get_entry_name, mock_get_template_parameters, - mock_write_config_file, mock_BootLoaderTemplateZipl, mock_Command_run, + mock_write_config_file, mock_Temporary_new_file, + mock_BootLoaderTemplateZipl, mock_Command_run, mock_Path_create, mock_Path_wipe, mock_BootImageBase_get_boot_names, mock_os_path_exists ): + temporary = Mock() + temporary.name = 'system_root_mount/kiwi_zipl.conf_' + mock_Temporary_new_file.return_value = temporary mock_get_entry_name.return_value = \ 'opensuse-leap-5.3.18-59.10-default.conf' @@ -82,7 +87,7 @@ class TestBootLoaderZipl: call( mock_BootLoaderTemplateZipl. return_value.get_loader_template.return_value, - 'system_root_mount/etc/zipl.conf', + 'system_root_mount/kiwi_zipl.conf_', mock_get_template_parameters.return_value ), call( @@ -91,12 +96,6 @@ class TestBootLoaderZipl: 'system_root_mount/boot/loader/entries/' 'opensuse-leap-5.3.18-59.10-default.conf', mock_get_template_parameters.return_value - ), - call( - mock_BootLoaderTemplateZipl. - return_value.get_loader_template.return_value, - 'system_root_mount/etc/zipl.conf', - {'targetbase': ''} ) ] assert self.bootloader._mount_system.called @@ -104,7 +103,7 @@ class TestBootLoaderZipl: [ 'chroot', 'system_root_mount', 'zipl', '--noninteractive', - '--config', '/etc/zipl.conf', + '--config', '/kiwi_zipl.conf_', '--blsdir', '/boot/loader/entries', '--verbose' ]