Skip to content

Commit

Permalink
UEFI
Browse files Browse the repository at this point in the history
Close #13
  • Loading branch information
amezin committed Dec 22, 2024
1 parent 98f9ec0 commit 295b4c3
Show file tree
Hide file tree
Showing 18 changed files with 79 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
| sudo tee /etc/apt/sources.list.d/hashicorp.list
- run: sudo apt-get update
- run: sudo apt-get install -y --no-install-recommends packer qemu-system-x86 qemu-system-modules-spice qemu-utils vagrant libvirt-daemon-system libvirt-dev dnsmasq
- run: sudo apt-get install -y --no-install-recommends packer qemu-system-x86 qemu-system-modules-spice qemu-utils vagrant libvirt-daemon-system libvirt-dev dnsmasq ovmf
- run: sudo apt-get clean -y
- run: sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc
- run: sudo docker image prune --all --force
Expand Down
6 changes: 6 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
BOX_DIR = File.dirname(File.expand_path(__FILE__))
FIRMWARE_FILES = Dir.glob('*.fd', base: BOX_DIR)

Vagrant.configure(2) do |config|
config.vm.provider :libvirt do |libvirt|
libvirt.memory = 4096
Expand Down Expand Up @@ -31,6 +34,9 @@ Vagrant.configure(2) do |config|
libvirt.graphics_port = 0
end
end

libvirt.nvram = File.join(BOX_DIR, 'efivars.fd')
libvirt.loader = File.join(BOX_DIR, FIRMWARE_FILES.reject { |name| name == 'efivars.fd' }.first)
end

config.vm.synced_folder '.', '/vagrant', disabled: true
Expand Down
9 changes: 9 additions & 0 deletions alpine-3.18.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ source "qemu" "alpine318" {
"setup-interfaces -a -r && ",
"setup-sshd -k 'http://{{ .HTTPIP }}:{{ .HTTPPort }}/vagrant.pub' openssh<enter>",
]
efi_firmware_code = var.efi_firmware_code
efi_firmware_vars = var.efi_firmware_vars
}

build {
Expand All @@ -41,6 +43,13 @@ build {
}
}

provisioner "shell" {
inline = [
"apk add efibootmgr",
"efibootmgr -c -d /dev/vda -p 1 -L alpine -l '\\EFI\\alpine\\grubx64.efi'",
]
}

provisioner "shell" {
inline = ["reboot"]
expect_disconnect = true
Expand Down
9 changes: 9 additions & 0 deletions alpine-3.19.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ source "qemu" "alpine319" {
"setup-interfaces -a -r && ",
"setup-sshd -k 'http://{{ .HTTPIP }}:{{ .HTTPPort }}/vagrant.pub' openssh<enter>",
]
efi_firmware_code = var.efi_firmware_code
efi_firmware_vars = var.efi_firmware_vars
}

build {
Expand All @@ -41,6 +43,13 @@ build {
}
}

provisioner "shell" {
inline = [
"apk add efibootmgr",
"efibootmgr -c -d /dev/vda -p 1 -L alpine -l '\\EFI\\alpine\\grubx64.efi'",
]
}

provisioner "shell" {
inline = ["reboot"]
expect_disconnect = true
Expand Down
11 changes: 11 additions & 0 deletions alpine-3.20.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ source "qemu" "alpine320" {
"setup-interfaces -a -r && ",
"setup-sshd -k 'http://{{ .HTTPIP }}:{{ .HTTPPort }}/vagrant.pub' openssh<enter>",
]
efi_firmware_code = var.efi_firmware_code
efi_firmware_vars = var.efi_firmware_vars
qemuargs = [["-serial", "stdio"]]
}

build {
Expand All @@ -41,6 +44,13 @@ build {
}
}

provisioner "shell" {
inline = [
"apk add efibootmgr",
"efibootmgr -c -d /dev/vda -p 1 -L alpine -l '\\EFI\\alpine\\grubx64.efi'",
]
}

