Class: Bootloader::BootloaderBase

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

Overview

Represents base for all kinds of bootloaders

Direct Known Subclasses

Grub2Base, NoneBootloader, SystemdBoot

Instance Method Summary collapse

Constructor Details

#initializeBootloaderBase

Returns a new instance of BootloaderBase.



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

def initialize
  textdomain "bootloader"

  @read = false
  @proposed = false
  @initial_sysconfig = Sysconfig.from_system
end

Instance Method Details

#merge(other) ⇒ Object

merges other bootloader configuration into this one. It have to be same bootloader type.



98
99
100
101
102
103
# File 'src/lib/bootloader/bootloader_base.rb', line 98

def merge(other)
  raise "Invalid merge argument #{other.name} for #{name}" if name != other.name

  @read ||= other.read?
  @proposed ||= other.proposed? # rubocop:disable Naming/MemoizedInstanceVariableName
end

#packagesArray<String>

Returns packages required to configure given bootloader.

Returns:

  • (Array<String>)

    packages required to configure given bootloader



79
80
81
82
83
84
85
86
87
# File 'src/lib/bootloader/bootloader_base.rb', line 79

def packages
  # require dracut to have initrd to be able to boot
  res = ["dracut"]

  # added kexec-tools fate#303395
  res << "kexec-tools" if include_kexec_tools_package?

  res
end

#prepareBoolean

Prepares the system to (before write the configuration)

Writes the new sysconfig and, when the Mode.normal is set, tries to install the required packages. If user decides to cancel the installation, it restores the previous sysconfig.

Returns:

  • (Boolean)

    true whether the system could be prepared as expected; false when user cancel the installation of needed packages



31
32
33
34
35
36
37
38
39
40
# File 'src/lib/bootloader/bootloader_base.rb', line 31

def prepare
  write_sysconfig

  return true unless Yast::Mode.normal
  return true if Yast::Package.InstallAll(packages)

  restore_initial_sysconfig

  false
end

#proposeObject

Proposes new configuration



59
60
61
# File 'src/lib/bootloader/bootloader_base.rb', line 59

def propose
  @proposed = true
end

#proposed?Boolean

Returns true if configuration is already proposed.

Returns:

  • (Boolean)

    true if configuration is already proposed



74
75
76
# File 'src/lib/bootloader/bootloader_base.rb', line 74

def proposed?
  @proposed
end

#readObject

reads configuration from target disk



54
55
56
# File 'src/lib/bootloader/bootloader_base.rb', line 54

def read
  @read = true
end

#read?Boolean

Returns true if configuration is already read.

Returns:

  • (Boolean)

    true if configuration is already read



69
70
71
# File 'src/lib/bootloader/bootloader_base.rb', line 69

def read?
  @read
end

#summaryArray<String>

Returns description for proposal summary page for given bootloader.

Returns:

  • (Array<String>)

    description for proposal summary page for given bootloader



64
65
66
# File 'src/lib/bootloader/bootloader_base.rb', line 64

def summary
  []
end

#write(etc_only: false) ⇒ Object

writes configuration to target disk

Parameters:

  • etc_only (Boolean) (defaults to: false)

    true on transactional systems because /boot is read-only there



45
46
47
48
49
50
51
# File 'src/lib/bootloader/bootloader_base.rb', line 45

def write(etc_only: false)
  return if etc_only

  # reset eventl. already installed systemd bootloader
  systemd_boot = BootloaderFactory.bootloader_by_name("systemd-boot")
  systemd_boot&.delete
end

#write_sysconfig(prewrite: false) ⇒ Object

done in common write but also in installation pre write as kernel update need it

Parameters:

  • prewrite (Boolean) (defaults to: false)

    true only in installation when scr is not yet switched



91
92
93
94
# File 'src/lib/bootloader/bootloader_base.rb', line 91

def write_sysconfig(prewrite: false)
  sysconfig = Bootloader::Sysconfig.new(bootloader: name)
  prewrite ? sysconfig.pre_write : sysconfig.write
end