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

yast / yast-bootloader / 6034222431

31 Aug 2023 07:10AM UTC coverage: 87.597%. First build
6034222431

Pull #686

github

schubi2
fixed typo; added docu
Pull Request #686: Systemd boot feature

735 of 735 new or added lines in 15 files covered. (100.0%)

3171 of 3620 relevant lines covered (87.6%)

12.98 hits per line

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

86.52
/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

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

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

21
    # @!attribute menue_timeout
22
    #   @return [Integer] menue timeout
23
    attr_accessor :menue_timeout
1✔
24

25
    # @!attribute secure_boot
26
    #   @return [Boolean] current secure boot setting
27
    attr_accessor :secure_boot
1✔
28

29
    def initialize
1✔
30
      super
39✔
31

32
      textdomain "bootloader"
39✔
33
    end
34

35
    def merge(other)
1✔
36
      log.info "merging with system: timeout=#{other.menue_timeout} " \
1✔
37
               "secure_boot=#{other.secure_boot}"
38
      super
1✔
39
      self.menue_timeout = other.menue_timeout unless other.menue_timeout.nil?
1✔
40
      self.secure_boot = other.secure_boot unless other.secure_boot.nil?
1✔
41
    end
42

43
    def read
1✔
44
      super
1✔
45

46
      read_menue_timeout
1✔
47
      self.secure_boot = Systeminfo.secure_boot_active?
1✔
48
    end
49

50
    # Write bootloader settings to disk
51
    def write(etc_only: false)
1✔
52
      super
1✔
53
      log.info("Writing settings...")
1✔
54
      if Yast::Stage.initial # while new installation only (currently)
1✔
55
        install_bootloader
1✔
56
        create_menue_entries
1✔
57
      end
58
      write_menue_timeout
1✔
59

60
      true
1✔
61
    end
62

63
    def propose
1✔
64
      super
×
65
      log.info("Propose settings...")
×
66
      self.menue_timeout = Yast::ProductFeatures.GetIntegerFeature("globals", "boot_timeout").to_i
×
67
      self.secure_boot = Systeminfo.secure_boot_supported?
×
68
    end
69

70
    def status_string(status)
1✔
71
      if status
2✔
72
        _("enabled")
×
73
      else
74
        _("disabled")
2✔
75
      end
76
    end
77

78
    # Secure boot setting shown in summary screen.
79
    # sdbootutil intialize secure boot if shim has been installed.
80
    #
81
    # @return [String]
82
    def secure_boot_summary
1✔
83
      link = if secure_boot
2✔
84
        "<a href=\"disable_secure_boot\">(#{_("disable")})</a>"
×
85
      else
86
        "<a href=\"enable_secure_boot\">(#{_("enable")})</a>"
2✔
87
      end
88

89
      "#{_("Secure Boot:")} #{status_string(secure_boot)} #{link}"
2✔
90
    end
91

92
    # Display bootloader summary
93
    # @return a list of summary lines
94
    def summary(*)
1✔
95
      result = [
96
        Yast::Builtins.sformat(
2✔
97
          _("Boot Loader Type: %1"),
98
          "Systemd Boot"
99
        )
100
      ]
101
      result << secure_boot_summary if Systeminfo.secure_boot_available?(name)
2✔
102
      result
2✔
103
    end
104

105
    def name
1✔
106
      "systemd-boot"
11✔
107
    end
108

109
    def packages
1✔
110
      res = super
1✔
111
      res << "sdbootutil" << "systemd-boot"
1✔
112

113
      case Yast::Arch.architecture
1✔
114
      when "x86_64"
115
        res << "shim" if secure_boot
1✔
116
      else
117
        log.warn "Unknown architecture #{Yast::Arch.architecture} for systemdboot"
×
118
      end
119

120
      res
1✔
121
    end
122

123
    def delete
1✔
124
      log.warn("is currently not supported")
12✔
125
    end
126

127
    # overwrite BootloaderBase version to save secure boot
128
    def write_sysconfig(prewrite: false)
1✔
129
      sysconfig = Bootloader::Sysconfig.new(bootloader: name,
×
130
        secure_boot: secure_boot, trusted_boot: false,
131
        update_nvram: false)
132
      prewrite ? sysconfig.pre_write : sysconfig.write
×
133
    end
134

135
  private
1✔
136

137
    SDBOOTUTIL = "/usr/bin/sdbootutil"
1✔
138

139
    def create_menue_entries
1✔
140
      cmdline_file = File.join(Yast::Installation.destdir, "/etc/kernel/cmdline")
1✔
141
      if Yast::Stage.initial
1✔
142
        # sdbootutil script needs the "root=<device>" entry in kernel parameters.
143
        # This will be written to /etc/kernel/cmdline which will be used in an
144
        # installed system by the administrator only. So we can use it because
145
        # the system will be installed new. This file will be deleted after
146
        # calling sdbootutil.
147
        File.open(cmdline_file, "w+") do |fw|
1✔
148
          fw.puts("root=#{Yast::BootStorage.root_partitions.first.name}")
1✔
149
        end
150
      end
151
      begin
152
        Yast::Execute.on_target!(SDBOOTUTIL, "--verbose", "add-all-kernels")
1✔
153
      rescue Cheetah::ExecutionFailed => e
154
        Yast::Report.Error(
×
155
          format(_(
156
                   "Cannot create systemd-boot menue entry:\n" \
157
                   "Command `%{command}`.\n" \
158
                   "Error output: %{stderr}"
159
                 ), command: e.commands.inspect, stderr: e.stderr)
160
        )
161
      end
162
      File.delete(cmdline_file) if Yast::Stage.initial # see above
1✔
163
    end
164

165
    def read_menue_timeout
1✔
166
      config = CFA::SystemdBoot.load
1✔
167
      self.menue_timeout = config.menue_timeout.to_i if config.menue_timeout
1✔
168
    end
169

170
    def write_menue_timeout
1✔
171
      config = CFA::SystemdBoot.load
1✔
172
      config.menue_timeout = menue_timeout.to_s
1✔
173
      config.save
1✔
174
    end
175

176
    def install_bootloader
1✔
177
      Yast::Execute.on_target!(SDBOOTUTIL, "--verbose",
1✔
178
        "install")
179
    rescue Cheetah::ExecutionFailed => e
180
      Yast::Report.Error(
×
181
      format(_(
182
               "Cannot install systemd bootloader:\n" \
183
               "Command `%{command}`.\n" \
184
               "Error output: %{stderr}"
185
             ), command: e.commands.inspect, stderr: e.stderr)
186
    )
187
      nil
×
188
    end
189
  end
190
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