Skip to content

Commit

Permalink
Merge f0bacb4 into 352c28b
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Nov 5, 2020
2 parents 352c28b + f0bacb4 commit de45e80
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Expand Up @@ -8,7 +8,7 @@ Metrics/AbcSize:
- 'src/lib/**/*.rb' # be more strict for new code in lib

Metrics/AbcSize:
Max: 30
Max: 35
Include:
- 'src/lib/**/*.rb' # be more strict for new code in lib

Expand Down
9 changes: 9 additions & 0 deletions package/yast2-bootloader.changes
@@ -1,3 +1,12 @@
-------------------------------------------------------------------
Thu Nov 5 21:48:43 UTC 2020 - Josef Reidinger <jreidinger@suse.com>

- Improve wording in summary to see where boot code is written
(jsc#SLE-16033)
- allow to specify extended or logical partition when boot from
partition (bsc#1165042)
- 4.3.14

-------------------------------------------------------------------
Thu Oct 22 12:53:21 UTC 2020 - Josef Reidinger <jreidinger@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-bootloader.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-bootloader
Version: 4.3.13
Version: 4.3.14
Release: 0
Summary: YaST2 - Bootloader Configuration
License: GPL-2.0-or-later
Expand Down
47 changes: 44 additions & 3 deletions src/lib/bootloader/grub2.rb
Expand Up @@ -110,8 +110,8 @@ def summary(simple_mode: false)

locations_val = locations
if !locations_val.empty?
result << Yast::Builtins.sformat(
_("Status Location: %1"),
result << format(
_("Write Boot Code To: %s"),
locations_val.join(", ")
)
end
Expand Down Expand Up @@ -193,6 +193,12 @@ def locations

partition_location = Yast::BootStorage.boot_partitions.map(&:name).join(", ")
locations << partition_location + _(" (/boot)") if stage1.boot_partition?
if stage1.extended_boot_partition?
partitions = Yast::BootStorage.boot_partitions.map do |partition|
Yast::BootStorage.extended_for_logical(partition).name
end
locations << partitions.join(", ") + _(" (/boot)")
end
if stage1.mbr?
# TRANSLATORS: MBR is acronym for Master Boot Record, if nothing locally specific
# is used in your language, then keep it as it is.
Expand Down Expand Up @@ -229,6 +235,34 @@ def partition_line
end
end

def logical_partition_line
if stage1.boot_partition?
_(
"Install boot code into a logical partition with /boot " \
"(<a href=\"disable_boot_boot\">do not install</a>)"
)
else
_(
"Do not install boot code into a logical partition with /boot " \
"(<a href=\"enable_boot_boot\">install</a>)"
)
end
end

def extended_partition_line
if stage1.extended_boot_partition?
_(
"Install boot code into a extended partition with /boot " \
"(<a href=\"disable_boot_extended\">do not install</a>)"
)
else
_(
"Do not install boot code into a extended partition with /boot " \
"(<a href=\"enable_boot_extended\">install</a>)"
)
end
end

# FATE#303643 Enable one-click changes in bootloader proposal
#
#
Expand All @@ -241,7 +275,14 @@ def url_location_summary
# do not allow to switch on boot from partition that do not support it
if stage1.can_use_boot?
line << "<li>"
line << partition_line
if stage1.logical_boot?
line << extended_partition_line
line << "</li>"
line << "<li>"
line << logical_partition_line
else
line << partition_line
end
line << "</li>"
end

Expand Down
16 changes: 15 additions & 1 deletion src/lib/bootloader/grub2_widgets.rb
Expand Up @@ -843,6 +843,12 @@ def handle(event)

def init
Yast::UI.ChangeWidget(Id(:boot), :Value, stage1.boot_partition?) if locations.include?(:boot)
if locations.include?(:logical)
Yast::UI.ChangeWidget(Id(:logical), :Value, stage1.boot_partition?)
end
if locations.include?(:extended)
Yast::UI.ChangeWidget(Id(:extended), :Value, stage1.extended_boot_partition?)
end
Yast::UI.ChangeWidget(Id(:mbr), :Value, stage1.mbr?) if locations.include?(:mbr)

init_custom_devices(stage1.custom_devices)
Expand All @@ -854,8 +860,10 @@ def store
next unless Yast::UI.QueryWidget(Id(id), :Value)

case id
when :boot
when :boot, :logical
stage1.boot_partition_names.each { |d| stage1.add_udev_device(d) }
when :extended
stage1.extended_boot_partitions_names.each { |d| stage1.add_udev_device(d) }
when :mbr
stage1.boot_disk_names.each { |d| stage1.add_udev_device(d) }
end
Expand Down Expand Up @@ -903,6 +911,12 @@ def locations
def location_checkboxes
checkboxes = []
checkboxes << checkbox(:boot, _("Boo&t from Partition")) if locations.include?(:boot)
if locations.include?(:logical)
checkboxes << checkbox(:logical, _("Boo&t from Logical Partition"))
end
if locations.include?(:extended)
checkboxes << checkbox(:extended, _("Boot from &Extended Partition"))
end
checkboxes << checkbox(:mbr, _("Boot from &Master Boot Record")) if locations.include?(:mbr)

checkboxes.concat(custom_partition_content)
Expand Down
11 changes: 9 additions & 2 deletions src/lib/bootloader/proposal_client.rb
Expand Up @@ -75,6 +75,8 @@ def initialize
"disable_boot_mbr",
"enable_boot_boot",
"disable_boot_boot",
"enable_boot_extended",
"disable_boot_extended",
"enable_secure_boot",
"disable_secure_boot",
"enable_trusted_boot",
Expand Down Expand Up @@ -341,15 +343,20 @@ def handle_errors(ret)
nil
end

CLICK_MAPPING = {
"boot_mbr" => :boot_disk_names,
"boot_boot" => :boot_partition_names,
"boot_extended" => :extended_boot_partitions_names
}.freeze
def single_click_action(option, value)
bootloader = ::Bootloader::BootloaderFactory.current

log.info "single_click_action: option #{option}, value #{value.inspect}"

case option
when "boot_mbr", "boot_boot"
when "boot_mbr", "boot_boot", "boot_extended"
stage1 = bootloader.stage1
devices = (option == "boot_mbr") ? stage1.boot_disk_names : stage1.boot_partition_names
devices = stage1.public_send(CLICK_MAPPING[option])
log.info "single_click_action: devices #{devices}"
devices.each do |device|
value ? stage1.add_udev_device(device) : stage1.remove_device(device)
Expand Down
42 changes: 35 additions & 7 deletions src/lib/bootloader/stage1.rb
Expand Up @@ -65,8 +65,13 @@ def available_locations
case Yast::Arch.architecture
when "i386", "x86_64"
res = [:mbr]
res << :boot if can_use_boot?
res
return res unless can_use_boot?

if logical_boot?
res << :logical << :extended
else
res << :boot
end
else
log.info "no available non-custom location for arch #{Yast::Arch.architecture}"

Expand Down Expand Up @@ -116,8 +121,31 @@ def mbr?
include_real_devs?(boot_disk_names)
end

def logical_boot?
detect_devices

@boot_objects.any? { |p| p.is?(:partition) && p.type.is?(:logical) }
end

def extended_boot_partitions_names
@boot_objects.map do |device|
dev = if device.is?(:partition) && device.type.is?(:logical)
Yast::BootStorage.extended_for_logical(device)
else
device
end
dev.name
end
end

def extended_boot_partition?
return false if boot_partition_names == extended_boot_partitions_names

include_real_devs?(extended_boot_partitions_names)
end

def custom_devices
known_devices = boot_disk_names + boot_partition_names
known_devices = boot_disk_names + boot_partition_names + extended_boot_partitions_names
log.info "known devices #{known_devices.inspect}"

devices.reject do |dev|
Expand Down Expand Up @@ -212,11 +240,11 @@ def detect_devices
# check if cache is valid
return if @cache_revision == Y2Storage::StorageManager.instance.staging_revision

devices = Yast::BootStorage.boot_partitions
@boot_devices = devices.map(&:name)
@boot_objects = Yast::BootStorage.boot_partitions
@boot_devices = @boot_objects.map(&:name)

devices = Yast::BootStorage.boot_disks
@mbr_devices = devices.map(&:name)
@mbr_objects = Yast::BootStorage.boot_disks
@mbr_devices = @mbr_objects.map(&:name)

@cache_revision = Y2Storage::StorageManager.instance.staging_revision
end
Expand Down
2 changes: 0 additions & 2 deletions src/modules/BootStorage.rb
Expand Up @@ -176,8 +176,6 @@ def stage1_partitions_for(device)
end
end

# now replace all logical partitions for extended
partitions.map! { |p| extended_for_logical(p) }
partitions.uniq!

log.info "stage1 partitions for #{device.inspect} are #{partitions.inspect}"
Expand Down

0 comments on commit de45e80

Please sign in to comment.