Compiling OVMF for ACRN and PVE on Ubuntu 18.04 LTS for iGPU Passthrough
This guide provides step-by-step instructions on how to compile Open Virtual Machine Firmware (OVMF) for Project ACRN and Proxmox Virtual Environment (PVE) using an Ubuntu 18.04 LTS system. The resulting OVMF is particularly useful for scenarios requiring Intel Integrated GPU (iGPU) passthrough to virtual machines. We’ll cover the necessary dependencies and compilation commands for each target environment.
Compile OVMF for ACRN using Ubuntu 18.04 LTS
This section will guide you through compiling OVMF specifically for use with Project ACRN, enabling iGPU passthrough capabilities.
Install Compile Dependencies
First, we need to install essential packages and clone the ACPICA (ACPI Component Architecture) project, which is necessary for the build process.
sudo apt install git build-essential curl gcc-5 g++-5 python uuid-dev nasm flex bison -y
git clone https://github.com/acpica/acpica.git
cd acpica
make clean
make
sudo make install
cd ..
These commands will update your package list, install the required development tools and libraries, and then download, compile, and install the ACPICA utilities.
Compile OVMF for ACRN
With the dependencies in place, we can now proceed to compile OVMF for ACRN. This build will incorporate elements needed for iGPU support.
git clone https://github.com/projectacrn/acrn-edk2.git
mkdir -p acrn-edk2/OvmfPkg/IntelGop/
mkdir -p acrn-edk2/OvmfPkg/Vbt/
cp IntelGopDriver.efi acrn-edk2/OvmfPkg/IntelGop/IntelGopDriver.efi
cp Vbt.bin acrn-edk2/OvmfPkg/Vbt/Vbt.bin
wget https://projectacrn.github.io/latest/_static/downloads/Use-the-default-vbt-released-with-GOP-driver.patch
wget https://projectacrn.github.io/latest/_static/downloads/Integrate-IntelGopDriver-into-OVMF.patch
cd acrn-edk2/
git apply ../Use-the-default-vbt-released-with-GOP-driver.patch
git apply ../Integrate-IntelGopDriver-into-OVMF.patch
git submodule update --init CryptoPkg/Library/OpensslLib/openssl
source edksetup.sh
make -C BaseTools
vim Conf/target.txt
During the steps above, we clone the ACRN EDK2 repository, create necessary directories for Intel Graphics Output Protocol (GOP) driver and Video BIOS Table (VBT), and copy the respective files (IntelGopDriver.efi and Vbt.bin - ensure these files are present in your working directory before running the cp commands). These components are crucial for iGPU passthrough. We then download and apply patches required for ACRN. After updating the submodules, we set up the EDK2 build environment and build the base tools.
Next, you need to edit the Conf/target.txt file. Open it with vim or your preferred text editor and ensure the following content is present:
ACTIVE_PLATFORM = OvmfPkg/OvmfPkgX64.dsc
TARGET_ARCH = X64
TOOL_CHAIN_TAG = GCC5
Finally, build OVMF with the specified options:
build -DFD_SIZE_2MB -DDEBUG_ON_SERIAL_PORT=TRUE
Compile OVMF for PVE
This section details the process for compiling OVMF tailored for a Proxmox VE setup, specifically for enabling iGPU passthrough. This method utilizes Docker for a containerized build environment.
Install Compile Dependencies (Docker)
The primary dependency for this build method is Docker. The following commands will download and execute the official Docker installation script.
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
This ensures you have a working Docker environment. For managing Docker as a non-root user, you might need to add your user to the docker group (often handled by the script, but can be done manually with sudo usermod -aG docker $USER and then logging out and back in or using newgrp docker).
Compile OVMF for PVE
Now, we’ll clone the build repository and execute the build scripts. This OVMF build is intended to support iGPU passthrough in PVE. You’ll need to have your GitHub access key added to the ssh-agent to clone the repository via SSH.
# You need to add your github accese key to the ssh-agent
git clone [email protected]:cmd2001/build-edk2-gvtd.git
cd build-edk2-gvtd
sh ./init_edk2.sh
mkdir gop
cp ../IntelGopDriver.efi gop/IntelGopDriver.efi
sudo bash ./build_ovmf.sh
sudo bash ./build_oprom.sh
These commands clone the build-edk2-gvtd repository, initialize the EDK2 environment using a script, create a directory for the GOP driver, and copy your IntelGopDriver.efi file into it (ensure this file is located in the parent directory before running cp). The IntelGopDriver.efi is key for iGPU functionality. Finally, it runs the provided shell scripts to build OVMF and the option ROM using Docker. The sudo prefix is used as the scripts likely perform operations requiring root privileges within the Docker environment or for file system manipulation.
Following these instructions should result in successfully compiled OVMF images for either ACRN or PVE environments, configured to support iGPU passthrough.
在 Ubuntu 18.04 LTS 上为 ACRN 和 PVE 编译支持核显直通的 OVMF
本指南将一步步介绍如何在 Ubuntu 18.04 LTS 系统上为 Project ACRN 和 Proxmox Virtual Environment (PVE) 编译开放虚拟机固件(OVMF)。编译生成的 OVMF 非常适合需要将 Intel 集成显卡(iGPU / 核显)直通给虚拟机的场景。下面将分别介绍针对这两种目标环境所需的依赖项与编译命令。
使用 Ubuntu 18.04 LTS 为 ACRN 编译 OVMF
本节将指导你编译专用于 Project ACRN 的 OVMF,以启用核显(iGPU)直通功能。
安装编译依赖
首先,我们需要安装必要的软件包,并克隆编译过程中所需的 ACPICA(ACPI 组件架构)项目。
sudo apt install git build-essential curl gcc-5 g++-5 python uuid-dev nasm flex bison -y
git clone https://github.com/acpica/acpica.git
cd acpica
make clean
make
sudo make install
cd ..
以上命令会更新软件包列表,安装所需的开发工具与库,然后下载、编译并安装 ACPICA 工具集。
为 ACRN 编译 OVMF
依赖项准备就绪后,就可以开始为 ACRN 编译 OVMF 了。此次构建将集成支持 iGPU 所需的组件。
git clone https://github.com/projectacrn/acrn-edk2.git
mkdir -p acrn-edk2/OvmfPkg/IntelGop/
mkdir -p acrn-edk2/OvmfPkg/Vbt/
cp IntelGopDriver.efi acrn-edk2/OvmfPkg/IntelGop/IntelGopDriver.efi
cp Vbt.bin acrn-edk2/OvmfPkg/Vbt/Vbt.bin
wget https://projectacrn.github.io/latest/_static/downloads/Use-the-default-vbt-released-with-GOP-driver.patch
wget https://projectacrn.github.io/latest/_static/downloads/Integrate-IntelGopDriver-into-OVMF.patch
cd acrn-edk2/
git apply ../Use-the-default-vbt-released-with-GOP-driver.patch
git apply ../Integrate-IntelGopDriver-into-OVMF.patch
git submodule update --init CryptoPkg/Library/OpensslLib/openssl
source edksetup.sh
make -C BaseTools
vim Conf/target.txt
在上述步骤中,我们克隆了 ACRN EDK2 仓库,为 Intel 图形输出协议(GOP)驱动和视频 BIOS 表(VBT)创建了必要的目录,并复制了对应的文件(IntelGopDriver.efi 和 Vbt.bin——请确保在运行 cp 命令前你的工作目录中已准备好这两个文件)。这些组件对于实现核显直通至关重要。随后,我们下载并应用了 ACRN 所需的补丁,更新子模块后初始化 EDK2 编译环境并构建基础工具(BaseTools)。
接下来,需要编辑 Conf/target.txt 文件。使用 vim 或你喜欢的文本编辑器打开它,确保其中包含以下内容:
ACTIVE_PLATFORM = OvmfPkg/OvmfPkgX64.dsc
TARGET_ARCH = X64
TOOL_CHAIN_TAG = GCC5
最后,使用指定参数编译 OVMF:
build -DFD_SIZE_2MB -DDEBUG_ON_SERIAL_PORT=TRUE
为 PVE 编译 OVMF
本节详细介绍为 Proxmox VE 环境定制编译 OVMF 的流程,专门用于实现核显直通。该方法使用 Docker 提供容器化的编译环境。
安装编译依赖(Docker)
此编译方法的主要依赖是 Docker。以下命令将下载并执行官方 Docker 安装脚本:
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
这将确保你拥有一个可用的 Docker 环境。若希望以非 root 用户管理 Docker,可以将当前用户加入 docker 用户组(安装脚本通常会处理,也可手动执行 sudo usermod -aG docker $USER,然后重新登录或运行 newgrp docker 生效)。
为 PVE 编译 OVMF
现在,我们克隆构建仓库并执行构建脚本。该 OVMF 构建专为在 PVE 中支持 iGPU 直通而设计。由于需要通过 SSH 克隆仓库,请先将你的 GitHub 访问密钥添加到 ssh-agent 中。
# 需要先将你的 GitHub 访问密钥添加到 ssh-agent
git clone [email protected]:cmd2001/build-edk2-gvtd.git
cd build-edk2-gvtd
sh ./init_edk2.sh
mkdir gop
cp ../IntelGopDriver.efi gop/IntelGopDriver.efi
sudo bash ./build_ovmf.sh
sudo bash ./build_oprom.sh
这些命令会克隆 build-edk2-gvtd 仓库,通过脚本初始化 EDK2 环境,创建存放 GOP 驱动的目录,并将你的 IntelGopDriver.efi 文件复制进去(请确保运行 cp 前该文件已位于上级目录中)。IntelGopDriver.efi 是实现核显功能的关键。最后,运行仓库提供的 Shell 脚本,通过 Docker 构建 OVMF 和 Option ROM。由于脚本需要调用 Docker 或执行文件系统操作,因此这里使用了 sudo。
按照上述步骤操作后,即可成功编译出适用于 ACRN 或 PVE 环境、支持 Intel 核显直通的 OVMF 固件镜像。
在 Ubuntu 18.04 LTS 上為 ACRN 與 PVE 編譯支援內顯直通的 OVMF
本指南將一步步介紹如何在 Ubuntu 18.04 LTS 系統上為 Project ACRN 與 Proxmox Virtual Environment (PVE) 編譯開放虛擬機器韌體(OVMF)。編譯產生的 OVMF 非常適合需要將 Intel 整合式顯示卡(iGPU / 內顯)直通(Passthrough)給虛擬機器的情境。以下將分別介紹針對這兩種目標環境所需的相依套件與編譯指令。
使用 Ubuntu 18.04 LTS 為 ACRN 編譯 OVMF
本節將指導你編譯專用於 Project ACRN 的 OVMF,以啟用內顯(iGPU)直通功能。
安裝編譯相依套件
首先,我們需要安裝必要的套件,並複製(Clone)編譯過程中所需的 ACPICA(ACPI 元件架構)專案。
sudo apt install git build-essential curl gcc-5 g++-5 python uuid-dev nasm flex bison -y
git clone https://github.com/acpica/acpica.git
cd acpica
make clean
make
sudo make install
cd ..
以上指令會更新套件列表,安裝所需的開發工具與函式庫,接著下載、編譯並安裝 ACPICA 工具集。
為 ACRN 編譯 OVMF
相依套件準備就緒後,即可開始為 ACRN 編譯 OVMF。此次建置將整合支援 iGPU 所需的元件。
git clone https://github.com/projectacrn/acrn-edk2.git
mkdir -p acrn-edk2/OvmfPkg/IntelGop/
mkdir -p acrn-edk2/OvmfPkg/Vbt/
cp IntelGopDriver.efi acrn-edk2/OvmfPkg/IntelGop/IntelGopDriver.efi
cp Vbt.bin acrn-edk2/OvmfPkg/Vbt/Vbt.bin
wget https://projectacrn.github.io/latest/_static/downloads/Use-the-default-vbt-released-with-GOP-driver.patch
wget https://projectacrn.github.io/latest/_static/downloads/Integrate-IntelGopDriver-into-OVMF.patch
cd acrn-edk2/
git apply ../Use-the-default-vbt-released-with-GOP-driver.patch
git apply ../Integrate-IntelGopDriver-into-OVMF.patch
git submodule update --init CryptoPkg/Library/OpensslLib/openssl
source edksetup.sh
make -C BaseTools
vim Conf/target.txt
在上述步驟中,我們複製了 ACRN EDK2 儲存庫,為 Intel 圖形輸出協定(GOP)驅動程式與視訊 BIOS 表(VBT)建立了必要的目錄,並複製了對應的檔案(IntelGopDriver.efi 與 Vbt.bin——請確保在執行 cp 指令前你的工作目錄中已準備好這兩個檔案)。這些元件對於實現內顯直通至關重要。隨後,我們下載並套用了 ACRN 所需的修補檔(Patch),更新子模組後初始化 EDK2 建置環境並編譯基礎工具(BaseTools)。
接下來,需要編輯 Conf/target.txt 檔案。使用 vim 或你慣用的文字編輯器開啟它,並確保其中包含以下內容:
ACTIVE_PLATFORM = OvmfPkg/OvmfPkgX64.dsc
TARGET_ARCH = X64
TOOL_CHAIN_TAG = GCC5
最後,使用指定參數建置 OVMF:
build -DFD_SIZE_2MB -DDEBUG_ON_SERIAL_PORT=TRUE
為 PVE 編譯 OVMF
本節詳細介紹為 Proxmox VE 環境客製化編譯 OVMF 的流程,專門用於啟用內顯直通。此方法使用 Docker 提供容器化的建置環境。
安裝編譯相依套件(Docker)
此建置方法的主要相依項目是 Docker。以下指令將下載並執行官方 Docker 安裝指令碼:
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
這能確保你擁有一個可用的 Docker 環境。若希望以非 root 使用者管理 Docker,可以將目前使用者加入 docker 群組(安裝指令碼通常會自動處理,也可手動執行 sudo usermod -aG docker $USER,然後重新登入或執行 newgrp docker 生效)。
為 PVE 編譯 OVMF
現在,我們複製建置儲存庫並執行建置指令碼。此 OVMF 建置專為在 PVE 中支援 iGPU 直通而設計。由於需要透過 SSH 複製儲存庫,請先將你的 GitHub 存取金鑰加入 ssh-agent 中。
# 需要先將你的 GitHub 存取金鑰加入 ssh-agent
git clone [email protected]:cmd2001/build-edk2-gvtd.git
cd build-edk2-gvtd
sh ./init_edk2.sh
mkdir gop
cp ../IntelGopDriver.efi gop/IntelGopDriver.efi
sudo bash ./build_ovmf.sh
sudo bash ./build_oprom.sh
這些指令會複製 build-edk2-gvtd 儲存庫,透過指令碼初始化 EDK2 環境,建立存放 GOP 驅動程式的目錄,並將你的 IntelGopDriver.efi 檔案複製進去(請確保執行 cp 前該檔案已位於上層目錄中)。IntelGopDriver.efi 是發揮內顯功能的關鍵。最後,執行儲存庫提供的 Shell 指令碼,透過 Docker 建置 OVMF 與 Option ROM。由於指令碼需要呼叫 Docker 或執行檔案系統操作,因此這裡使用了 sudo。
按照上述步驟操作後,即可成功編譯出適用於 ACRN 或 PVE 環境、支援 Intel 內顯直通的 OVMF 韌體映像檔。
Ubuntu 18.04 LTS で ACRN および PVE 向けに iGPU パススルー対応 OVMF をビルドする
本ガイドでは、Ubuntu 18.04 LTS 環境を使用して Project ACRN および Proxmox Virtual Environment (PVE) 向けに Open Virtual Machine Firmware (OVMF) をコンパイルする手順をステップバイステップで解説します。ここでビルドする OVMF は、Intel 内蔵 GPU (iGPU) を仮想マシンへパススルーする構成で特に役立ちます。それぞれのターゲット環境に必要な依存パッケージとビルドコマンドを順に説明します。
Ubuntu 18.04 LTS で ACRN 向け OVMF をコンパイルする
このセクションでは、Project ACRN で iGPU パススルー機能を有効にするための OVMF をコンパイルする手順を説明します。
ビルド依存関係のインストール
まず、ビルドプロセスに必要な基本パッケージをインストールし、ACPICA (ACPI Component Architecture) プロジェクトをクローンしてビルドします。
sudo apt install git build-essential curl gcc-5 g++-5 python uuid-dev nasm flex bison -y
git clone https://github.com/acpica/acpica.git
cd acpica
make clean
make
sudo make install
cd ..
上記のコマンドにより、パッケージリストの更新、必要な開発ツールおよびライブラリのインストールが行われ、続いて ACPICA ユーティリティのダウンロード、コンパイル、インストールが実行されます。
ACRN 向け OVMF のコンパイル
依存関係の準備ができたら、ACRN 向けの OVMF をコンパイルします。このビルドには iGPU サポートに必要な要素が組み込まれます。
git clone https://github.com/projectacrn/acrn-edk2.git
mkdir -p acrn-edk2/OvmfPkg/IntelGop/
mkdir -p acrn-edk2/OvmfPkg/Vbt/
cp IntelGopDriver.efi acrn-edk2/OvmfPkg/IntelGop/IntelGopDriver.efi
cp Vbt.bin acrn-edk2/OvmfPkg/Vbt/Vbt.bin
wget https://projectacrn.github.io/latest/_static/downloads/Use-the-default-vbt-released-with-GOP-driver.patch
wget https://projectacrn.github.io/latest/_static/downloads/Integrate-IntelGopDriver-into-OVMF.patch
cd acrn-edk2/
git apply ../Use-the-default-vbt-released-with-GOP-driver.patch
git apply ../Integrate-IntelGopDriver-into-OVMF.patch
git submodule update --init CryptoPkg/Library/OpensslLib/openssl
source edksetup.sh
make -C BaseTools
vim Conf/target.txt
上記の手順では、ACRN EDK2 リポジトリをクローンし、Intel Graphics Output Protocol (GOP) ドライバおよび Video BIOS Table (VBT) 用のディレクトリを作成して、それぞれのファイル(IntelGopDriver.efi と Vbt.bin —— cp コマンドを実行する前に作業ディレクトリに配置しておいてください)をコピーしています。これらのコンポーネントは iGPU パススルーに不可欠です。その後、ACRN に必要なパッチをダウンロードして適用し、サブモジュールを更新したうえで EDK2 のビルド環境をセットアップし、ベースツール(BaseTools)をビルドします。
次に、Conf/target.txt ファイルを編集します。vim または任意のテキストエディタで開き、以下の内容が含まれていることを確認してください。
ACTIVE_PLATFORM = OvmfPkg/OvmfPkgX64.dsc
TARGET_ARCH = X64
TOOL_CHAIN_TAG = GCC5
最後に、指定したオプションで OVMF をビルドします。
build -DFD_SIZE_2MB -DDEBUG_ON_SERIAL_PORT=TRUE
PVE 向け OVMF をコンパイルする
このセクションでは、Proxmox VE 環境で iGPU パススルーを有効にするための OVMF をコンパイルする手順を説明します。この方法では、Docker を利用してコンテナ化されたビルド環境で作業を行います。
ビルド依存関係(Docker)のインストール
このビルド方式で主に必要となる依存環境は Docker です。以下のコマンドで公式の Docker インストールスクリプトをダウンロードして実行します。
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
これにより Docker 環境が構築されます。非 root ユーザーとして Docker を操作する場合は、現在のユーザーを docker グループに追加してください(スクリプトによって自動設定される場合もありますが、手動で行う場合は sudo usermod -aG docker $USER を実行してから再ログインするか、newgrp docker を実行します)。
PVE 向け OVMF のコンパイル
続いて、ビルド用リポジトリをクローンし、ビルドスクリプトを実行します。この OVMF ビルドは PVE での iGPU パススルーをサポートするためのものです。SSH 経由でリポジトリをクローンするため、あらかじめ GitHub のアクセスキーを ssh-agent に登録しておく必要があります。
# あらかじめ GitHub のアクセスキーを ssh-agent に追加しておく必要があります
git clone [email protected]:cmd2001/build-edk2-gvtd.git
cd build-edk2-gvtd
sh ./init_edk2.sh
mkdir gop
cp ../IntelGopDriver.efi gop/IntelGopDriver.efi
sudo bash ./build_ovmf.sh
sudo bash ./build_oprom.sh
これらのコマンドは build-edk2-gvtd リポジトリをクローンし、スクリプトで EDK2 環境を初期化した後、GOP ドライバ用のディレクトリを作成して IntelGopDriver.efi をコピーします(cp を実行する前に親ディレクトリにこのファイルを配置しておいてください)。IntelGopDriver.efi は iGPU を機能させるための重要なファイルです。最後に、付属のシェルスクリプトを実行して Docker 上で OVMF と Option ROM をビルドします。スクリプト内で Docker 操作やファイルシステム操作に root 権限が必要となるため、sudo を付けて実行しています。
以上の手順に従うことで、ACRN または PVE 環境向けに iGPU パススルーをサポートする OVMF イメージをコンパイルできます。