Skip to content

Commit

Permalink
Add support for detecting EFI boot
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Nov 18, 2021
1 parent a214818 commit c762a98
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/autoyast-rnc/rules.rnc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ y2_match_to =
| hostname
| hostaddress
| hostid
| efi
| karch
| linux
| installed_product
Expand All @@ -72,6 +73,7 @@ custom4 = element custom4 { MAP, (match_text
custom5 = element custom5 { MAP, (match_text & match_type? & script) }
disksize = element disksize { MAP, (match_text & match_type?) }
domain = element domain { MAP, (match_text & match_type?) }
efi = element efi { MAP, (match_text & match_type?) }
hostname = element hostname { MAP, (match_text & match_type?) }
hostaddress = element hostaddress { MAP, (match_text & match_type?) }
hostid = element hostid { MAP, (match_text & match_type?) }
Expand Down
8 changes: 8 additions & 0 deletions src/lib/autoinstall/y2erb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ def self.render(path)
class TemplateEnvironment
include Yast::Logger


# @return [Boolean] whether the system was booted using UEFI or not according to linuxrc
def efi?
Yast.import "Linuxrc"

Yast::Linuxrc.InstallInf("EFI") == "1"
end

def hardware
@hardware ||= Yast::SCR.Read(Yast::Path.new(".probe"))
end
Expand Down
17 changes: 16 additions & 1 deletion src/modules/AutoInstallRules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def main
Yast.import "XML"
Yast.import "Kernel"
Yast.import "Mode"
Yast.import "Linuxrc"
Yast.import "Profile"
Yast.import "Label"
Yast.import "Report"
Expand Down Expand Up @@ -84,6 +85,7 @@ def reset
@totaldisk = 0
@hostid = ""
@mac = ""
@efi = false
@linux = 0
@others = 0
@xserver = ""
Expand Down Expand Up @@ -139,6 +141,13 @@ def StdErrLog(stderr)
nil
end

# Returns whether the system was booted using UEFI or not
#
# @return [Boolean] true when the system is booted using EFI
def boot_efi?
Yast::Linuxrc.InstallInf("EFI") == "1"
end

# getMAC()
# Return MAC address of active device
# @return [String] mac address
Expand Down Expand Up @@ -286,6 +295,11 @@ def ProbeRules
#
Ops.set(@ATTR, "mac", @mac)

#
# EFI Boot
#
@ATTR["efi"] = @efi

#
# Network
#
Expand Down Expand Up @@ -1072,7 +1086,8 @@ def CreateFile(filename)
def AutoInstallRules
@mac = getMAC
@hostid = getHostid
Builtins.y2milestone("init mac:%1 hostid:%2", @mac, @hostid)
@efi = boot_efi?
log.info "init mac:#{@mac} hostid: #{@hostid} efi: #{@efi}"
nil
end

Expand Down
22 changes: 22 additions & 0 deletions test/lib/y2erb_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,26 @@ def hardware_mock_data
expect(subject.os_release).to be_a(Hash)
end
end

describe "#efi?" do
let(:efi) { "0" }

before do
allow(Yast::Linuxrc).to receive(:InstallInf).with("EFI").and_return(efi)
end

context "when the system is boot using efi" do
let(:efi) { "1" }

it "returns true" do
expect(subject.efi?).to eq(true)
end
end

context "when the system is boot without UEFI" do
it "returns false" do
expect(subject.efi?).to eq(false)
end
end
end
end

0 comments on commit c762a98

Please sign in to comment.