Class: Bootloader::GrubInstall

Inherits:
Object
  • Object
show all
Includes:
Yast::I18n, Yast::Logger
Defined in:
src/lib/bootloader/grub_install.rb

Overview

Wraps grub install script for easier usage.

Instance Method Summary collapse

Constructor Details

#initialize(efi: false) ⇒ GrubInstall

Returns a new instance of GrubInstall.


16
17
18
19
20
# File 'src/lib/bootloader/grub_install.rb', line 16

def initialize(efi: false)
  @efi = efi
  @grub2_name = "grub2#{@efi ? "-efi" : ""}"
  textdomain "bootloader"
end

Instance Method Details

#execute(devices: [], secure_boot: false, trusted_boot: false, update_nvram: true) ⇒ Array<String>

Runs grub2 install command.

Parameters:

  • devices (Array<String>) (defaults to: [])

    list of devices where grub2 should be installed. Ignored when grub2 does not need device.

  • secure_boot (Boolean) (defaults to: false)

    if secure boot variant should be used

  • trusted_boot (Boolean) (defaults to: false)

    if trusted boot variant should be used

  • update_nvram (Boolean) (defaults to: true)

    if bootloader entry should be added to nvram

Returns:

  • (Array<String>)

    list of devices for which install failed


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'src/lib/bootloader/grub_install.rb', line 30

def execute(devices: [], secure_boot: false, trusted_boot: false, update_nvram: true)
  if secure_boot && !Systeminfo.secure_boot_available?(@grub2_name)
    # There might be some secure boot setting left over when the
    # bootloader had been switched.
    # Simply ignore it when it is not applicable instead of raising an
    # error.
    log.warn "Ignoring secure boot setting on this machine"
  end

  cmd = basic_cmd(secure_boot, trusted_boot, update_nvram)

  if no_device_install?
    Yast::Execute.on_target(cmd)

    if non_removable_efi?
      cmd.delete("--removable")
      Yast::Execute.on_target(cmd)
    end
    []
  else
    return [] if devices.empty?

    last_failure = nil
    res = devices.select do |device|

      Yast::Execute.on_target!(cmd + [device])
      false
    rescue Cheetah::ExecutionFailed => e
      log.warn "Failed to install grub to device #{device}. #{e.inspect}"
      last_failure = e
      true

    end

    # Failed to install to all devices
    report_failure(last_failure) if res.size == devices.size

    res
  end
end