diff --git a/src/Makefile.am b/src/Makefile.am index e1ae95890..3698d1116 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -74,6 +74,10 @@ ynclude5_DATA = \ include/bootloader/ppc/dialogs.rb \ include/bootloader/ppc/helps.rb +ylibdir = "${yast2dir}/lib/bootloader" +ylib_DATA = \ + lib/bootloader/grub2base.rb + scrconf_DATA = \ scrconf/cfg_bootloader.scr \ scrconf/cfg_bootsplash.scr \ diff --git a/src/lib/bootloader/grub2base.rb b/src/lib/bootloader/grub2base.rb new file mode 100644 index 000000000..9a62df588 --- /dev/null +++ b/src/lib/bootloader/grub2base.rb @@ -0,0 +1,134 @@ +# encoding: utf-8 +require "yast" + +module Yast + class GRUB2Base < Module + def main + Yast.import "UI" + + textdomain "bootloader" + + Yast.import "BootArch" + Yast.import "BootCommon" + Yast.import "BootStorage" + Yast.import "Kernel" + Yast.import "Mode" + Yast.import "Stage" + Yast.import "Storage" + Yast.import "StorageDevices" + Yast.import "Pkg" + Yast.import "HTML" + Yast.import "Initrd" + Yast.import "Product" + + # includes + # for simplified widgets than other + Yast.include self, "bootloader/grub2/dialogs.rb" + end + + # general functions + + # Propose global options of bootloader + def StandardGlobals + { + "timeout" => "8", + "default" => "0", + "vgamode" => "", + "gfxmode" => "auto", + "terminal" => "gfxterm", + "os_prober" => "true" + } + end + + # Update read settings to new version of configuration files + def Update + Read(true, true) + + #we don't handle sections, grub2 section create them for us + #BootCommon::UpdateSections (); + BootCommon.UpdateGlobals + + nil + end + + # Reset bootloader settings + # @param [Boolean] init boolean true to repropose also device map + def Reset(init) + return if Mode.autoinst + BootCommon.Reset(init) + + nil + end + + def Dialogs + Builtins.y2milestone("Called GRUB2 Dialogs") + { + "installation" => fun_ref( + method(:Grub2InstallDetailsDialog), + "symbol ()" + ), + "loader" => fun_ref( + method(:Grub2LoaderDetailsDialog), + "symbol ()" + ) + } + end + + def Propose + if BootCommon.was_proposed + # workaround autoyast config is Imported thus was_proposed always set + if Mode.autoinst + Builtins.y2milestone( + "autoinst mode we ignore meaningless was_proposed as it always set" + ) + else + Builtins.y2milestone( + "calling Propose with was_proposed set is really bogus, clear it to force a re-propose" + ) + return + end + end + + + if BootCommon.globals == nil || BootCommon.globals.empty? + BootCommon.globals = StandardGlobals() + else + BootCommon.globals |= StandardGlobals() + end + + swap_parts = BootCommon.getSwapPartitions + largest_swap_part = swap_parts.max_by{|part, size| size}.first || "" + + resume = BootArch.ResumeAvailable ? largest_swap_part : "" + # try to use label or udev id for device name... FATE #302219 + if resume != "" && resume != nil + resume = BootStorage.Dev2MountByDev(resume) + end + + BootCommon.globals["append"] = BootArch.DefaultKernelParams(resume) + BootCommon.globals["append_failsafe"] = BootArch.FailsafeKernelParams + BootCommon.globals["distributor"] = Product.name + BootCommon.kernelCmdLine = Kernel.GetCmdLine + + Builtins.y2milestone("Proposed globals: %1", BootCommon.globals) + + nil + end + + + + # Initializer of GRUB bootloader + def Initializer + Builtins.y2milestone("Called GRUB2 initializer") + BootCommon.current_bootloader_attribs = { + "propose" => false, + "read" => false, + "scratch" => false, + "restore_mbr" => false, + "bootloader_on_disk" => false + } + + nil + end + end +end diff --git a/src/modules/BootGRUB2.rb b/src/modules/BootGRUB2.rb index 72b6c88e9..9d32bd6b3 100644 --- a/src/modules/BootGRUB2.rb +++ b/src/modules/BootGRUB2.rb @@ -19,49 +19,21 @@ # $Id: BootGRUB.ycp 63508 2011-03-04 12:53:27Z jreidinger $ # require "yast" +require "bootloader/grub2base" module Yast - class BootGRUB2Class < Module + class BootGRUB2Class < GRUB2Base def main - Yast.import "UI" - - textdomain "bootloader" - - Yast.import "BootArch" - Yast.import "BootCommon" - Yast.import "BootStorage" - Yast.import "Kernel" - Yast.import "Mode" - Yast.import "Stage" - Yast.import "Storage" - Yast.import "StorageDevices" - Yast.import "Pkg" - Yast.import "HTML" - Yast.import "Initrd" - Yast.import "Product" + super # includes # for shared some routines with grub Yast.include self, "bootloader/grub2/misc.rb" - # for simplified widgets than other - Yast.include self, "bootloader/grub2/dialogs.rb" BootGRUB2() end # general functions - # Propose global options of bootloader - def StandardGlobals - { - "timeout" => "8", - "default" => "0", - "vgamode" => "", - "gfxmode" => "auto", - "terminal" => "gfxterm", - "os_prober" => "true" - } - end - # Read settings from disk # @param [Boolean] reread boolean true to force reread settings from system # @param [Boolean] avoid_reading_device_map do not read new device map from file, use @@ -109,16 +81,6 @@ def Read(reread, avoid_reading_device_map) ret end - # Update read settings to new version of configuration files - def Update - Read(true, true) - - #we don't handle sections, grub2 section create them for us - #BootCommon::UpdateSections (); - BootCommon.UpdateGlobals - - nil - end # Write bootloader settings to disk # @return [Boolean] true on success def Write @@ -141,87 +103,9 @@ def Write ret end - # Reset bootloader settings - # @param [Boolean] init boolean true to repropose also device map - def Reset(init) - return if Mode.autoinst - BootCommon.Reset(init) - - nil - end - - # Propose bootloader settings - def Propose - if BootCommon.was_proposed - # workaround autoyast config is Imported thus was_proposed always set - if Mode.autoinst - Builtins.y2milestone( - "autoinst mode we ignore meaningless was_proposed as it always set" - ) - else - Builtins.y2milestone( - "calling Propose with was_proposed set is really bogus, clear it to force a re-propose" - ) - return - end - end - - if BootCommon.globals == nil || Builtins.size(BootCommon.globals) == 0 - BootCommon.globals = StandardGlobals() - else - BootCommon.globals = Convert.convert( - Builtins.union(BootCommon.globals, StandardGlobals()), - :from => "map", - :to => "map " - ) - end - - grub_LocationProposal - - swap_sizes = BootCommon.getSwapPartitions - swap_parts = Builtins.maplist(swap_sizes) { |name, size| name } - swap_parts = Builtins.sort(swap_parts) do |a, b| - Ops.greater_than(Ops.get(swap_sizes, a, 0), Ops.get(swap_sizes, b, 0)) - end - - largest_swap_part = Ops.get(swap_parts, 0, "") - - resume = BootArch.ResumeAvailable ? largest_swap_part : "" - # try to use label or udev id for device name... FATE #302219 - if resume != "" && resume != nil - resume = BootStorage.Dev2MountByDev(resume) - end - Ops.set( - BootCommon.globals, - "append", - BootArch.DefaultKernelParams(resume) - ) - Ops.set( - BootCommon.globals, - "append_failsafe", - BootArch.FailsafeKernelParams - ) - Ops.set( - BootCommon.globals, - "distributor", - Ops.add(Ops.add(Product.short_name, " "), Product.version) - ) - BootCommon.kernelCmdLine = Kernel.GetCmdLine - - Builtins.y2milestone("Proposed globals: %1", BootCommon.globals) - - # Let grub2 scripts detects correct root= for us. :) - # BootCommon::globals["root"] = BootStorage::Dev2MountByDev(BootStorage::RootPartitionDevice); - - # We don't set vga= if Grub2 gfxterm enabled, because the modesettings - # will be delivered to kernel by Grub2's gfxpayload set to "keep" - #if (BootArch::VgaAvailable () && Kernel::GetVgaType () != "") - #{ - # BootCommon::globals["vgamode"] = Kernel::GetVgaType (); - #} - - nil + super + grub_LocationProposal if !BootCommon.was_proposed || !Mode.autoinst end # FATE#303643 Enable one-click changes in bootloader proposal @@ -369,20 +253,6 @@ def GetFunctions } end - # Initializer of GRUB bootloader - def Initializer - Builtins.y2milestone("Called GRUB2 initializer") - BootCommon.current_bootloader_attribs = { - "propose" => false, - "read" => false, - "scratch" => false, - "restore_mbr" => false, - "bootloader_on_disk" => false - } - - nil - end - # Constructor def BootGRUB2 Ops.set( diff --git a/src/modules/BootGRUB2EFI.rb b/src/modules/BootGRUB2EFI.rb index 1b4bbd31b..b08657318 100644 --- a/src/modules/BootGRUB2EFI.rb +++ b/src/modules/BootGRUB2EFI.rb @@ -19,49 +19,18 @@ # $Id: BootGRUB2EFI.ycp 63508 2011-03-04 12:53:27Z jreidinger $ # require "yast" +require "installation/grub2base" module Yast - class BootGRUB2EFIClass < Module + class BootGRUB2EFIClass < GRUB2Base def main - Yast.import "UI" + super - textdomain "bootloader" - - Yast.import "BootArch" - Yast.import "BootCommon" - Yast.import "BootStorage" - Yast.import "Kernel" - Yast.import "Mode" - Yast.import "Stage" - Yast.import "Storage" - Yast.import "StorageDevices" - Yast.import "Pkg" - Yast.import "HTML" - Yast.import "Initrd" - Yast.import "Product" - - # includes - # for shared some routines with grub - # include "bootloader/grub/misc.ycp"; - # for simplified widgets than other - Yast.include self, "bootloader/grub2/dialogs.rb" BootGRUB2EFI() end # general functions - # Propose global options of bootloader - def StandardGlobals - { - "timeout" => "8", - "default" => "0", - "vgamode" => "", - "gfxmode" => "auto", - "terminal" => "gfxterm", - "os_prober" => "true" - } - end - # Read settings from disk # @param [Boolean] reread boolean true to force reread settings from system # @param [Boolean] avoid_reading_device_map do not read new device map from file, use @@ -70,30 +39,7 @@ def StandardGlobals def Read(reread, avoid_reading_device_map) BootCommon.InitializeLibrary(reread, "grub2-efi") BootCommon.ReadFiles(avoid_reading_device_map) if reread - # TODO: check if necessary for grub2efi - # grub_DetectDisks (); - ret = BootCommon.Read(false, avoid_reading_device_map) - - # TODO: check if necessary for grub2 - # refresh device map if not read - # if (BootStorage::device_mapping == nil - # || size (BootStorage::device_mapping) == 0) - # { - # BootStorage::ProposeDeviceMap (); - # } - - ret - end - - # Update read settings to new version of configuration files - def Update - Read(true, true) - - #we don't handle sections, grub2 section create them for us - #BootCommon::UpdateSections (); - BootCommon.UpdateGlobals - - nil + BootCommon.Read(false, avoid_reading_device_map) end # Write bootloader settings to disk @@ -112,87 +58,6 @@ def Write ret end - # Reset bootloader settings - # @param [Boolean] init boolean true to repropose also device map - def Reset(init) - return if Mode.autoinst - BootCommon.Reset(init) - - nil - end - - # Propose bootloader settings - - def Propose - if BootCommon.was_proposed - # workaround autoyast config is Imported thus was_proposed always set - if Mode.autoinst - Builtins.y2milestone( - "autoinst mode we ignore meaningless was_proposed as it always set" - ) - else - Builtins.y2milestone( - "calling Propose with was_proposed set is really bogus, clear it to force a re-propose" - ) - return - end - end - - if BootCommon.globals == nil || Builtins.size(BootCommon.globals) == 0 - BootCommon.globals = StandardGlobals() - else - BootCommon.globals = Convert.convert( - Builtins.union(BootCommon.globals, StandardGlobals()), - :from => "map", - :to => "map " - ) - end - - swap_sizes = BootCommon.getSwapPartitions - swap_parts = Builtins.maplist(swap_sizes) { |name, size| name } - swap_parts = Builtins.sort(swap_parts) do |a, b| - Ops.greater_than(Ops.get(swap_sizes, a, 0), Ops.get(swap_sizes, b, 0)) - end - - largest_swap_part = Ops.get(swap_parts, 0, "") - - resume = BootArch.ResumeAvailable ? largest_swap_part : "" - # try to use label or udev id for device name... FATE #302219 - if resume != "" && resume != nil - resume = BootStorage.Dev2MountByDev(resume) - end - Ops.set( - BootCommon.globals, - "append", - BootArch.DefaultKernelParams(resume) - ) - Ops.set( - BootCommon.globals, - "append_failsafe", - BootArch.FailsafeKernelParams - ) - Ops.set( - BootCommon.globals, - "distributor", - Ops.add(Ops.add(Product.short_name, " "), Product.version) - ) - BootCommon.kernelCmdLine = Kernel.GetCmdLine - - Builtins.y2milestone("Proposed globals: %1", BootCommon.globals) - - # Let grub2 scripts detects correct root= for us. :) - # BootCommon::globals["root"] = BootStorage::Dev2MountByDev(BootStorage::RootPartitionDevice); - - # We don't set vga= if Grub2 gfxterm enabled, because the modesettings - # will be delivered to kernel by Grub2's gfxpayload set to "keep" - #if (BootArch::VgaAvailable () && Kernel::GetVgaType () != "") - #{ - # BootCommon::globals["vgamode"] = Kernel::GetVgaType (); - #} - - nil - end - # Display bootloader summary # @return a list of summary lines @@ -214,11 +79,6 @@ def Summary deep_copy(result) end - def Dialogs - Builtins.y2milestone("Called GRUB2 Dialogs") - { "loader" => fun_ref(method(:Grub2LoaderDetailsDialog), "symbol ()") } - end - # Return map of provided functions # @return a map of functions (eg. $["write":BootGRUB2EFI::Write]) def GetFunctions @@ -238,20 +98,6 @@ def GetFunctions end - # Initializer of GRUB2EFI bootloader - def Initializer - Builtins.y2milestone("Called GRUB2EFI initializer") - BootCommon.current_bootloader_attribs = { - "propose" => false, - "read" => false, - "scratch" => false, - "restore_mbr" => false, - "bootloader_on_disk" => false - } - - nil - end - # Constructor def BootGRUB2EFI Ops.set(