• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yast / yast-bootloader / 22104545678

17 Feb 2026 03:29PM UTC coverage: 86.938%. Remained the same
22104545678

push

github

schubi2
fixed crash

0 of 1 new or added line in 1 file covered. (0.0%)

3501 of 4027 relevant lines covered (86.94%)

12.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.54
/src/modules/BootSupportCheck.rb
1
# frozen_string_literal: true
2

3
# File:
4
#      modules/BootSupportCheck.rb
5
#
6
# Module:
7
#      Bootloader installation and configuration
8
#
9
# Summary:
10
#      Check whether the current system setup is a supported configuration
11
#
12
# Authors:
13
#      Jiri Srain <jsrain@suse.cz>
14
#
15
require "yast"
1✔
16

17
require "bootloader/bootloader_factory"
1✔
18
require "y2storage/disk_analyzer"
1✔
19

20
module Yast
1✔
21
  class BootSupportCheckClass < Module
1✔
22
    include Yast::Logger
1✔
23

24
    def main
1✔
25
      textdomain "bootloader"
1✔
26

27
      Yast.import "Bootloader"
1✔
28
      Yast.import "Arch"
1✔
29
      Yast.import "BootStorage"
1✔
30
      Yast.import "FileUtils"
1✔
31
      Yast.import "Mode"
1✔
32

33
      # List of problems found during last check
34
      @detected_problems = []
1✔
35
    end
36

37
    # Check if the system configuraiton is supported
38
    # Also sets the founds problems into internal variable
39
    # Always run this function before calling DetectedProblems()
40
    # @return [Boolean] true if supported
41
    def SystemSupported
1✔
42
      @detected_problems = []
16✔
43

44
      lt = ::Bootloader::BootloaderFactory.current.name
16✔
45
      # detect correct bootloader type
46
      supported = correct_loader_type(lt)
16✔
47

48
      # check specifics for individual loaders
49
      case lt
16✔
50
      when "grub2"
51
        supported = GRUB2() && supported
12✔
52
      when "grub2-efi"
53
        supported = GRUB2EFI() && supported
1✔
54
      when "systemd-boot"
55
        supported = SYSTEMDBOOT() && supported
1✔
56
      when "grub2-bls"
57
        supported = GRUB2BLS() && supported
1✔
58
      end
59

60
      log.info "Configuration supported: #{supported}"
16✔
61

62
      supported
16✔
63
    end
64

65
    # Formated string of detected problems
66
    # Always run SystemSupported before calling this function
67
    # @return [Boolean] a list of problems, empty if no was found
68
    def StringProblems
1✔
69
      @detected_problems.join("\n")
7✔
70
    end
71

72
    publish :function => :StringProblems, :type => "string ()"
1✔
73
    publish :function => :SystemSupported, :type => "boolean ()"
1✔
74

75
  private
1✔
76

77
    # Add a new problem description to the list of found problems
78
    def add_new_problem(description)
1✔
79
      @detected_problems << description
18✔
80
    end
81

82
    # Check that bootloader matches current hardware
83
    def correct_loader_type(type)
1✔
84
      return true if type == "none"
16✔
85

86
      # grub2 is sooo cool...
87
      return true if type == "grub2" && !::Bootloader::Systeminfo.efi_mandatory?
15✔
88

89
      if (Arch.i386 || Arch.x86_64) && ["grub2-efi", "grub2-bls", "systemd-boot"].include?(type) && efi?
4✔
90
        return true
×
91
      end
92

93
      if ["grub2-efi", "grub2-bls", "systemd-boot"].include?(type) && ::Bootloader::Systeminfo.efi_mandatory?
4✔
94
        return true
×
95
      end
96

97
      log.error "Unsupported combination of hardware platform #{Arch.architecture} and bootloader #{type}"
4✔
98
      add_new_problem(
4✔
99
        Builtins.sformat(
100
          _("Unsupported combination of hardware platform %1 and bootloader %2"),
101
          Arch.architecture,
102
          type
103
        )
104
      )
105
      false
4✔
106
    end
107

108
    # when grub2 is used and install stage1 to MBR, target /boot is btrfs, label is gpt-like
109
    # then there must be special partition to install core.img, otherwise grub2-install failed
110
    def check_gpt_reserved_partition
1✔
111
      return true unless stage1.mbr?
11✔
112

113
      boot_fs = BootStorage.boot_filesystem
4✔
114
      gpt_disks = BootStorage.stage1_disks_for(boot_fs).select(&:gpt?)
4✔
115
      return true if gpt_disks.empty?
4✔
116
      return true if boot_fs.type != ::Y2Storage::Filesystems::Type::BTRFS
4✔
117
      # more relax check, at least one disk is enough. Let propose more advanced stuff like boot
118
      # duplicite md raid1 with bios_boot on all disks to storage and user. Check there only when
