Skip to content

Commit

Permalink
grub2bls
Browse files Browse the repository at this point in the history
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
  • Loading branch information
schubi2 committed Nov 13, 2024
1 parent 7f1e6e2 commit 299e572
Show file tree
Hide file tree
Showing 17 changed files with 815 additions and 1,192 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Metrics/BlockLength:

# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 30 # TODO this should be lower for new code
Max: 31 # TODO this should be lower for new code
Include:
- 'src/lib/**/*.rb' # be more strict for new code in lib

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ that holds and also can propose the bootloader implementation. So now let's expl

- [GRUB2](https://www.rubydoc.info/github/yast/yast-bootloader/master/Bootloader/Grub2) for legacy booting or emulated grub2 boot like s390x.
- [GRUB2-EFI](https://www.rubydoc.info/github/yast/yast-bootloader/master/Bootloader/Grub2EFI) for EFI variant of GRUB2 bootloader
- [GRUB2-BLS](https://www.rubydoc.info/github/yast/yast-bootloader/master/Bootloader/Grub2Bls) bootloader based on Boot Loader Specification(BLS) (for EFI only)
- [systemd-boot](https://www.rubydoc.info/github/yast/yast-bootloader/master/Bootloader/SystemdBoot) systemd bootloader (for EFI only)
- [None](https://www.rubydoc.info/github/yast/yast-bootloader/master/Bootloader/NoneBootloader) when YaST does not manage booting
- [GRUB2 base](https://www.rubydoc.info/github/yast/yast-bootloader/master/Bootloader/Grub2Base) is the shared functionality for both GRUB2 implementations
Expand Down
1,490 changes: 446 additions & 1,044 deletions doc/bootloader_backend.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 13 additions & 11 deletions src/lib/bootloader/autoyast_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ def import(data)

case bootloader.name
when "grub2", "grub2-efi", "grub2-bls"
import_grub2(data, bootloader)
import_grub2efi(data, bootloader)
import_stage1(data, bootloader)
if ["grub2", "grub2-efi"].include?(bootloader.name)
import_grub2(data, bootloader)
import_grub2efi(data, bootloader)
import_stage1(data, bootloader)
import_device_map(data, bootloader)
import_password(data, bootloader)
# always nil pmbr as autoyast does not support it yet,
# so use nil to always use proposed value (bsc#1081967)
bootloader.pmbr_action = nil
end
import_default(data, bootloader.grub_default)
import_device_map(data, bootloader)
import_password(data, bootloader)
# always nil pmbr as autoyast does not support it yet,
# so use nil to always use proposed value (bsc#1081967)
bootloader.pmbr_action = nil
cpu_mitigations = data.global.cpu_mitigations
if cpu_mitigations
bootloader.cpu_mitigations = CpuMitigations.from_string(cpu_mitigations)
Expand Down Expand Up @@ -75,9 +77,9 @@ def export(config)
when "grub2", "grub2-efi", "grub2-bls"
global = res["global"]
export_grub2(global, config) if config.name == "grub2"
export_grub2efi(global, config) if ["grub2-efi", "grub2-bls"].include?(config.name)
export_grub2efi(global, config) if config.name == "grub2-efi"
export_password(global, config.password) if ["grub2", "grub2-efi"].include?(config.name)
export_default(global, config.grub_default)
export_password(global, config.password)
res["global"]["cpu_mitigations"] = config.cpu_mitigations.value.to_s
when "systemd-boot"
res["global"]["timeout"] = config.menu_timeout
Expand Down Expand Up @@ -106,7 +108,7 @@ def import_grub2(data, bootloader)
end

def import_grub2efi(data, bootloader)
return unless ["grub2-efi", "grub2-bls"].include?(bootloader.name)
return unless bootloader.name == "grub2-efi"

GRUB2EFI_BOOLEAN_MAPPING.each do |key, method|
val = data.global.public_send(key)
Expand Down
34 changes: 18 additions & 16 deletions src/lib/bootloader/bls_sections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def default=(value)
# writes default to system making it persistent
def write
return if @default.empty?
write_default()

write_default
end

def read
Expand All @@ -51,43 +52,44 @@ def read
end

private
OS_RELEASE_PATH = "/etc/os-release".freeze

OS_RELEASE_PATH = "/etc/os-release"

def grubenv_path
str = Yast::Misc.CustomSysconfigRead("ID_LIKE", "openSUSE",
OS_RELEASE_PATH)
os = str.split(" ").first
return File.join(Yast::Installation.destdir,
"/boot/efi/EFI/", os, "/grubenv")
OS_RELEASE_PATH)
os = str.split.first
File.join("/boot/efi/EFI/", os, "/grubenv")
end

# @return [String] return default boot as string or "" if not set
# or something goes wrong
def read_default
Yast::Misc.CustomSysconfigRead("default", "",
grubenv_path)
grubenv_path)
end

# write default entry
def write_default
ret = Yast::Execute.on_target("/usr/bin/sdbootutil",
"set-default", @default,
allowed_exitstatus: [0, 1])
if ret != 0 # fallback directly over grub2-editenv
Yast::Execute.on_target("/usr/bin/grub2-editenv", grubenv_path,
"set", "default="+@default)
end
"set-default", @default,
allowed_exitstatus: [0, 1])

return unless ret != 0

# fallback directly over grub2-editenv
Yast::Execute.on_target("/usr/bin/grub2-editenv", grubenv_path,
"set", "default=" + @default)
end

# @return [Array] return array of entries or []
# @return [Array] return array of entries or []
def read_entries
output = Yast::Execute.on_target(
"/usr/bin/bootctl", "--json=short", "list" ,stdout: :capture
"/usr/bin/bootctl", "--json=short", "list", stdout: :capture
)
return [] if output.nil?

JSON.parse(output)
end

end
end
5 changes: 4 additions & 1 deletion src/lib/bootloader/bootloader_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
module Bootloader
# Represents base for all kinds of bootloaders
class BootloaderBase
include Yast::I18n

def initialize
textdomain "bootloader"

@read = false
@proposed = false
@initial_sysconfig = Sysconfig.from_system
Expand Down Expand Up @@ -121,6 +125,5 @@ def status_string(status)
_("disabled")
end
end

end
end
2 changes: 1 addition & 1 deletion src/lib/bootloader/bootloader_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def use_systemd_boot?
end

def use_grub2_bls?
(Yast::Arch.x86_64 || Yast::Arch.aarch64) # only these architectures are supported.
(Yast::Arch.x86_64 || Yast::Arch.aarch64) # only these architectures are supported.
end

def grub2_efi_installable?
Expand Down
3 changes: 0 additions & 3 deletions src/lib/bootloader/generic_widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ def localized_names(name)
names[name] or raise "Unknown supported bootloader '#{name}'"
end

# rubocop:disable Metrics/MethodLength
# It will be reduced again if systemd-boot is not anymore in beta phase.
def handle
old_bl = BootloaderFactory.current.name
new_bl = value
Expand Down Expand Up @@ -88,7 +86,6 @@ def handle
:redraw
end

# rubocop:enable Metrics/MethodLength
def help
_(
"<p><b>Boot Loader</b>\n" \
Expand Down
48 changes: 24 additions & 24 deletions src/lib/bootloader/grub2_widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,14 @@ def init
end

def store
if !@hidden_menu_widget.is_a?(CWM::Empty)
if @hidden_menu_widget.checked?
grub_default.hidden_timeout = value.to_s
grub_default.timeout = "0"
else
grub_default.hidden_timeout = "0"
grub_default.timeout = value.to_s
end
if @hidden_menu_widget.is_a?(CWM::Empty)
grub_default.timeout = value.to_s
elsif @hidden_menu_widget.checked?
grub_default.hidden_timeout = value.to_s
grub_default.timeout = "0"
else
grub_default.timeout = value.to_s
grub_default.hidden_timeout = "0"
grub_default.timeout = value.to_s
end
end
end
Expand Down Expand Up @@ -355,7 +353,8 @@ def store
end

def validate
return true if Yast::Mode.config || !value || ["grub2-efi", "grub2-bls"].include?(grub2.name)
return true if Yast::Mode.config || !value || ["grub2-efi",
"grub2-bls"].include?(grub2.name)

tpm_files = Dir.glob("/sys/**/pcrs")
if !tpm_files.empty? && !File.read(tpm_files[0], 1).nil?
Expand Down Expand Up @@ -982,10 +981,10 @@ def label
end

def contents
if (Yast::Arch.s390 || grub2.name=="grub2-bls")
console_widget = CWM::Empty.new("console")
console_widget = if Yast::Arch.s390 || grub2.name == "grub2-bls"
CWM::Empty.new("console")
else
console_widget = ConsoleWidget.new
ConsoleWidget.new
end
VBox(
VSpacing(1),
Expand Down Expand Up @@ -1064,7 +1063,7 @@ def loader_location_widget?
end

def generic_mbr_widget?
(Yast::Arch.x86_64 || Yast::Arch.i386) && !(["grub2-efi", "grub2-bls"].include?(grub2.name))
(Yast::Arch.x86_64 || Yast::Arch.i386) && !["grub2-efi", "grub2-bls"].include?(grub2.name)
end

def secure_boot_widget?
Expand All @@ -1086,26 +1085,26 @@ def pmbr_widget?
end

def device_map_button?
(Yast::Arch.x86_64 || Yast::Arch.i386) && !(["grub2-efi", "grub2-bls"].include?(grub2.name))
(Yast::Arch.x86_64 || Yast::Arch.i386) && !["grub2-efi", "grub2-bls"].include?(grub2.name)
end
end

# Represents bootloader specific options like its timeout,
# default section or password protection
class BootloaderTab < CWM::Tab
include Grub2Helper

def label
textdomain "bootloader"

_("Boot&loader Options")
end

def contents
if grub2.name != "grub2-bls"
hidden_menu_widget = HiddenMenuWidget.new
hidden_menu_widget = if grub2.name == "grub2-bls"
CWM::Empty.new("hidden_menu")
else
hidden_menu_widget = CWM::Empty.new("hidden_menu")
HiddenMenuWidget.new
end
VBox(
VSpacing(2),
Expand All @@ -1121,24 +1120,25 @@ def contents
HSpacing(1)
),
VSpacing(1),
MarginBox(1, 1, MinWidth(1,DefaultSectionWidget.new)),
MarginBox(1, 1, MinWidth(1, DefaultSectionWidget.new)),
MarginBox(1, 1, grub_password_widget),
VStretch()
)
end

private

def grub_password_widget
if grub2.name != "grub2-bls"
GrubPasswordWidget.new
else
if grub2.name == "grub2-bls"
CWM::Empty.new("password_widget")
else
GrubPasswordWidget.new
end
end

def os_prober_widget
if OsProber.available? && # Checks !Arch.s390 and if package is available
grub2.name != "grub2-bls"
grub2.name != "grub2-bls"
Left(OSProberWidget.new)
else
CWM::Empty.new("os_prober")
Expand Down
1 change: 0 additions & 1 deletion src/lib/bootloader/grub2base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ def update_nvram_summary

"#{_("Update NVRAM:")} #{status_string(update_nvram)} #{link}"
end

end
# rubocop:enable Metrics/ClassLength
end
Loading

0 comments on commit 299e572

Please sign in to comment.