• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yast / yast-bootloader / 6034542486

31 Aug 2023 07:50AM UTC coverage: 87.597%. First build
6034542486

Pull #686

github

schubi2
version changed; added changes entry
Pull Request #686: Systemd boot feature

735 of 735 new or added lines in 15 files covered. (100.0%)

3171 of 3620 relevant lines covered (87.6%)

12.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.48
/src/modules/BootSupportCheck.rb
1
# frozen_string_literal: true
2

3
# File:
4
#      modules/BootSupportCheck.ycp
5
#
6
# Module:
7
#      Bootloader installation and configuration
8
#
9
# Summary:
10
#      Check whether the current system setup is a supported configuration
11
#
12
# Authors:
13
#      Jiri Srain <jsrain@suse.cz>
14
#
15
require "yast"
1✔
16

17
require "bootloader/bootloader_factory"
1✔
18

19
module Yast
1✔
20
  class BootSupportCheckClass < Module
1✔
21
    include Yast::Logger
1✔
22

23
    def main
1✔
24
      textdomain "bootloader"
1✔
25

26
      Yast.import "Bootloader"
1✔
27
      Yast.import "Arch"
1✔
28
      Yast.import "BootStorage"
1✔
29
      Yast.import "FileUtils"
1✔
30
      Yast.import "Mode"
1✔
31

32
      # List of problems found during last check
33
      @detected_problems = []
1✔
34
    end
35

36
    # Check if the system configuraiton is supported
37
    # Also sets the founds problems into internal variable
38
    # Always run this function before calling DetectedProblems()
39
    # @return [Boolean] true if supported
40
    def SystemSupported
1✔
41
      @detected_problems = []
15✔
42

43
      lt = ::Bootloader::BootloaderFactory.current.name
15✔
44
      # detect correct bootloader type
45
      supported = correct_loader_type(lt)
15✔
46

47
      # check specifics for individual loaders
48
      case lt
15✔
49
      when "grub2"
50
        supported = GRUB2() && supported
12✔
51
      when "grub2-efi"
52
        supported = GRUB2EFI() && supported
1✔
53
      when "systemd-boot"
54
        supported = SYSTEMDBOOT() && supported
1✔
55
      end
56

57
      log.info "Configuration supported: #{supported}"
15✔
58

59
      supported
15✔
60
    end
61

62
    # Formated string of detected problems
63
    # Always run SystemSupported before calling this function
64
    # @return [Boolean] a list of problems, empty if no was found
65
    def StringProblems
1✔
66
      @detected_problems.join("\n")
7✔
67
    end
68

69
    publish :function => :StringProblems, :type => "string ()"
1✔
70
    publish :function => :SystemSupported, :type => "boolean ()"
1✔
71

72
  private
1✔
73

74
    # Add a new problem description to the list of found problems
75
    def add_new_problem(description)
1✔
76
      @detected_problems << description
17✔
77
    end
78

79
    # Check that bootloader matches current hardware
80
    def correct_loader_type(type)
1✔
81
      return true if type == "none"
15✔
82

83
      # grub2 is sooo cool...
84
      return true if type == "grub2" && !::Bootloader::Systeminfo.efi_mandatory?
14✔
85

86
      if (Arch.i386 || Arch.x86_64) && ["grub2-efi", "systemd-boot"].include?(type) && efi?
3✔
87
        return true
×
88
      end
89

90
      if ["grub2-efi", "systemd-boot"].include?(type) && ::Bootloader::Systeminfo.efi_mandatory?
3✔
91
        return true
×
92
      end
93

94
      log.error "Unsupported combination of hardware platform #{Arch.architecture} and bootloader #{type}"
3✔
95
      add_new_problem(
3✔
96
        Builtins.sformat(
97
          _("Unsupported combination of hardware platform %1 and bootloader %2"),
98
          Arch.architecture,
99
          type
100
        )
101
      )
102
      false
3✔
103
    end
104

105
    # when grub2 is used and install stage1 to MBR, target /boot is btrfs, label is gpt-like
106
    # then there must be special partition to install core.img, otherwise grub2-install failed
