Class: Bootloader::SystemdBoot
- Inherits:
-
BootloaderBase
- Object
- BootloaderBase
- Bootloader::SystemdBoot
- Includes:
- Yast::I18n, Yast::Logger
- Defined in:
- src/lib/bootloader/systemdboot.rb
Overview
Represents systemd bootloader with efi target
Constant Summary collapse
- CMDLINE =
"/etc/kernel/cmdline"
Instance Attribute Summary collapse
-
#menu_timeout ⇒ Integer
Menu timeout.
-
#secure_boot ⇒ Boolean
Current secure boot setting.
Instance Method Summary collapse
-
#cpu_mitigations ⇒ Object
rubocop:enable Metrics/AbcSize.
- #cpu_mitigations=(value) ⇒ Object
- #delete ⇒ Object
- #explicit_cpu_mitigations ⇒ Object
-
#initialize ⇒ SystemdBoot
constructor
A new instance of SystemdBoot.
- #kernel_params ⇒ Object
-
#merge(other) ⇒ Object
rubocop:disable Metrics/AbcSize.
- #name ⇒ Object
- #packages ⇒ Object
- #propose ⇒ Object
- #read ⇒ Object
-
#secure_boot_summary ⇒ String
Secure boot setting shown in summary screen.
- #status_string(status) ⇒ Object
-
#summary ⇒ Object
Display bootloader summary.
-
#write(etc_only: false) ⇒ Object
Write bootloader settings to disk.
-
#write_sysconfig(prewrite: false) ⇒ Object
overwrite BootloaderBase version to save secure boot.
Methods inherited from BootloaderBase
Constructor Details
#initialize ⇒ SystemdBoot
Returns a new instance of SystemdBoot.
32 33 34 35 36 37 38 39 40 |
# File 'src/lib/bootloader/systemdboot.rb', line 32 def initialize super textdomain "bootloader" # For kernel parameters we are using the same data structure # like grub2 in order to be compatible with all calls. @kernel_container = ::CFA::Grub2::Default.new @explicit_cpu_mitigations = false end |
Instance Attribute Details
#menu_timeout ⇒ Integer
Returns menu timeout.
26 27 28 |
# File 'src/lib/bootloader/systemdboot.rb', line 26 def @menu_timeout end |
#secure_boot ⇒ Boolean
Returns current secure boot setting.
30 31 32 |
# File 'src/lib/bootloader/systemdboot.rb', line 30 def secure_boot @secure_boot end |
Instance Method Details
#cpu_mitigations ⇒ Object
rubocop:enable Metrics/AbcSize
81 82 83 |
# File 'src/lib/bootloader/systemdboot.rb', line 81 def cpu_mitigations CpuMitigations.from_kernel_params(kernel_params) end |
#cpu_mitigations=(value) ⇒ Object
89 90 91 92 93 |
# File 'src/lib/bootloader/systemdboot.rb', line 89 def cpu_mitigations=(value) log.info "set mitigations to #{value.to_human_string}" @explicit_cpu_mitigations = true value.modify_kernel_params(kernel_params) end |
#delete ⇒ Object
186 187 188 |
# File 'src/lib/bootloader/systemdboot.rb', line 186 def delete log.warn("is currently not supported") end |
#explicit_cpu_mitigations ⇒ Object
85 86 87 |
# File 'src/lib/bootloader/systemdboot.rb', line 85 def explicit_cpu_mitigations @explicit_cpu_mitigations ? cpu_mitigations : nil end |
#kernel_params ⇒ Object
42 43 44 |
# File 'src/lib/bootloader/systemdboot.rb', line 42 def kernel_params @kernel_container.kernel_params end |
#merge(other) ⇒ Object
rubocop:disable Metrics/AbcSize
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'src/lib/bootloader/systemdboot.rb', line 47 def merge(other) log.info "merging: timeout: #{}=>#{other.}" log.info " secure_boot: #{secure_boot}=>#{other.secure_boot}" log.info " mitigations: #{cpu_mitigations.to_human_string}=>" \ "#{other.cpu_mitigations.to_human_string}" log.info " kernel_params: #{kernel_params.serialize}=>" \ "#{other.kernel_params.serialize}" super self. = other. unless other..nil? self.secure_boot = other.secure_boot unless other.secure_boot.nil? kernel_serialize = kernel_params.serialize # handle specially noresume as it should lead to remove all other resume kernel_serialize.gsub!(/resume=\S+/, "") if other.kernel_params.parameter("noresume") # prevent double cpu_mitigations params kernel_serialize.gsub!(/mitigations=\S+/, "") if other.kernel_params.parameter("mitigations") new_kernel_params = "#{kernel_serialize} #{other.kernel_params.serialize}" # deduplicate identicatel parameter. Keep always the last one ( so reverse is needed ). new_params = new_kernel_params.split.reverse.uniq.reverse.join(" ") @kernel_container.kernel_params.replace(new_params) # explicitly set mitigations means overwrite of our self.cpu_mitigations = other.cpu_mitigations if other.explicit_cpu_mitigations log.info "merging result: timeout: #{}" log.info " secure_boot: #{secure_boot}" log.info " mitigations: #{cpu_mitigations.to_human_string}" log.info " kernel_params: #{kernel_params.serialize}" end |
#name ⇒ Object
168 169 170 |
# File 'src/lib/bootloader/systemdboot.rb', line 168 def name "systemd-boot" end |
#packages ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'src/lib/bootloader/systemdboot.rb', line 172 def packages res = super res << "sdbootutil" << "systemd-boot" case Yast::Arch.architecture when "x86_64" res << "shim" if secure_boot else log.warn "Unknown architecture #{Yast::Arch.architecture} for systemdboot" end res end |
#propose ⇒ Object
122 123 124 125 126 127 128 129 130 131 |
# File 'src/lib/bootloader/systemdboot.rb', line 122 def propose super log.info("Propose settings...") if @kernel_container.kernel_params.empty? kernel_line = Yast::BootArch.DefaultKernelParams(Yast::BootStorage.propose_resume) @kernel_container.kernel_params.replace(kernel_line) end self. = Yast::ProductFeatures.GetIntegerFeature("globals", "boot_timeout").to_i self.secure_boot = Systeminfo.secure_boot_supported? end |
#read ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'src/lib/bootloader/systemdboot.rb', line 95 def read super self.secure_boot = Systeminfo.secure_boot_active? lines = "" filename = File.join(Yast::Installation.destdir, CMDLINE) if File.exist?(filename) File.open(filename).each do |line| lines = + line end end @kernel_container.kernel_params.replace(lines) end |
#secure_boot_summary ⇒ String
Secure boot setting shown in summary screen. sdbootutil intialize secure boot if shim has been installed.
145 146 147 148 149 150 151 152 153 |
# File 'src/lib/bootloader/systemdboot.rb', line 145 def secure_boot_summary link = if secure_boot "<a href=\"disable_secure_boot\">(#{_("disable")})</a>" else "<a href=\"enable_secure_boot\">(#{_("enable")})</a>" end "#{_("Secure Boot:")} #{status_string(secure_boot)} #{link}" end |
#status_string(status) ⇒ Object
133 134 135 136 137 138 139 |
# File 'src/lib/bootloader/systemdboot.rb', line 133 def status_string(status) if status _("enabled") else _("disabled") end end |
#summary ⇒ Object
Display bootloader summary
157 158 159 160 161 162 163 164 165 166 |
# File 'src/lib/bootloader/systemdboot.rb', line 157 def summary(*) result = [ Yast::Builtins.sformat( _("Boot Loader Type: %1"), "Systemd Boot" ) ] result << secure_boot_summary if Systeminfo.secure_boot_available?(name) result end |
#write(etc_only: false) ⇒ Object
Write bootloader settings to disk
112 113 114 115 116 117 118 119 120 |
# File 'src/lib/bootloader/systemdboot.rb', line 112 def write(etc_only: false) super log.info("Writing settings...") install_bootloader if Yast::Stage.initial # while new installation only (currently) true end |
#write_sysconfig(prewrite: false) ⇒ Object
overwrite BootloaderBase version to save secure boot
191 192 193 194 195 196 |
# File 'src/lib/bootloader/systemdboot.rb', line 191 def write_sysconfig(prewrite: false) sysconfig = Bootloader::Sysconfig.new(bootloader: name, secure_boot: secure_boot, trusted_boot: false, update_nvram: false) prewrite ? sysconfig.pre_write : sysconfig.write end |