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

yast / yast-bootloader / 22094328265

17 Feb 2026 10:10AM UTC coverage: 86.965% (+0.04%) from 86.922%
22094328265

push

github

schubi2
test

1 of 7 new or added lines in 1 file covered. (14.29%)

1 existing line in 1 file now uncovered.

3496 of 4020 relevant lines covered (86.97%)

12.83 hits per line

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

74.12
/src/lib/bootloader/bootloader_factory.rb
1
# frozen_string_literal: true
2

3
require "yast"
1✔
4
require "bootloader/sysconfig"
1✔
5
require "bootloader/none_bootloader"
1✔
6
require "bootloader/grub2"
1✔
7
require "bootloader/grub2efi"
1✔
8
require "bootloader/grub2bls"
1✔
9
require "bootloader/systemdboot"
1✔
10
require "bootloader/exceptions"
1✔
11
require "y2storage/disk_analyzer"
1✔
12

13
Yast.import "Arch"
1✔
14
Yast.import "Mode"
1✔
15
Yast.import "ProductFeatures"
1✔
16

17
module Bootloader
1✔
18
  # Factory to get instance of bootloader
19
  class BootloaderFactory
1✔
20
    SUPPORTED_BOOTLOADERS = [
1✔
21
      "none", # allows user to manage bootloader itself
22
      "grub2",
23
      "grub2-efi"
24
    ].freeze
25

26
    # Keyword used in autoyast for default bootloader used for given system.
27
    DEFAULT_KEYWORD = "default"
1✔
28
    SYSTEMDBOOT = "systemd-boot"
1✔
29
    GRUB2BLS = "grub2-bls"
1✔
30

31
    class << self
1✔
32
      include Yast::Logger
1✔
33

34
      attr_writer :current
1✔
35

36
      def proposed
1✔
37
        bootloader_by_name(proposed_name)
×
38
      end
39

40
      def system
1✔
41
        sysconfig_name = Sysconfig.from_system.bootloader
21✔
42
        return nil unless sysconfig_name
21✔
43

44
        bootloader_by_name(sysconfig_name)
2✔
45
      end
46

47
      def current
1✔
48
        @current ||= (system || proposed)
456✔
49
      end
50

51
      def current_name=(name)
1✔
52
        @current = bootloader_by_name(name)
246✔
53
      end
54

55
      def clear_cache
1✔
56
        @cached_bootloaders = nil
221✔
57
      end
58

59
      def supported_names
1✔
60
        if Yast::Mode.config
18✔
61
          # default means bootloader use what it think is the best
62
          result = BootloaderFactory::SUPPORTED_BOOTLOADERS.clone
×
63
          result << GRUB2BLS if use_grub2_bls?
×
64
          result << SYSTEMDBOOT if use_systemd_boot?
×
65
          result << DEFAULT_KEYWORD
×
66
          return result
×
67
        end
68

69
        begin
70
          system_bl = system.name
18✔
71
        # rescue exception if system one is not support
72
        rescue StandardError
73
          system_bl = nil
18✔
74
        end
75
        ret = system_bl ? [system.name] : [] # use current as first
18✔
76
        # grub2 everywhere except aarch64 or riscv64
77
        ret << "grub2" unless Systeminfo.efi_mandatory?
18✔
78
        ret << "grub2-efi" if Systeminfo.efi_supported?
18✔
79
        ret << GRUB2BLS if use_grub2_bls?
18✔
80
        ret << SYSTEMDBOOT if use_systemd_boot?
18✔
81
        ret << "none"
18✔
82
        # avoid double entry for selected one
83
        ret.uniq
18✔
84
      end
85

86
      # rubocop:disable Metrics/CyclomaticComplexity
87
      def bootloader_by_name(name)
1✔
88
        # needed to be able to store settings when moving between bootloaders
89
        @cached_bootloaders ||= {}
267✔
90
        case name
267✔
91
        when "grub2"
92
          @cached_bootloaders["grub2"] ||= Grub2.new
181✔
93
        when "grub2-efi"
94
          @cached_bootloaders["grub2-efi"] ||= Grub2EFI.new
12✔
95
        when "systemd-boot"
96
          @cached_bootloaders["systemd-boot"] ||= SystemdBoot.new
60✔
97
        when "grub2-bls"
98
          @cached_bootloaders["grub2-bls"] ||= Grub2Bls.new
4✔
99
        when "none"
100
          @cached_bootloaders["none"] ||= NoneBootloader.new
8✔
101
        when String
102
          raise UnsupportedBootloader, name
1✔
103
        else
104
          log.error "Factory receive nil name"
1✔
105

106
          nil # in other cases it means that read failed
1✔
107
        end
108
      end
109
    # rubocop:enable Metrics/CyclomaticComplexity
110

111
    private
1✔
112

113
      def use_systemd_boot?
1✔
114
        # only these architectures are supported.
115
        Yast::ProductFeatures.GetBooleanFeature("globals", "enable_systemd_boot") &&
18✔
116
          (Yast::Arch.x86_64 ||
16✔
117
           Yast::Arch.aarch64 ||
118
           Yast::Arch.arm ||
119
           Yast::Arch.riscv64)
120
      end
121

122
      def use_grub2_bls?
1✔
123
        # only these architectures are supported.
124
        (Yast::Arch.x86_64 ||
18✔
125
         Yast::Arch.aarch64 ||
126
         Yast::Arch.arm ||
127
         Yast::Arch.riscv64)
128
      end
129

130
      def grub2_efi_installable?
1✔
131
        Systeminfo.efi_mandatory? ||
×
132
          ((Yast::Arch.x86_64 || Yast::Arch.i386) && Systeminfo.efi?)
×
133
      end
134

135
      def bls_installable?(preferred_bootloader)
1✔
UNCOV
136
        staging = Y2Storage::StorageManager.instance.staging
×
NEW
137
        disk_ana = Y2Storage::DiskAnalyzer.new(staging)
×
NEW
138
        installed_systems = disk_ana.installed_systems()
×
NEW
139
        if installed_systems.size > 0 && preferred_bootloader == "grub2-bls"
×
NEW
140
          log.info("Installed system(s) #{installed_systems.inspect} will be kept." +
×
141
                   "So, grub2-bls should not be suggested due resulting disk space problems on boot partition.")
NEW
142
          return false
×
143
        end
144
        
145
        ((Yast::Arch.x86_64 ||
×
146
          Yast::Arch.i386 ||
147
          Yast::Arch.aarch64 ||
148
          Yast::Arch.arm ||
149
          Yast::Arch.riscv64) && Systeminfo.efi?)
150
      end
151

152
      def proposed_name
1✔
153
        preferred_bootloader = Yast::ProductFeatures.GetStringFeature("globals",
×
154
          "preferred_bootloader")
155
        if supported_names.include?(preferred_bootloader) &&
×
156
            !["grub2-efi", "systemd-boot", "grub2-bls"].include?(preferred_bootloader)
157
          return preferred_bootloader
×
158
        end
159

NEW
160
        if bls_installable?(preferred_bootloader) && ["systemd-boot", "grub2-bls"].include?(preferred_bootloader)
×
161
          return preferred_bootloader
×
162
        end
163

164
        return "grub2-efi" if grub2_efi_installable?
×
165

166
        "grub2" # grub2 works(c) everywhere
×
167
      end
168
    end
169
  end
170
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