Module: Yast::BootloaderGrub2MiscInclude

Includes:
Logger
Defined in:
src/include/bootloader/grub2/misc.rb

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) gpt_boot_disk?

Returns:

  • (Boolean)


77
78
79
80
81
# File 'src/include/bootloader/grub2/misc.rb', line 77

def gpt_boot_disk?
  targets = BootCommon.GetBootloaderDevices
  boot_discs = targets.map { |d| Storage.GetDisk(Storage.GetTargetMap, d) }
  boot_discs.any? { |d| d["label"] == "gpt" }
end

- (String) grub_ConfigureLocation

grub_ConfigureLocation() Where to install the bootloader. Returns the type of device where to install: one of bootroot mbrextended `mbr_md Also sets the boot_* keys in the internal global variable globals accordingly.

Returns:

  • (String)

    type of location proposed to bootloader



73
74
75
# File 'src/include/bootloader/grub2/misc.rb', line 73

def grub_ConfigureLocation
  ::Bootloader::Stage1.new.propose
end

- (Object) grub_DetectDisks

Detect “/boot”, “/” (root), extended partition device and MBR disk device

If no bootloader device has been set up yet (globals), or the first (FIXME(!)) device is not available as a boot partition, also call grub_ConfigureLocation to configure globals and set the globals and globals flags if needed all these settings are stored in internal variables



90
91
92
93
94
95
96
97
98
99
100
101
# File 'src/include/bootloader/grub2/misc.rb', line 90

def grub_DetectDisks
  location_reconfigure = BootStorage.detect_disks

  return if location_reconfigure == :ok
  # if already proposed, then empty location is intention of user
  if location_reconfigure == :empty && BootCommon.was_proposed
    # in auto install we do not allow empty boot locations
    return unless Mode.auto
  end

  grub_ConfigureLocation
end

- (Object) grub_LocationProposal

Propose the boot loader location for grub - if no proposal has been made, collects the devices for “/”, “/boot”, MBR and makes a new proposal - if no device mapping exists, creates a device mapping - if the devices that were somehow (proposal, user interface) selected for bootloader installation do not match the current partitioning any more (e.g. “/boot” partition was selected but is not available anymore (and “/” did not move there), “/” was selected but has moved, etc.), then also re-collect the devices for “/”, “/boot”, MBR and make a new proposal



112
113
114
115
116
117
118
119
120
121
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'src/include/bootloader/grub2/misc.rb', line 112

def grub_LocationProposal
  log.info "globals: #{BootCommon.globals}"
  log.info "Mode #{Mode.mode}"
  no_boot_key = ["boot_boot", "boot_root", "boot_mbr", "boot_extended", "boot_custom"].none? do |k|
    BootCommon.globals[k]
  end
  if !BootCommon.was_proposed ||
      # During autoinstall, the autoyast profile must contain a bootloader
      # device specification (we currently really only support system
      # *cloning* with autoyast...). But as a convenience, and because
      # this kind of magic is available for empty globals and sections, we
      # propose a bootloader location if none was specified.
      # Note that "no bootloader device" can be specified by explicitly
      # setting this up, e.g. by setting one or all boot_* flags to
      # "false".
      (Mode.autoinst || Mode.autoupgrade) && no_boot_key
    grub_DetectDisks
    # check whether edd is loaded; if not: load it
    edd_loaded = SCR.Read(path(".proc.modules"))["edd"]
    log.info "edd loaded? #{edd_loaded.inspect}"
    if !edd_loaded
      command = "/sbin/modprobe edd"
      out = SCR.Execute(path(".target.bash_output"), command)
      log.info "Command '#{command}' output: #{out}"
    end
    redundant_devices = BootStorage.devices_for_redundant_boot
    BootCommon.globals["boot_md_mbr"] = redundant_devices.join(",") unless redundant_devices.empty?
  end
  log.info "(2) globals: #{BootCommon.globals}"

  # refresh device map
  if BootStorage.device_map.empty?  ||
      BootCommon.cached_settings_base_data_change_time !=
          Storage.GetTargetChangeTime &&
          # bnc#585824 - Bootloader doesn't use defined device map from autoyast
          !((Mode.autoinst || Mode.autoupgrade) &&
            BootCommon.cached_settings_base_data_change_time.nil?)
    BootStorage.device_map.propose
    BootCommon.InitializeLibrary(true, "grub2")
  end

  if !Mode.autoinst && !Mode.autoupgrade
    changes = ::Bootloader::DiskChangeDetector.new.changes
    if !changes.empty?
      log.info "Location change detected"
      if BootCommon.askLocationResetPopup(changes.join("\n"))
        reset_bootloader_device
        Builtins.y2milestone("Reconfiguring locations")
        grub_DetectDisks
      end
    end
  end

  nil
end

- (Object) initialize_bootloader_grub2_misc(_include_target)



31
32
33
34
35
36
37
38
39
40
41
42
# File 'src/include/bootloader/grub2/misc.rb', line 31

def initialize_bootloader_grub2_misc(_include_target)
  textdomain "bootloader"
  Yast.import "Arch"
  Yast.import "BootCommon"
  Yast.import "BootStorage"
  Yast.import "Map"
  Yast.import "Mode"
  Yast.import "PackageSystem"
  Yast.import "Partitions"
  Yast.import "Storage"
  Yast.import "StorageDevices"
end

- (Object) reset_bootloader_device

Set “boot_*” flags in the globals map according to the boot device selected with parameter selected_location. Only a single boot device can be selected with this function. The function cannot be used to set a custom boot device. It will always be deleted.

FIXME: `mbr_md is probably unneeded; AFA we can see, this decision is automatic anyway and perl-Bootloader should be able to make it without help from the user or the proposal.

Parameters:

  • selected_location (Symbol)

    symbol one of bootroot mbrextended mbr_mdnone



58
59
60
61
62
63
64
65
# File 'src/include/bootloader/grub2/misc.rb', line 58

def reset_bootloader_device
  # first, default to all off:
  ["boot_boot", "boot_root", "boot_mbr", "boot_extended"].each do |flag|
    BootCommon.globals[flag] = "false"
  end
  # need to remove the boot_custom key to switch this value off
  BootCommon.globals.delete("boot_custom")
end