• 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

93.65
/src/lib/bootloader/systemdboot.rb
1
# frozen_string_literal: true
2

3
require "fileutils"
1✔
4
require "yast"
1✔
5
require "bootloader/sysconfig"
1✔
6
require "bootloader/cpu_mitigations"
1✔
7
require "bootloader/bls"
1✔
8
require "bootloader/bls_sections"
1✔
9
require "cfa/grub2/default"
1✔
10

11
Yast.import "Report"
1✔
12
Yast.import "Arch"
1✔
13
Yast.import "ProductFeatures"
1✔
14
Yast.import "BootStorage"
1✔
15
Yast.import "Stage"
1✔
16

17
module Bootloader
1✔
18
  # Represents systemd bootloader with efi target
19
  class SystemdBoot < BootloaderBase
1✔
20
    include Yast::Logger
1✔
21
    include Yast::I18n
1✔
22

23
    CMDLINE = "/etc/kernel/cmdline"
1✔
24

25
    # @!attribute timeout
26
    #   @return [Integer] menu timeout
27
    attr_accessor :timeout
1✔
28
    alias_method :menu_timeout, :timeout # Agama compatible
1✔
29
    alias_method :menu_timeout=, :timeout= # Agama compatible
1✔
30

31
    # @!attribute secure_boot
32
    #   @return [Boolean] current secure boot setting
33
    attr_accessor :secure_boot
1✔
34

35
    attr_reader :sections
1✔
36

37
    # @!attribute pmbr_action
38
    #   @return [:remove, :add, :nothing]
39
    attr_accessor :pmbr_action
1✔
40

41
    def initialize
1✔
42
      super
62✔
43

44
      textdomain "bootloader"
62✔
45
      # For kernel parameters we are using the same data structure
46
      # like grub2 in order to be compatible with all calls.
47
      @kernel_container = ::CFA::Grub2::Default.new
62✔
48
      @explicit_cpu_mitigations = false
62✔
49
      @pmbr_action = :nothing
62✔
50
      @sections = ::Bootloader::BlsSections.new
62✔
51
    end
52

53
    def kernel_params
1✔
54
      @kernel_container.kernel_params
33✔
55
    end
56

57
    # rubocop:disable Metrics/AbcSize
58
    def merge(other)
1✔
59
      log.info "merging: timeout: #{timeout}=>#{other.timeout}"
1✔
60
      log.info "         secure_boot: #{secure_boot}=>#{other.secure_boot}"
1✔
61
      log.info "         mitigations: #{cpu_mitigations.to_human_string}=>" \
1✔
62
               "#{other.cpu_mitigations.to_human_string}"
63
      log.info "         pmbr_action: #{pmbr_action}=>#{other.pmbr_action}"
1✔
64
      log.info "         kernel_params: #{kernel_params.serialize}=>" \
1✔
65
               "#{other.kernel_params.serialize}"
66
      log.info "         default menu: #{@sections.default}=>" \
1✔
67
               "#{other.sections.default}"
68
      super
1✔
69
      self.timeout = other.timeout unless other.timeout.nil?
1✔
70
      self.secure_boot = other.secure_boot unless other.secure_boot.nil?
1✔
71
      self.pmbr_action = other.pmbr_action if other.pmbr_action
1✔
72

73
      kernel_serialize = kernel_params.serialize
1✔
74
      # handle specially noresume as it should lead to remove all other resume
75
      kernel_serialize.gsub!(/resume=\S+/, "") if other.kernel_params.parameter("noresume")
1✔
76

77
      # prevent double cpu_mitigations params
78
      kernel_serialize.gsub!(/mitigations=\S+/, "") if other.kernel_params.parameter("mitigations")
1✔
79

80
      new_kernel_params = "#{kernel_serialize} #{other.kernel_params.serialize}"
1✔
81
      # deduplicate identicatel parameter. Keep always the last one ( so reverse is needed ).
82
      new_params = new_kernel_params.split.reverse.uniq.reverse.join(" ")
1✔
83

84
      @kernel_container.kernel_params.replace(new_params)
1✔
85

86
      # explicitly set mitigations means overwrite of our
87
      self.cpu_mitigations = other.cpu_mitigations if other.explicit_cpu_mitigations
1✔
88

89
      @sections.default = other.sections.default if other.sections.default
1✔
90

91
      log.info "merging result: timeout: #{timeout}"
1✔
92
      log.info "                secure_boot: #{secure_boot}"
1✔
93
      log.info "                mitigations: #{cpu_mitigations.to_human_string}"
1✔
94
      log.info "                kernel_params: #{kernel_params.serialize}"
1✔
95
      log.info "                pmbr_action: #{pmbr_action}"
1✔
96
      log.info "                default menu: #{@sections.default}"
1✔
97
    end
98
    # rubocop:enable Metrics/AbcSize
99

100
    def cpu_mitigations
1✔
101
      CpuMitigations.from_kernel_params(kernel_params)
6✔
102
    end
103

104
    def explicit_cpu_mitigations
1✔
105
      @explicit_cpu_mitigations ? cpu_mitigations : nil
1✔
106
    end
107

108
    def cpu_mitigations=(value)
1✔
109
      log.info "set mitigations to #{value.to_human_string}"
×
110
      @explicit_cpu_mitigations = true
×
111
      value.modify_kernel_params(kernel_params)
×
112
    end
113

114
    def read
1✔
115
      super
3✔
116

117
      @sections.read
3✔
118
      self.timeout = Bls.menu_timeout
3✔
119
      self.secure_boot = Systeminfo.secure_boot_active?
3✔
120

121
      lines = ""
3✔
122
      filename = File.join(Yast::Installation.destdir, CMDLINE)
3✔
123
      if File.exist?(filename)
3✔
124
        File.open(filename).each do |line|
3✔
125
          lines = + line
3✔
126
        end
127
      end
128
      @kernel_container.kernel_params.replace(lines)
3✔
129
    end
130

131
    # Write bootloader settings to disk
132
    def write(etc_only: false)
1✔
133
      super
5✔
134
      log.info("Writing settings...")
5✔
135
      write_kernel_parameter
5✔
136
      if Yast::Stage.initial # while new installation only (currently)
5✔
137
        Bls.install_bootloader
5✔
138
        Bls.set_authentication
5✔
139
      end
140

141
      Bls.create_menu_entries
5✔
142
      Bls.write_menu_timeout(timeout)
5✔
143
      @sections.write
5✔
144
      Pmbr.write_efi(pmbr_action)
5✔
145

146
      true
5✔
147
    end
148

149
    def propose
1✔
150
      super
3✔
151
      log.info("Propose settings...")
3✔
152
      if @kernel_container.kernel_params.empty?
3✔
153
        kernel_line = Yast::BootArch.DefaultKernelParams(Yast::BootStorage.propose_resume)
3✔
154
        @kernel_container.kernel_params.replace(kernel_line)
3✔
155
      end
156
      self.timeout = Yast::ProductFeatures.GetIntegerFeature("globals", "boot_timeout").to_i
3✔
157
      self.secure_boot = Systeminfo.secure_boot_supported?
3✔
158
      # for UEFI always remove PMBR flag on disk (bnc#872054)
159
      self.pmbr_action = :remove
3✔
160
    end
161

162
    # Secure boot setting shown in summary screen.
163
    # sdbootutil intialize secure boot if shim has been installed.
164
    #
165
    # @return [String]
166
    def secure_boot_summary
1✔
167
      link = if secure_boot
2✔
UNCOV
168
        "<a href=\"disable_secure_boot\">(#{_("disable")})</a>"
×
169
      else
170
        "<a href=\"enable_secure_boot\">(#{_("enable")})</a>"
2✔
171
      end
172

173
      "#{_("Secure Boot:")} #{status_string(secure_boot)} #{link}"
2✔
174
    end
175

176
    # Display bootloader summary
177
    # @return a list of summary lines
178
    def summary(*)
1✔
179
      result = [
180
        Yast::Builtins.sformat(
2✔
181
          _("Boot Loader Type: %1"),
182
          "Systemd Boot"
183
        )
184
      ]
185
      result << secure_boot_summary if Systeminfo.secure_boot_available?(name)
2✔
186
      result
2✔
187
    end
188

189
    def name
1✔
190
      "systemd-boot"
12✔
191
    end
192

193
    def packages
1✔
194
      res = super
1✔
195
      res << "sdbootutil" << "systemd-boot"
1✔
196

197
      case Yast::Arch.architecture
1✔
198
      when "x86_64"
199
        res << "shim"
1✔
200
      else
UNCOV
201
        log.warn "Unknown architecture #{Yast::Arch.architecture} for systemdboot"
×
202
      end
203

204
      res
1✔
205
    end
206

207
    def delete
1✔
208
      log.warn("is currently not supported")
16✔
209
    end
210

211
    # overwrite BootloaderBase version to save secure boot
212
    def write_sysconfig(prewrite: false)
1✔
UNCOV
213
      sysconfig = Bootloader::Sysconfig.new(bootloader: name,
×
214
        secure_boot: secure_boot, trusted_boot: false,
215
        update_nvram: false)
UNCOV
216
      prewrite ? sysconfig.pre_write : sysconfig.write
×
217
    end
218

219
  private
1✔
220

221
    def write_kernel_parameter
1✔
222
      # writing kernel parameter to /etc/kernel/cmdline
223
      File.open(File.join(Yast::Installation.destdir, CMDLINE), "w+") do |fw|
5✔
224
        if Yast::Stage.initial # while new installation only
5✔
225
          fw.puts("root=#{Yast::BootStorage.root_partitions.first.name} #{kernel_params.serialize}")
5✔
226
        else # root entry is already available
UNCOV
227
          fw.puts(kernel_params.serialize)
×
228
        end
229
      end
230
    end
231
  end
232
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