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

yast / yast-bootloader / 15826763191

23 Jun 2025 02:16PM UTC coverage: 87.227% (-0.2%) from 87.386%
15826763191

push

github

web-flow
Merge pull request #719 from yast/dracut_dependency

Dracut dependency

3 of 3 new or added lines in 2 files covered. (100.0%)

35 existing lines in 5 files now uncovered.

3469 of 3977 relevant lines covered (87.23%)

12.83 hits per line

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

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

3
# File:
4
#      modules/BootSupportCheck.ycp
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

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

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

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

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

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

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

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

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

61
      supported
16✔
62
    end
63

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

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

74
  private
1✔
75

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

166
      return true if all_activate
7✔
167

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

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

175
      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✔
176
      false
7✔
177
    end
178

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

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

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

202
      ret.all?
12✔
203
    end
204

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

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

215
    # grub2-bls-related check
216
    def GRUB2BLS
1✔
217
      true
1✔
218
    end
219

220
    def stage1
1✔
221
      ::Bootloader::BootloaderFactory.current.stage1
44✔
222
    end
223

224
    def staging
1✔
UNCOV
225
      Y2Storage::StorageManager.instance.staging
×
226
    end
227
  end
228

229
  BootSupportCheck = BootSupportCheckClass.new
1✔
230
  BootSupportCheck.main
1✔
231
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

© 2025 Coveralls, Inc