Repository: OSInside/kiwi

Issue:
Support GPT on IBM Z
## Problem description
As it turns out, [zipl supports GPT disks](https://www.ibm.com/docs/en/linux-on-systems?topic=bs-zipl-initial-program-loader), and Fedora prefers GPT whenever possible, so it'd be good to support using GPT for s390 systems when using the zipl bootloader.

## OS and Software information

* KIWI version: 10.2.3
* Operating system host version: Fedora Linux 42
* Operating system target version: Fedora Linux 42
* Open Build Service version (N/A if not using OBS): N/A
* Koji version (N/A if not using Koji): 1.35.1

Discussion:

Solution patch:
diff --git a/doc/source/image_description/elements.rst b/doc/source/image_description/elements.rst
index 973d5724..24887b80 100644
--- a/doc/source/image_description/elements.rst
+++ b/doc/source/image_description/elements.rst
@@ -1181,11 +1181,11 @@ timeout_style="countdown|hidden":
   an indication of the remaining time is displayed. The attribute is
   available for the grub loader only.
 
-targettype="CDL|LDL|FBA|SCSI":
+targettype="CDL|LDL|FBA|SCSI|GPT":
   Specifies the device type of the disk zipl should boot.
-  On zFCP devices, use `SCSI`; on DASD devices, use `CDL` or `LDL`; on
-  emulated DASD devices, use `FBA`. The attribute is available for the
-  zipl loader only.
+  On zFCP and/or KVM devices, use `SCSI` or `GPT`; on DASD devices,
+  use `CDL` or `LDL`; on emulated DASD devices, use `FBA`.
+  The attribute is available for the zipl loader only.
 
 <preferences><type><bootloader><securelinux>
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/kiwi/firmware.py b/kiwi/firmware.py
index 624a21f2..223edb5b 100644
--- a/kiwi/firmware.py
+++ b/kiwi/firmware.py
@@ -68,6 +68,8 @@ class FirmWare:
         if 's390' in self.arch:
             if self.zipl_target_type and 'CDL' in self.zipl_target_type:
                 return 'dasd'
+            elif self.zipl_target_type and 'GPT' in self.zipl_target_type:
+                return 'gpt'
             else:
                 return 'msdos'
         elif 'ppc64' in self.arch:
diff --git a/kiwi/xml_state.py b/kiwi/xml_state.py
index c1cdeef2..7653be28 100644
--- a/kiwi/xml_state.py
+++ b/kiwi/xml_state.py
@@ -1174,7 +1174,7 @@ class XMLState:
         :rtype: bool
         """
         bootloader = self.get_build_type_bootloader_section()
-        if bootloader:
+        if bootloader and bootloader.get_bls() is not None:
             return bootloader.get_bls()
         return True
 
diff --git a/package/kiwi-revert-bls-default-for-suse.patch b/package/kiwi-revert-bls-default-for-suse.patch
index 4a5c4036..842060ff 100644
--- a/package/kiwi-revert-bls-default-for-suse.patch
+++ b/package/kiwi-revert-bls-default-for-suse.patch
@@ -1,25 +1,15 @@
-From b0d850842b0c8d4c98f0486f66ffd7c6e8f1a685 Mon Sep 17 00:00:00 2001
-From: Neal Gompa <ngompa@opensuse.org>
-Date: Thu, 2 May 2024 06:23:45 -0400
-Subject: [PATCH] Revert "kiwi/bootloader: restore backward compatibility for
- grub2 with bls"
-
-For the time being, SUSE distributions cannot handle KIWI's default to use
-BLS with GRUB2. Until they catch up, revert this.
-
-This reverts commit 155d969d7752d92c90c69044bdd69be70f0a1c24.
----
- kiwi/xml_state.py                         | 2 +-
- test/unit/bootloader/config/grub2_test.py | 4 ----
- 2 files changed, 1 insertion(+), 5 deletions(-)
+restore backward compatibility for grub2 with bls.
+For the time being, SUSE distributions cannot handle KIWI's
+default (True) to use BLS with GRUB2. Until they catch up, the
+kiwi default is set to: False
 
 diff --git a/kiwi/xml_state.py b/kiwi/xml_state.py
-index eb39163cd..8c3fd45f3 100644
+index 7653be284..1e72cca22 100644
 --- a/kiwi/xml_state.py
 +++ b/kiwi/xml_state.py
-@@ -1009,7 +1009,7 @@ class XMLState:
+@@ -1176,7 +1176,7 @@ class XMLState:
          bootloader = self.get_build_type_bootloader_section()
-         if bootloader:
+         if bootloader and bootloader.get_bls() is not None:
              return bootloader.get_bls()
 -        return True
 +        return False
@@ -27,10 +17,18 @@ index eb39163cd..8c3fd45f3 100644
      def get_build_type_bootloader_console(self) -> List[str]:
          """
 diff --git a/test/unit/bootloader/config/grub2_test.py b/test/unit/bootloader/config/grub2_test.py
-index e9189a609..d81d76ec7 100644
+index b40362941..a2dd3106d 100644
 --- a/test/unit/bootloader/config/grub2_test.py
 +++ b/test/unit/bootloader/config/grub2_test.py
-@@ -600,7 +600,6 @@ class TestBootLoaderConfigGrub2:
+@@ -629,7 +629,6 @@ class TestBootLoaderConfigGrub2:
+             'GRUB_BACKGROUND': '/boot/grub2/themes/openSUSE/background.png',
+             'GRUB_CMDLINE_LINUX_DEFAULT': '"some-cmdline"',
+             'GRUB_DISTRIBUTOR': '"Bob"',
+-            'GRUB_ENABLE_BLSCFG': 'true',
+             'GRUB_ENABLE_CRYPTODISK': 'y',
+             'GRUB_GFXMODE': '800x600',
+             'GRUB_SERIAL_COMMAND': '"serial --speed=38400"',
+@@ -677,7 +676,6 @@ class TestBootLoaderConfigGrub2:
              'GRUB_BACKGROUND': '/boot/grub2/themes/openSUSE/background.png',
              'GRUB_CMDLINE_LINUX_DEFAULT': '"some-cmdline"',
              'GRUB_DISTRIBUTOR': '"Bob"',
@@ -38,7 +36,7 @@ index e9189a609..d81d76ec7 100644
              'GRUB_ENABLE_CRYPTODISK': 'y',
              'GRUB_GFXMODE': '800x600',
              'GRUB_SERIAL_COMMAND': '"serial --speed=38400"',
-@@ -643,7 +642,6 @@ class TestBootLoaderConfigGrub2:
+@@ -720,7 +718,6 @@ class TestBootLoaderConfigGrub2:
              call('GRUB_CMDLINE_LINUX', '"root=LABEL=some-label"'),
              call('GRUB_DISABLE_LINUX_UUID', 'true'),
              call('GRUB_DISTRIBUTOR', '"Bob"'),
@@ -46,7 +44,7 @@ index e9189a609..d81d76ec7 100644
              call('GRUB_ENABLE_CRYPTODISK', 'y'),
              call('GRUB_ENABLE_LINUX_LABEL', 'true'),
              call('GRUB_GFXMODE', '800x600'),
-@@ -688,7 +686,6 @@ class TestBootLoaderConfigGrub2:
+@@ -765,7 +762,6 @@ class TestBootLoaderConfigGrub2:
              call('GRUB_DISABLE_LINUX_PARTUUID', 'false'),
              call('GRUB_DISABLE_LINUX_UUID', 'true'),
              call('GRUB_DISTRIBUTOR', '"Bob"'),
@@ -54,7 +52,7 @@ index e9189a609..d81d76ec7 100644
              call('GRUB_ENABLE_CRYPTODISK', 'y'),
              call('GRUB_GFXMODE', '800x600'),
              call(
-@@ -732,7 +729,6 @@ class TestBootLoaderConfigGrub2:
+@@ -809,7 +805,6 @@ class TestBootLoaderConfigGrub2:
              call('GRUB_CMDLINE_LINUX_DEFAULT', '"abcd console=tty0"'),
              call('GRUB_DISABLE_LINUX_UUID', 'true'),
              call('GRUB_DISTRIBUTOR', '"Bob"'),
@@ -62,6 +60,3 @@ index e9189a609..d81d76ec7 100644
              call('GRUB_ENABLE_CRYPTODISK', 'y'),
              call('GRUB_ENABLE_LINUX_LABEL', 'true'),
              call('GRUB_GFXMODE', '800x600'),
--- 
-2.44.0
-


Test patch:
diff --git a/test/unit/firmware_test.py b/test/unit/firmware_test.py
index 9a21d642..20a26b97 100644
--- a/test/unit/firmware_test.py
+++ b/test/unit/firmware_test.py
@@ -38,6 +38,9 @@ class TestFirmWare:
         xml_state.get_build_type_bootloader_targettype.return_value = 'CDL'
         self.firmware_s390_cdl = FirmWare(xml_state)
 
+        xml_state.get_build_type_bootloader_targettype.return_value = 'GPT'
+        self.firmware_s390_gpt = FirmWare(xml_state)
+
         xml_state.get_build_type_bootloader_targettype.return_value = 'SCSI'
         self.firmware_s390_scsi = FirmWare(xml_state)
 
@@ -67,6 +70,7 @@ class TestFirmWare:
         assert self.firmware_efi_mbr.get_partition_table_type() == 'msdos'
         assert self.firmware_s390_cdl.get_partition_table_type() == 'dasd'
         assert self.firmware_s390_scsi.get_partition_table_type() == 'msdos'
+        assert self.firmware_s390_gpt.get_partition_table_type() == 'gpt'
 
     def test_get_partition_table_type_ppc_ofw_mode(self):
         assert self.firmware_ofw.get_partition_table_type() == 'gpt'
diff --git a/test/unit/xml_state_test.py b/test/unit/xml_state_test.py
index dfaec639..da008005 100644
--- a/test/unit/xml_state_test.py
+++ b/test/unit/xml_state_test.py
@@ -1208,7 +1208,12 @@ class TestXMLState:
     @patch('kiwi.xml_parse.type_.get_bootloader')
     def test_get_build_type_bootloader_bls(self, mock_bootloader):
         mock_bootloader.return_value = [self.bootloader]
+        self.bootloader.get_bls.return_value = False
         assert self.state.get_build_type_bootloader_bls() is False
+        self.bootloader.get_bls.return_value = True
+        assert self.state.get_build_type_bootloader_bls() is True
+        self.bootloader.get_bls.return_value = None
+        assert self.state.get_build_type_bootloader_bls() is True
 
     @patch('kiwi.xml_parse.type_.get_bootloader')
     def test_get_build_type_bootloader_console(self, mock_bootloader):