Class: Bootloader::Grub2
- Inherits:
-
Grub2Base
- Object
- BootloaderBase
- Grub2Base
- Bootloader::Grub2
- Defined in:
- src/lib/bootloader/grub2.rb
Overview
Represents non-EFI variant of GRUB2
Constant Summary
Instance Attribute Summary (collapse)
-
- (Object) device_map
readonly
Returns the value of attribute device_map.
-
- (Object) stage1
readonly
Returns the value of attribute stage1.
- - (Boolean) trusted_boot
Attributes inherited from Grub2Base
#grub_default, #password, #pmbr_action, #sections
Instance Method Summary (collapse)
-
- (Grub2) initialize
constructor
A new instance of Grub2.
- - (Object) merge(other)
- - (Object) name
- - (Object) packages
- - (Object) propose
-
- (Object) read
Read settings from disk, overwritting already set values.
-
- (Object) summary(simple_mode: false)
Display bootloader summary.
-
- (Boolean) write
Write bootloader settings to disk.
-
- (Object) write_sysconfig(prewrite: false)
FIXME: refactor with injection like super(prewrite: prewrite, sysconfig = …) overwrite BootloaderBase version to save trusted boot.
Methods inherited from Grub2Base
#disable_serial_console, #enable_serial_console, #pmbr_setup
Methods inherited from BootloaderBase
Constructor Details
- (Grub2) initialize
Returns a new instance of Grub2
23 24 25 26 27 28 29 30 31 |
# File 'src/lib/bootloader/grub2.rb', line 23 def initialize super textdomain "bootloader" @stage1 = Stage1.new @grub_install = GrubInstall.new(efi: false) @device_map = DeviceMap.new @trusted_boot = false end |
Instance Attribute Details
- (Object) device_map (readonly)
Returns the value of attribute device_map
19 20 21 |
# File 'src/lib/bootloader/grub2.rb', line 19 def device_map @device_map end |
- (Object) stage1 (readonly)
Returns the value of attribute stage1
18 19 20 |
# File 'src/lib/bootloader/grub2.rb', line 18 def stage1 @stage1 end |
- (Boolean) trusted_boot
21 22 23 |
# File 'src/lib/bootloader/grub2.rb', line 21 def trusted_boot @trusted_boot end |
Instance Method Details
- (Object) merge(other)
91 92 93 94 95 96 97 98 |
# File 'src/lib/bootloader/grub2.rb', line 91 def merge(other) super @device_map = other.device_map if !other.device_map.empty? @trusted_boot = other.trusted_boot unless other.trusted_boot.nil? stage1.merge(other.stage1) end |
- (Object) name
134 135 136 |
# File 'src/lib/bootloader/grub2.rb', line 134 def name "grub2" end |
- (Object) packages
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'src/lib/bootloader/grub2.rb', line 138 def packages res = super res << "grub2" # do not require it in insts-sys as insts-sys have it itself (bsc#1004229) if stage1.generic_mbr? && !Yast::Stage.initial # needed for generic _mbr binary files res << "syslinux" end if Yast::Arch.x86_64 || Yast::Arch.i386 res << "trustedgrub2" << "trustedgrub2-i386-pc" if @trusted_boot end res end |
- (Object) propose
80 81 82 83 84 85 86 87 88 89 |
# File 'src/lib/bootloader/grub2.rb', line 80 def propose super stage1.propose # for GPT add protective MBR flag otherwise some systems won't # boot, safer option for legacy booting (bnc#872054) self.pmbr_action = :add if Yast::BootStorage.gpt_boot_disk? device_map.propose if Yast::Arch.x86_64 || Yast::Arch.i386 @trusted_boot = false end |
- (Object) read
Read settings from disk, overwritting already set values
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'src/lib/bootloader/grub2.rb', line 34 def read super begin stage1.read rescue Errno::ENOENT # grub_installdevice is not part of grub2 rpm, so it doesn't need to exist. # In such case ignore exception and use empty @stage1 log.info "grub_installdevice does not exist. Using empty one." @stage1 = Stage1.new end begin # device map is needed only for legacy boot on intel device_map.read if Yast::Arch.x86_64 || Yast::Arch.i386 rescue Errno::ENOENT # device map is only optional part of grub2, so it doesn't need to exist. # In such case ignore exception and use empty device map log.info "grub2/device.map does not exist. Using empty one." @device_map = DeviceMap.new end @trusted_boot = Sysconfig.from_system.trusted_boot end |
- (Object) summary(simple_mode: false)
Display bootloader summary
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'src/lib/bootloader/grub2.rb', line 102 def summary(simple_mode: false) result = [ Yast::Builtins.sformat( _("Boot Loader Type: %1"), "GRUB2" ), Yast::Builtins.sformat( _("Enable Trusted Boot: %1"), @trusted_boot ? _("yes") : _("no") ) ] locations_val = locations if !locations_val.empty? result << Yast::Builtins.sformat( _("Status Location: %1"), locations_val.join(", ") ) end # it is necessary different summary for autoyast and installation # other mode than autoyast on running system # both ppc and s390 have special devices for stage1 so it do not make sense # allow change of location to MBR or boot partition (bnc#879107) no_location = simple_mode || Yast::Arch.ppc || Yast::Arch.s390 || Yast::Mode.config result << url_location_summary unless no_location order_sum = disk_order_summary result << order_sum unless order_sum.empty? result end |
- (Boolean) write
Write bootloader settings to disk
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'src/lib/bootloader/grub2.rb', line 61 def write # super have to called as first as grub install require some config writen in ancestor super device_map.write if Yast::Arch.x86_64 || Yast::Arch.i386 stage1.write # TODO: own class handling PBMR pmbr_setup(*gpt_disks_devices) # powernv must not call grub2-install (bnc#970582) unless Yast::Arch.board_powernv @grub_install.execute(devices: stage1.devices, trusted_boot: trusted_boot) end # Do some mbr activations ( s390 do not have mbr nor boot flag on its disks ) # powernv do not have prep partition, so we do not have any partition to activate (bnc#970582) MBRUpdate.new.run(stage1) if !Yast::Arch.s390 && !Yast::Arch.board_powernv end |
- (Object) write_sysconfig(prewrite: false)
FIXME: refactor with injection like super(prewrite: prewrite, sysconfig = …) overwrite BootloaderBase version to save trusted boot
158 159 160 161 |
# File 'src/lib/bootloader/grub2.rb', line 158 def write_sysconfig(prewrite: false) sysconfig = Bootloader::Sysconfig.new(bootloader: name, trusted_boot: @trusted_boot) prewrite ? sysconfig.pre_write : sysconfig.write end |