provisioner "shell" {
inline = ["reboot"]
expect_disconnect = true
Expand All @@ -66,6 +76,7 @@ build {
post-processors {
post-processor "vagrant" {
vagrantfile_template = "Vagrantfile"
include = [var.efi_firmware_code, "${path.root}/output-${source.name}/efivars.fd"]
}

post-processor "vagrant-registry" {
Expand Down
2 changes: 1 addition & 1 deletion alpine-answer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ ROOTSSHKEY="${trimspace(file("${path.root}/keys/vagrant.pub"))}"

NTPOPTS="openntpd"

DISKOPTS="-k lts -m sys /dev/vda"
DISKOPTS="-v -k lts -m sys /dev/vda"
2 changes: 2 additions & 0 deletions arch-edk2.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
efi_firmware_code = "/usr/share/edk2/x64/OVMF_CODE.4m.fd"
efi_firmware_vars = "/usr/share/edk2/x64/OVMF_VARS.4m.fd"
20 changes: 20 additions & 0 deletions common.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@ variable "headless" {
description = "Build in headless mode"
}

variable "efi_firmware_code" {
type = string
default = "/usr/share/OVMF/OVMF_CODE_4M.fd"
description = "Path to the CODE part of OVMF (or other compatible firmwares)"
validation {
condition = fileexists(var.efi_firmware_code)
error_message = "OVMF CODE file must exist."
}
}

variable "efi_firmware_vars" {
type = string
default = "/usr/share/OVMF/OVMF_VARS_4M.fd"
description = "Path to the VARS corresponding to the OVMF code file"
validation {
condition = fileexists(var.efi_firmware_vars)
error_message = "OVMF VARS file must exist."
}
}

data "external-raw" "git-describe" {
program = ["git", "describe", "--tags"]
}
Expand Down
2 changes: 2 additions & 0 deletions debian-12.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ source "qemu" "debian12" {
"preseed/url=http://{{.HTTPIP}}:{{.HTTPPort}}/debian-preseed.cfg ",
"<enter>"
]
efi_firmware_code = var.efi_firmware_code
efi_firmware_vars = var.efi_firmware_vars
qemuargs = [["-serial", "stdio"]]
}

Expand Down
2 changes: 2 additions & 0 deletions fedora-40.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ source "qemu" "fedora40" {
"initrd /images/pxeboot/initrd.img<enter><wait10>",
"boot<enter><wait>"
]
efi_firmware_code = var.efi_firmware_code
efi_firmware_vars = var.efi_firmware_vars
qemuargs = [["-serial", "stdio"]]
}

Expand Down
2 changes: 2 additions & 0 deletions fedora-41.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ source "qemu" "fedora41" {
"initrd /images/pxeboot/initrd.img<enter><wait10>",
"boot<enter><wait>"
]
efi_firmware_code = var.efi_firmware_code
efi_firmware_vars = var.efi_firmware_vars
qemuargs = [["-serial", "stdio"]]
}

Expand Down
2 changes: 2 additions & 0 deletions opensuse-leap-15.6.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ source "qemu" "opensuseleap156" {
"autoyast=http://{{ .HTTPIP }}:{{ .HTTPPort }}/opensuse.xml<wait>",
"<enter><wait>"
]
efi_firmware_code = var.efi_firmware_code
efi_firmware_vars = var.efi_firmware_vars
qemuargs = [["-serial", "stdio"]]
}

Expand Down
2 changes: 2 additions & 0 deletions opensuse-tumbleweed.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ source "qemu" "opensusetumbleweed" {
"autoyast=http://{{ .HTTPIP }}:{{ .HTTPPort }}/opensuse.xml<wait>",
"<enter><wait>"
]
efi_firmware_code = var.efi_firmware_code
efi_firmware_vars = var.efi_firmware_vars
qemuargs = [["-serial", "stdio"]]
}

Expand Down
2 changes: 2 additions & 0 deletions silverblue-40.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ source "qemu" "silverblue40" {
"initrd /images/pxeboot/initrd.img<enter><wait10>",
"boot<enter><wait>"
]
efi_firmware_code = var.efi_firmware_code
efi_firmware_vars = var.efi_firmware_vars
qemuargs = [["-serial", "stdio"]]
}

Expand Down
2 changes: 2 additions & 0 deletions silverblue-41.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ source "qemu" "silverblue41" {
"initrd /images/pxeboot/initrd.img<enter><wait10>",
"boot<enter><wait>"
]
efi_firmware_code = var.efi_firmware_code
efi_firmware_vars = var.efi_firmware_vars
qemuargs = [["-serial", "stdio"]]
}

Expand Down
2 changes: 2 additions & 0 deletions ubuntu-22.04.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ source "qemu" "ubuntu2204" {
"initrd /casper/initrd<enter><wait>",
"boot<enter>"
]
efi_firmware_code = var.efi_firmware_code
efi_firmware_vars = var.efi_firmware_vars
qemuargs = [["-serial", "stdio"]]
}

Expand Down
2 changes: 2 additions & 0 deletions ubuntu-24.04.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ source "qemu" "ubuntu2404" {
"initrd /casper/initrd<enter><wait>",
"boot<enter>"
]
efi_firmware_code = var.efi_firmware_code
efi_firmware_vars = var.efi_firmware_vars
qemuargs = [["-serial", "stdio"]]
}

Expand Down
2 changes: 2 additions & 0 deletions ubuntu-24.10.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ source "qemu" "ubuntu2410" {
"initrd /casper/initrd<enter><wait>",
"boot<enter>"
]
efi_firmware_code = var.efi_firmware_code
efi_firmware_vars = var.efi_firmware_vars
qemuargs = [["-serial", "stdio"]]
}

Expand Down

0 comments on commit 295b4c3

Please sign in to comment.