107
    def check_gpt_reserved_partition
1✔
108
      return true unless stage1.mbr?
11✔
109

110
      boot_fs = BootStorage.boot_filesystem
4✔
111
      gpt_disks = BootStorage.stage1_disks_for(boot_fs).select(&:gpt?)
4✔
112
      return true if gpt_disks.empty?
4✔
113
      return true if boot_fs.type != ::Y2Storage::Filesystems::Type::BTRFS
4✔
114
      # more relax check, at least one disk is enough. Let propose more advanced stuff like boot
115
      # duplicite md raid1 with bios_boot on all disks to storage and user. Check there only when
116
      # we are sure it is problem (bsc#1125792)
117
      return true if gpt_disks.any? { |disk| disk.partitions.any? { |p| p.id.is?(:bios_boot) } }
12✔
118

119
      Builtins.y2error("Used together boot from MBR, gpt, btrfs and without bios_grub partition.")
×
120
      # TRANSLATORS: description of technical problem. Do not translate technical terms unless native language have well known translation.
121
      add_new_problem(
×
122
        _(
123
          "Boot from MBR does not work together with Btrfs filesystem and GPT disk label\n" \
124
          "without bios_grub partition.\n\n" \
125
          "To fix this issue,\n\n" \
126
          " - create a bios_grub partition, or\n" \
127
          " - use any Ext filesystem for boot partition, or\n" \
128
          " - do not install stage 1 to MBR."
129
        )
130
      )
131
      false
×
132
    end
133

134
    # Check if boot partition exist
135
    # check if not on raid0
136
    #
137
    # @return [Boolean] true on success
138

139
    # Check if EFI is needed
140
    def efi?
1✔
141
      ::Bootloader::Systeminfo.efi?
×
142
    end
143

144
    def check_activate_partition
1✔
145
      # activate set
146
      return true if stage1.activate?
11✔
147

148
      # there is already activate flag
149
      disks = Yast::BootStorage.boot_disks
7✔
150

151
      # do not activate for ppc and GPT see bsc#983194
152
      return true if Arch.ppc64 && disks.all?(&:gpt?)
7✔
153

154
      all_activate = disks.all? do |disk|
7✔
155
        if disk.partition_table
7✔
156
          legacy_boot = disk.partition_table.partition_legacy_boot_flag_supported?
7✔
157

158
          disk.partitions.any? { |p| legacy_boot ? p.legacy_boot? : p.boot? }
28✔
159
        else
160
          false
×
161
        end
162
      end
163

164
      return true if all_activate
7✔
165

166
      add_new_problem(_("Activate flag is not set by installer. If it is not set at all, some BIOSes could refuse to boot."))
7✔
167
      false
7✔
168
    end
169

170
    def check_mbr
1✔
171
      return true if stage1.generic_mbr? || stage1.mbr?
11✔
172

173
      add_new_problem(_("The installer will not modify the MBR of the disk. Unless it already contains boot code, the BIOS won't be able to boot from this disk."))
7✔
174
      false
7✔
175
    end
176

177
    # GRUB2-related check
178
    def GRUB2
1✔
179
      ret = []
12✔
180
      ret << check_gpt_reserved_partition if Arch.x86_64
12✔
181
      ret << check_activate_partition if Arch.x86_64 || Arch.ppc64
12✔
182
      ret << check_mbr if Arch.x86_64
12✔
183

184
      ret.all?
12✔
185
    end
186

187
    # GRUB2EFI-related check
188
    def GRUB2EFI
1✔
189
      true
1✔
190
    end
191

192
    # systemd-boot-related check
193
    def SYSTEMDBOOT
1✔
194
      true
1✔
195
    end
196

197
    def stage1
1✔
198
      ::Bootloader::BootloaderFactory.current.stage1
44✔
199
    end
200

201
    def staging
1✔
202
      Y2Storage::StorageManager.instance.staging
×
203
    end
204
  end
205

206
  BootSupportCheck = BootSupportCheckClass.new
1✔
207
  BootSupportCheck.main
1✔
208
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc