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

yast / yast-bootloader / 11817815252

13 Nov 2024 01:01PM UTC coverage: 87.695%. Remained the same
11817815252

push

github

schubi2
grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

rubocop

rubocop

grub2bls

grub2bls

grub2bls

sync text about secure boot on s390 to be correct (bsc#1219989)

make rubocop happy

rubocop

rubocop

fixed test cases

fixed test cases

grub2bls

grub2bls

grub2bls

grub2bls

grub2bls

rubocop

rubocop

rubocop

rubocop

rubocop

docu

added yast-bootloader

added yast-bootloader

93 of 100 new or added lines in 7 files covered. (93.0%)

64 existing lines in 6 files now uncovered.

3371 of 3844 relevant lines covered (87.7%)

13.03 hits per line

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

88.19
/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 "cfa/systemd_boot"
1✔
8
require "cfa/grub2/default"
1✔
9

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

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

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

24
    # @!attribute menu_timeout
25
    #   @return [Integer] menu timeout
26
    attr_accessor :menu_timeout
1✔
27

28
    # @!attribute secure_boot
29
    #   @return [Boolean] current secure boot setting
30
    attr_accessor :secure_boot
1✔
31

32
    def initialize
1✔
33
      super
65✔
34

35
      textdomain "bootloader"
65✔
36
      # For kernel parameters we are using the same data structure
37
      # like grub2 in order to be compatible with all calls.
38
      @kernel_container = ::CFA::Grub2::Default.new
65✔
39
      @explicit_cpu_mitigations = false
65✔
40
    end
41

42
    def kernel_params
1✔
43
      @kernel_container.kernel_params
31✔
44
    end
45

46
    # rubocop:disable Metrics/AbcSize
47
    def merge(other)
1✔
48
      log.info "merging: timeout: #{menu_timeout}=>#{other.menu_timeout}"
1✔
49
      log.info "         secure_boot: #{secure_boot}=>#{other.secure_boot}"
1✔
50
      log.info "         mitigations: #{cpu_mitigations.to_human_string}=>" \
1✔
51
               "#{other.cpu_mitigations.to_human_string}"
52
      log.info "         kernel_params: #{kernel_params.serialize}=>" \
1✔
53
               "#{other.kernel_params.serialize}"
54
      super
1✔
55
      self.menu_timeout = other.menu_timeout unless other.menu_timeout.nil?
1✔
56
      self.secure_boot = other.secure_boot unless other.secure_boot.nil?
1✔
57

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

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

65
      new_kernel_params = "#{kernel_serialize} #{other.kernel_params.serialize}"
1✔
66
      # deduplicate identicatel parameter. Keep always the last one ( so reverse is needed ).
67
      new_params = new_kernel_params.split.reverse.uniq.reverse.join(" ")
1✔
68

69
      @kernel_container.kernel_params.replace(new_params)
1✔
70

71
      # explicitly set mitigations means overwrite of our
72
      self.cpu_mitigations = other.cpu_mitigations if other.explicit_cpu_mitigations
1✔
73

74
      log.info "merging result: timeout: #{menu_timeout}"
1✔
75
      log.info "                secure_boot: #{secure_boot}"
1✔
76
      log.info "                mitigations: #{cpu_mitigations.to_human_string}"
1✔
77
      log.info "                kernel_params: #{kernel_params.serialize}"
1✔
78
    end
79
    # rubocop:enable Metrics/AbcSize
80

81
    def cpu_mitigations
1✔
82
      CpuMitigations.from_kernel_params(kernel_params)
6✔
83
    end
84

85
    def explicit_cpu_mitigations
1✔
86
      @explicit_cpu_mitigations ? cpu_mitigations : nil
1✔
87
    end
88

89
    def cpu_mitigations=(value)
1✔
90
      log.info "set mitigations to #{value.to_human_string}"
×
91
      @explicit_cpu_mitigations = true
×
92
      value.modify_kernel_params(kernel_params)
×
93
    end
94

95
    def read
1✔
96
      super
3✔
97

98
      read_menu_timeout
3✔
99
      self.secure_boot = Systeminfo.secure_boot_active?
3✔
100

101
      lines = ""
3✔
102
      filename = File.join(Yast::Installation.destdir, CMDLINE)
3✔
103
      if File.exist?(filename)
3✔
104
        File.open(filename).each do |line|
3✔
105
          lines = + line
3✔
106
        end
107
      end
108
      @kernel_container.kernel_params.replace(lines)
3✔
109
    end
110

111
    # Write bootloader settings to disk
112
    def write(etc_only: false)
1✔
113
      super
4✔
114
      log.info("Writing settings...")
4✔
115
      install_bootloader if Yast::Stage.initial # while new installation only (currently)
4✔
116
      create_menu_entries
4✔
117
      write_menu_timeout
4✔
118

119
      true
4✔
120
    end
121

122
    def propose
1✔
123
      super
3✔
124
      log.info("Propose settings...")
3✔
125
      if @kernel_container.kernel_params.empty?
3✔
126
        kernel_line = Yast::BootArch.DefaultKernelParams(Yast::BootStorage.propose_resume)
3✔
127
        @kernel_container.kernel_params.replace(kernel_line)
3✔
128
      end
129
      self.menu_timeout = Yast::ProductFeatures.GetIntegerFeature("globals", "boot_timeout").to_i
3✔
130
      self.secure_boot = Systeminfo.secure_boot_supported?
3✔
131
    end
132

133
    # Secure boot setting shown in summary screen.
134
    # sdbootutil intialize secure boot if shim has been installed.
135
    #
136
    # @return [String]
137
    def secure_boot_summary
1✔
138
      link = if secure_boot
2✔
139
        "<a href=\"disable_secure_boot\">(#{_("disable")})</a>"
×
140
      else
141
        "<a href=\"enable_secure_boot\">(#{_("enable")})</a>"
2✔
142
      end
143

144
      "#{_("Secure Boot:")} #{status_string(secure_boot)} #{link}"
2✔
145
    end
146

147
    # Display bootloader summary
148
    # @return a list of summary lines
149
    def summary(*)
1✔
150
      result = [
151
        Yast::Builtins.sformat(
2✔
152
          _("Boot Loader Type: %1"),
153
          "Systemd Boot"
154
        )
155
      ]
156
      result << secure_boot_summary if Systeminfo.secure_boot_available?(name)
2✔
157
      result
2✔
158
    end
159

160
    def name
1✔
161
      "systemd-boot"
11✔
162
    end
163

164
    def packages
1✔
165
      res = super
1✔
166
      res << "sdbootutil" << "systemd-boot"
1✔
167

168
      case Yast::Arch.architecture
1✔
169
      when "x86_64"
170
        res << "shim" if secure_boot
1✔
171
      else
172
        log.warn "Unknown architecture #{Yast::Arch.architecture} for systemdboot"
×
173
      end
174

175
      res
1✔
176
    end
177

178
    def delete
1✔
179
      log.warn("is currently not supported")
15✔
180
    end
181

182
    # overwrite BootloaderBase version to save secure boot
183
    def write_sysconfig(prewrite: false)
1✔
184
      sysconfig = Bootloader::Sysconfig.new(bootloader: name,
×
185
        secure_boot: secure_boot, trusted_boot: false,
186
        update_nvram: false)
187
      prewrite ? sysconfig.pre_write : sysconfig.write
×
188
    end
189

190
  private
1✔
191

192
    SDBOOTUTIL = "/usr/bin/sdbootutil"
1✔
193

194
    def write_kernel_parameter
1✔
195
      # writing kernel parameter to /etc/kernel/cmdline
196
      File.open(File.join(Yast::Installation.destdir, CMDLINE), "w+") do |fw|
4✔
197
        if Yast::Stage.initial # while new installation only
4✔
198
          fw.puts("root=#{Yast::BootStorage.root_partitions.first.name} #{kernel_params.serialize}")
4✔
199
        else # root entry is already available
200
          fw.puts(kernel_params.serialize)
×
201
        end
202
      end
203
    end
204

205
    def create_menu_entries
1✔
206
      write_kernel_parameter
4✔
207

208
      begin
209
        Yast::Execute.on_target!(SDBOOTUTIL, "--verbose", "add-all-kernels")
4✔
210
      rescue Cheetah::ExecutionFailed => e
UNCOV
211
        Yast::Report.Error(
×
212
          format(_(
213
                   "Cannot create systemd-boot menu entry:\n" \
214
                   "Command `%{command}`.\n" \
215
                   "Error output: %{stderr}"
216
                 ), command: e.commands.inspect, stderr: e.stderr)
217
        )
218
      end
219
    end
220

221
    def read_menu_timeout
1✔
222
      config = CFA::SystemdBoot.load
3✔
223
      return unless config.menu_timeout
3✔
224

UNCOV
225
      self.menu_timeout = if config.menu_timeout == "menu-force"
×
UNCOV
226
        -1
×
227
      else
UNCOV
228
        config.menu_timeout.to_i
×
229
      end
230
    end
231

232
    def write_menu_timeout
1✔
233
      config = CFA::SystemdBoot.load
4✔
234
      config.menu_timeout = if menu_timeout == -1
4✔
UNCOV
235
        "menu-force"
×
236
      else
237
        menu_timeout.to_s
4✔
238
      end
239
      config.save
4✔
240
    end
241

242
    def install_bootloader
1✔
243
      Yast::Execute.on_target!(SDBOOTUTIL, "--verbose",
4✔
244
        "install")
245
    rescue Cheetah::ExecutionFailed => e
UNCOV
246
      Yast::Report.Error(
×
247
      format(_(
248
               "Cannot install systemd bootloader:\n" \
249
               "Command `%{command}`.\n" \
250
               "Error output: %{stderr}"
251
             ), command: e.commands.inspect, stderr: e.stderr)
252
    )
UNCOV
253
      nil
×
254
    end
255
  end
256
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