Class: Bootloader::Grub2Bls
- Inherits:
-
Grub2Base
- Object
- BootloaderBase
- Grub2Base
- Bootloader::Grub2Bls
- Includes:
- Yast::I18n, Yast::Logger
- Defined in:
- src/lib/bootloader/grub2bls.rb
Overview
Represents grub2 bls bootloader with efi target
Constant Summary collapse
- CMDLINE =
"/etc/kernel/cmdline"
Instance Attribute Summary collapse
-
#sections ⇒ Object
readonly
Returns the value of attribute sections.
Attributes inherited from Grub2Base
#console, #grub_default, #password, #pmbr_action, #secure_boot, #stage1, #trusted_boot, #update_nvram
Instance Method Summary collapse
-
#initialize ⇒ Grub2Bls
constructor
A new instance of Grub2Bls.
-
#merge(other) ⇒ Object
merges other bootloader configuration into this one.
-
#name ⇒ Object
Bootloader name.
-
#packages ⇒ Array<String>
Packages required to configure given bootloader.
-
#propose ⇒ Object
Proposes new configuration.
-
#proposed? ⇒ Boolean
True if configuration is already proposed.
-
#read ⇒ Object
reads configuration from target disk rubocop:disable Metrics/AbcSize.
-
#read? ⇒ Boolean
True if configuration is already read.
-
#summary ⇒ Object
Display bootloader summary.
-
#write ⇒ Object
writes configuration to target disk.
-
#write_sysconfig(prewrite: false) ⇒ Object
overwrite BootloaderBase version to save secure boot.
Methods inherited from Grub2Base
#cpu_mitigations, #cpu_mitigations=, #disable_serial_console, #enable_serial_console, #explicit_cpu_mitigations, #include_os_prober_package?, #serial_console?
Methods inherited from BootloaderBase
Constructor Details
#initialize ⇒ Grub2Bls
Returns a new instance of Grub2Bls.
22 23 24 25 26 27 28 29 |
# File 'src/lib/bootloader/grub2bls.rb', line 22 def initialize super textdomain "bootloader" @sections = ::Bootloader::BlsSections.new @is_read = false @is_proposed = false end |
Instance Attribute Details
#sections ⇒ Object (readonly)
Returns the value of attribute sections.
18 19 20 |
# File 'src/lib/bootloader/grub2bls.rb', line 18 def sections @sections end |
Instance Method Details
#merge(other) ⇒ Object
merges other bootloader configuration into this one. It have to be same bootloader type. rubocop:disable Metrics/AbcSize
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'src/lib/bootloader/grub2bls.rb', line 122 def merge(other) raise "Invalid merge argument #{other.name} for #{name}" if name != other.name log.info "merging: timeout: #{grub_default.timeout}=>#{other.grub_default.timeout}" log.info " mitigations: #{cpu_mitigations.to_human_string}=>" \ "#{other.cpu_mitigations.to_human_string}" log.info " pmbr_action: #{pmbr_action}=>#{other.pmbr_action}" log.info " secure boot: #{other.secure_boot}" log.info " update_nvram: #{update_nvram}=>#{other.update_nvram}" log.info " grub_default.kernel_params: #{grub_default.kernel_params.serialize}=>" \ "#{other.grub_default.kernel_params.serialize}" log.info " grub_default.kernel_params: #{grub_default.kernel_params.serialize}=>" \ "#{other.grub_default.kernel_params.serialize}" merge_sections(other) merge_grub_default(other) merge_pmbr_action(other) self.secure_boot = other.secure_boot unless other.secure_boot.nil? self.update_nvram = other.update_nvram unless other.update_nvram.nil? log.info "merging result: timeout: #{grub_default.timeout}" log.info " mitigations: #{cpu_mitigations.to_human_string}" log.info " kernel_params: #{grub_default.kernel_params.serialize}" log.info " pmbr_action: #{pmbr_action}" log.info " secure boot: #{secure_boot}" log.info " update_nvram: #{update_nvram}" end |
#name ⇒ Object
Returns bootloader name.
46 47 48 |
# File 'src/lib/bootloader/grub2bls.rb', line 46 def name "grub2-bls" end |
#packages ⇒ Array<String>
Returns packages required to configure given bootloader.
152 153 154 155 156 157 158 |
# File 'src/lib/bootloader/grub2bls.rb', line 152 def packages res = super res << ("grub2-" + grub2bls_architecture + "-efi-bls") res << "sdbootutil" res << "shim" if Systeminfo.secure_boot_supported? res end |
#propose ⇒ Object
Proposes new configuration
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'src/lib/bootloader/grub2bls.rb', line 81 def propose log.info("Propose settings...") if grub_default.kernel_params.empty? kernel_line = Yast::BootArch.DefaultKernelParams(Yast::BootStorage.propose_resume) grub_default.kernel_params.replace(kernel_line) end grub_default.timeout = Yast::ProductFeatures.GetIntegerFeature("globals", "boot_timeout").to_i self.secure_boot = Systeminfo.secure_boot_supported? @is_proposed = true # for UEFI always remove PMBR flag on disk (bnc#872054) self.pmbr_action = :remove end |
#proposed? ⇒ Boolean
Returns true if configuration is already proposed.
95 96 97 |
# File 'src/lib/bootloader/grub2bls.rb', line 95 def proposed? @is_proposed end |
#read ⇒ Object
reads configuration from target disk rubocop:disable Metrics/AbcSize
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'src/lib/bootloader/grub2bls.rb', line 52 def read @sections.read grub_default.timeout = Bls. log.info "Boot timeout: #{grub_default.timeout}" lines = "" filename = File.join(Yast::Installation.destdir, CMDLINE) if File.exist?(filename) File.open(filename).each do |line| lines = + line end end self.secure_boot = Systeminfo.secure_boot_active? self.update_nvram = Systeminfo.update_nvram_active? grub_default.kernel_params.replace(lines) log.info "kernel params: #{grub_default.kernel_params}" log.info "bls sections: #{@sections.all}" log.info "bls default: #{@sections.default}" log.info "secure boot: #{secure_boot}" log.info "update nvram: #{update_nvram}" @is_read = true # flag that settings has been read end |
#read? ⇒ Boolean
Returns true if configuration is already read.
76 77 78 |
# File 'src/lib/bootloader/grub2bls.rb', line 76 def read? @is_read end |
#summary ⇒ Object
Display bootloader summary
33 34 35 36 37 38 39 40 41 42 43 |
# File 'src/lib/bootloader/grub2bls.rb', line 33 def summary(*) result = [ Yast::Builtins.sformat( _("Boot Loader Type: %1"), "GRUB2 BLS" ) ] result << secure_boot_summary if Systeminfo.secure_boot_available?(name) result << update_nvram_summary if Systeminfo.nvram_available?(name) result end |
#write ⇒ Object
writes configuration to target disk
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'src/lib/bootloader/grub2bls.rb', line 100 def write(*) # writing kernel parameter to /etc/kernel/cmdline File.open(File.join(Yast::Installation.destdir, CMDLINE), "w+") do |fw| fw.puts(grub_default.kernel_params.serialize) end if Yast::Stage.initial # while new installation only Bls.install_bootloader Bls. Bls.set_authentication else Bls.update_bootloader end @sections.write Bls.(grub_default.timeout) Pmbr.write_efi(pmbr_action) end |
#write_sysconfig(prewrite: false) ⇒ Object
overwrite BootloaderBase version to save secure boot
161 162 163 164 165 166 |
# File 'src/lib/bootloader/grub2bls.rb', line 161 def write_sysconfig(prewrite: false) sysconfig = Bootloader::Sysconfig.new(bootloader: name, secure_boot: secure_boot, trusted_boot: false, update_nvram: update_nvram) prewrite ? sysconfig.pre_write : sysconfig.write end |