119
      # we are sure it is problem (bsc#1125792)
120
      return true if gpt_disks.any? { |disk| disk.partitions.any? { |p| p.id.is?(:bios_boot) } }
12✔
121

122
      Builtins.y2error("Used together boot from MBR, gpt, btrfs and without bios_grub partition.")
×
123
      # TRANSLATORS: description of technical problem. Do not translate technical terms unless native language have well known translation.
124
      add_new_problem(
×
125
        _(
126
          "Boot from MBR does not work together with Btrfs filesystem and GPT disk label\n" \
127
          "without bios_grub partition.\n\n" \
128
          "To fix this issue,\n\n" \
129
          " - create a bios_grub partition, or\n" \
130
          " - use any Ext filesystem for boot partition, or\n" \
131
          " - do not install stage 1 to MBR."
132
        )
133
      )
134
      false
×
135
    end
136

137
    # Check if boot partition exist
138
    # check if not on raid0
139
    #
140
    # @return [Boolean] true on success
141

142
    # Check if EFI is needed
143
    def efi?
1✔
144
      ::Bootloader::Systeminfo.efi?
×
145
    end
146

147
    def check_activate_partition
1✔
148
      # activate set
149
      return true if stage1.activate?
11✔
150

151
      # there is already activate flag
152
      disks = Yast::BootStorage.boot_disks
7✔
153

154
      # do not activate for ppc and GPT see bsc#983194
155
      return true if Arch.ppc64 && disks.all?(&:gpt?)
7✔
156

157
      all_activate = disks.all? do |disk|
7✔
158
        if disk.partition_table
7✔
159
          legacy_boot = disk.partition_table.partition_legacy_boot_flag_supported?
7✔
160

161
          disk.partitions.any? { |p| legacy_boot ? p.legacy_boot? : p.boot? }
28✔
162
        else
163
          false
×
164
        end
165
      end
166

167
      return true if all_activate
7✔
168

169
      add_new_problem(_("Activate flag is not set by installer. If it is not set at all, some BIOSes could refuse to boot."))
7✔
170
      false
7✔
171
    end
172

173
    def check_mbr
1✔
174
      return true if stage1.generic_mbr? || stage1.mbr?
11✔
175

176
      add_new_problem(_("The installer will not modify the MBR of the disk. Unless it already contains boot code, the BIOS won't be able to boot from this disk."))
7✔
177
      false
7✔
178
    end
179

180
    def check_fido2_tpm2
1✔
181
      ret = true
13✔
182
      devicegraph = Y2Storage::StorageManager.instance.staging
13✔
183
      devicegraph.encryptions&.each do |d|
13✔
184
        next unless d.method.id == :systemd_fde
×
185
        next if d.authentication.value == "password"
×
186

187
        add_new_problem(format(_("This bootloader cannot handle authentication " \
×
188
                                 "%{name} for device %{device}."),
189
          name: d.authentication.value, device: d.blk_device.name))
190
        ret = false
×
191
      end
192
      ret
13✔
193
    end
194

195
    # GRUB2-related check
196
    def GRUB2
1✔
197
      ret = []
12✔
198
      ret << check_gpt_reserved_partition if Arch.x86_64
12✔
199
      ret << check_activate_partition if Arch.x86_64 || Arch.ppc64
12✔
200
      ret << check_mbr if Arch.x86_64
12✔
201
      ret << check_fido2_tpm2
12✔
202

203
      ret.all?
12✔
204
    end
205

206
    # GRUB2EFI-related check
207
    def GRUB2EFI
1✔
208
      check_fido2_tpm2
1✔
209
    end
210

211
    # systemd-boot-related check
212
    def SYSTEMDBOOT
1✔
213
      true
1✔
214
    end
215

216
    # grub2-bls-related check
217
    def GRUB2BLS
1✔
218
        staging = Y2Storage::StorageManager.instance.staging
1✔
219
        disk_ana = Y2Storage::DiskAnalyzer.new(staging)
1✔
220
        installed_systems = disk_ana.installed_systems()
1✔
221
        if installed_systems.size > 0
1✔
NEW
222
          log.info(format(_"Installed system(s) %{systems} will be kept. " \
×
223
                           "So, grub2-bls should not be taken due disk space problems on boot partition."),
224
                   systems: installed_systems.join(",")
225
                  )
226
          return false
×
227
        end
228
      true
1✔
229
    end
230

231
    def stage1
1✔
232
      ::Bootloader::BootloaderFactory.current.stage1
44✔
233
    end
234

235
    def staging
1✔
236
      Y2Storage::StorageManager.instance.staging
×
237
    end
238
  end
239

240
  BootSupportCheck = BootSupportCheckClass.new
1✔
241
  BootSupportCheck.main
1✔
242
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc