详解 UEFI 模式下安装 Linux
UEFI BIOS GRUB

> 
> 此页面是免费浏览的，没有烦人的外部广告；然而，我的确花了时间准备，网站托管也花了钱。如果您发现此页面帮到了您，请考虑进行小额[捐款](http://www.rodsbooks.com/linux-uefi/)，以帮助保持网站的运行。谢谢！ 原著于 2013/10/19；最后修改于 2015/3/16
> 
> 
> 


![](/data/attachment/album/201705/05/232225rsydrjnujbcsdmdn.jpg)


### 引言


几年来，一种新的固件技术悄然出现，而大多数普通用户对此并无所知。该技术被称为<ruby> <a href="https://en.wikipedia.org/wiki/Uefi">  可扩展固件接口 </a> <rp>  （ </rp> <rt>  Extensible Firmware Interface </rt> <rp>  ） </rp></ruby>（EFI）， 或更新一些的统一可扩展固件接口（Unified EFI，UEFI，本质上是 EFI 2.x），它已经开始替代古老的<ruby> <a href="https://en.wikipedia.org/wiki/BIOS">  基本输入/输出系统 </a> <rp>  （ </rp> <rt>  Basic Input/Output System </rt> <rp>  ） </rp></ruby>（BIOS）固件技术，有经验的计算机用户或多或少都有些熟悉 BIOS。


本页面是给 Linux 用户使用 EFI 技术的一个快速介绍，其中包括有关开始将 Linux 安装到此类计算机上的建议。不幸的是，EFI 是一个庞杂的话题；EFI 软件本身是复杂的，许多实现有系统特定的怪异行为甚至是缺陷。因此，我无法在一个页面上描述在 EFI 计算机上安装和使用 Linux 的一切知识。我希望你能将本页面作为一个有用的起点，不管怎么说，每个部分以及末尾“参考文献”部分的链接可以指引你找到更多的文档。


### 你的计算机是否使用 EFI 技术？


EFI 是一种*固件*，意味着它是内置于计算机中处理低级任务的软件。最重要的是，固件控制着计算机的引导过程，反过来说这代表着基于 EFI 的计算机与基于 BIOS 的计算机的引导过程不同。（有关此规律的例外之处稍后再说。）这种差异可能使操作系统安装介质的设计超级复杂化，但是一旦安装好并运行之后，它对计算机的日常操作几乎没有影响。请注意，大多数制造商使用术语 “BIOS” 来表示他们的 EFI。我认为这种用法很混乱，所以我避免了；在我看来，EFI 和 BIOS 是两种不同类型的固件。



> 
> **注意：**苹果公司的 Mac 使用的 EFI 在许多方面是不同寻常的。尽管本页面的大部分内容同样适用于 Mac，但有些细节上的出入，特别是在设置 EFI 引导加载程序的时候。这个任务最好在 OS X 上进行，使用 Mac 的 [bless utility](http://ss64.com/osx/bless.html)工具，我不在此做过多描述。
> 
> 
> 


自从 2006 年第一次推出以来，EFI 已被用于基于英特尔的 Mac 上。从 2012 年底开始，大多数安装 Windows 8 或更高版本系统的计算机就已经默认使用 UEFI 启动，实际上大多数 PC 从 2011 年中期就开始使用 UEFI，虽然默认情况下它们可能无法以 EFI 模式启动。2011 年前销出的 PC 也有一些支持 EFI，尽管它们大都默认使用 BIOS 模式启动。


如果你不确定你的计算机是否支持 EFI，则应查看固件设置实用程序和参考用户手册关于 *EFI*、*UEFI* 以及 *legacy booting* 的部分。（可以通过搜索用户手册的 PDF 文件来快速了解。）如果你没有找到类似的参考，你的计算机可能使用老式的（“legacy”） BIOS 引导；但如果你找到了这些术语的参考，几乎可以肯定它使用了 EFI 技术。你还可以尝试*只*有 EFI 模式的引导加载器的安装介质。使用 [rEFInd](http://www.rodsbooks.com/refind/getting.html) 制作的 USB 闪存驱动器或 CD-R 镜像是用来测试不错的选择。


在继续之前，你应当了解大多数 x86 和 x86-64 架构的计算机上的 EFI 都包含一个叫做<ruby> 兼容支持模块 <rt>  Compatibility Support Module </rt></ruby>（CSM）的组件，这使得 EFI 能够使用旧的 BIOS 风格的引导机制来引导操作系统。这会非常方便，因为它向后兼容；但是这样也导致一些意外情况的发生，因为计算机不论以 EFI 模式引导还是以 BIOS （也称为 CSM 或 legacy）模式引导，在控制时没有标准的使用规范和用户界面。特别地，你的 Linux 安装介质非常容易意外的以 BIOS/CSM/legacy 模式启动，这会导致 Linux 以 BIOS/CSM/legacy 模式安装。如果 Linux 是唯一的操作系统，也可以正常工作，但是如果与在 EFI 模式下的 Windows 组成双启动的话，就会非常复杂。（反过来问题也可能发生。）以下部分将帮助你以正确模式引导安装程序。如果你在阅读这篇文章之前就已经以 BIOS 模式安装了 Linux，并且希望切换引导模式，请阅读后续章节，“哎呀：将传统模式下安装的引导转为 EFI 模式下的引导”。


UEFI 的一个附加功能值得一提：<ruby> 安全启动 <rt>  Secure Boot </rt></ruby>。此特性旨在最大限度的降低计算机受到 *boot kit* 病毒感染的风险，这是一种感染计算机引导加载程序的恶意软件。Boot kits 很难检测和删除，阻止它们的运行刻不容缓。微软公司要求所有带有支持 Windows 8 标志的台式机和笔记本电脑启用 安全启动。这一配置使 Linux 的安装变得复杂，尽管有些发行版可以较好的处理这个问题。不要将安全启动和 EFI 或 UEFI 混淆；支持 EFI 的计算机不一定支持 安全启动，而且支持 EFI 的 x86-64 的计算机也可以禁用 安全启动。微软同意用户在 Windows 8 认证的 x86 和 x86-64 计算机上禁用安全启动功能；然而对装有 Windows 8 的 ARM 计算机而言却相反，它们必须**不允许**用户禁用 安全启动。幸运的是，基于 ARM 的 Windows 8 计算机目前很少见。我建议避免使用它们。


### 你的发行版是否支持 EFI 技术？


大多数 Linux 发行版已经支持 EFI 好多年了。然而，不同的发行版对 EFI 的支持程度不同。大多数主流发行版（Fedora，OpenSUSE，Ubuntu 等）都能很好的支持 EFI，包括对安全启动的支持。另外一些“自行打造”的发行版，比如 Gentoo，对 EFI 的支持较弱，但它们的性质使其很容易添加 EFI 支持。事实上，可以向*任意* Linux 发行版添加 EFI 支持：你需要安装 Linux（即使在 BIOS 模式下），然后在计算机上安装 EFI 引导加载程序。有关如何执行此操作的信息，请参阅“哎呀：将传统模式下安装的引导转为 EFI 模式下的引导”部分。


你应当查看发行版的功能列表，来确定它是否支持 EFI。你还应当注意你的发行版对安全启动的支持情况，特别是如果你打算和 Windows 8 组成双启动。请注意，即使正式支持安全启动的发行版也可能要求禁用此功能，因为 Linux 对安全启动的支持通常很差劲，或者导致意外情况的发生。


### 准备安装 Linux


下面几个准备步骤有助于在 EFI 计算机上 Linux 的安装，使其更加顺利：


#### 1、 升级固件


有些 EFI 是有问题的，不过硬件制造商偶尔会发布其固件的更新。因此我建议你将固件升级到最新可用的版本。如果你从论坛的帖子知道自己计算机的 EFI 有问题，你应当在安装 Linux 之前更新它，因为如果安装 Linux 之后更新固件，会有些问题需要额外的操作才能解决。另一方面，升级固件是有一定风险的，所以如果制造商提供了 EFI 支持，最好的办法就是按它们提供的方式进行升级。


#### 2、 了解如何使用固件


通常你可以通过在引导过程之初按 Del 键或功能键进入固件设置实用程序。按下开机键后尽快查看相关的提示信息，或者尝试每个功能键。类似的，ESC 键或功能键通常可以进入固件的内置引导管理器，可以选择要进入的操作系统或外部设备。一些制造商把这些设置隐藏的很深。在某些情况下，如[此页面](http://www.eightforums.com/tutorials/20256-uefi-firmware-settings-boot-inside-windows-8-a.html)所述，你可以在 Windows 8 内做到这些。


#### 3、调整以下固件设置


* **快速启动** — 此功能可以通过在硬件初始化时使用快捷方式来加快引导过程。这很好用，但有时候会使 USB 设备不能初始化，导致计算机无法从 USB 闪存驱动器或类似的设备启动。因此禁用快速启动*可能*有一定的帮助，甚至是必须的；你可以让它保持激活，而只在 Linux 安装程序启动遇到问题时将其停用。请注意，此功能有时可能会以其它名字出现。在某些情况下，你必须*启用* USB 支持，而不是*禁用*快速启动功能。
* **安全启动** — Fedora，OpenSUSE，Ubuntu 以及其它的发行版官方就支持安全启动；但是如果在启动引导加载程序或内核时遇到问题，可能需要禁用此功能。不幸的是，没办法具体描述怎么禁用，因为不同计算机的设置方法也不同。请参阅[我的安全启动页面](http://www.rodsbooks.com/efi-bootloaders/secureboot.html#disable)获取更多关于此话题的信息。



> 
> **注意：** 一些教程说安装 Linux 时需要启用 BIOS/CSM/legacy 支持。通常情况下，这样做是错的。启用这些支持可以解决启动安装程序涉及的问题，但也会带来新的问题。以这种方式安装的教程通常可以通过“引导修复”来解决这些问题，但最好从一开始就做对。本页面提供了帮助你以 EFI 模式启动 Linux 安装程序的提示，从而避免以后的问题。
> 
> 
>
* **CSM/legacy 选项** — 如果你想以 EFI 模式安装，请*关闭*这些选项。一些教程推荐启用这些选项，有时这是必须的 —— 比如，有些附加视频卡需要在固件中启用 BIOS 模式。尽管如此，大多数情况下启用 CSM/legacy 支持只会无意中增加以 BIOS 模式启动 Linux 的风险，但你并*不想*这样。请注意，安全启动和 CSM/legacy 选项有时会交织在一起，因此更改任一选项之后务必检查另一个。


#### 4、 禁用 Windows 的快速启动功能


[这个页面](http://www.eightforums.com/tutorials/6320-fast-startup-turn-off-windows-8-a.html)描述了如何禁用此功能，不禁用的话会导致文件系统损坏。请注意此功能与固件的快速启动不同。


#### 5、 检查分区表


使用 [GPT fdisk](http://www.rodsbooks.com/gdisk/)、parted 或其它任意分区工具检查磁盘分区。理想情况下，你应该创建一个包含每个分区确切起点和终点（以扇区为单位）的纸面记录。这会是很有用的参考，特别是在安装时进行手动分区的时候。如果已经安装了 Windows，确定可以识别你的 [EFI 系统分区（ESP）](http://en.wikipedia.org/wiki/EFI_System_partition)，它是一个 FAT 分区，设置了“启动标记”（在 parted 或 Gparted 中）或在 gdisk 中的类型码为 EF00。


### 安装 Linux


大部分 Linux 发行版都提供了足够的安装说明；然而我注意到了在 EFI 模式安装中的几个常见的绊脚石：


* **确保使用正确位深的发行版** — EFI 启动加载器和 EFI 自身的位深相同。现代计算机通常是 64 位，尽管最初几代基于 Intel 的 Mac、一些现代的平板电脑和变形本、以及一些鲜为人知的电脑使用 32 位 EFI。虽然可以将 32 位 EFI 引导加载程序添加至 32 位发行版，但我还没有遇到过正式支持 32 位 EFI 的 Linux 发行版。（我的 《[在 Linux 上管理 EFI 引导加载程序](http://www.rodsbooks.com/efi-bootloaders)》 一文概述了引导加载程序，而且理解了这些原则你就可以修改 32 位发行版的安装程序，尽管这不是一个初学者该做的。）在 64 位 EFI 的计算机上安装 32 位发行版最让人头疼，我不准备在这里描述这一过程；在具有 64 位 EFI 的计算机上，你应当使用 64 位的发行版。
* **正确准备引导介质** — 将 .iso 镜像传输到 USB 闪存驱动器的第三方工具，比如 unetbootin，在创建正确的 EFI 模式引导项时经常失败。我建议按照发行版维护者的建议来创建 USB 闪存驱动器。如果没有类似的建议，使用 Linux 的 dd 工具，通过执行 `dd if=image.iso of=/dev/sdc` 在识别为 `/dev/sdc` 的 USB 闪存驱动器上创建一个镜像。至于 Windows，有 [WinDD](https://sourceforge.net/projects/windd/) 和 [dd for windows](http://www.chrysocome.net/dd)，但我从没测试过它们。请注意，使用不兼容 EFI 的工具创建安装介质是错误的，这会导致人们进入在 BIOS 模式下安装然后再纠正它们的误区，所以不要忽视这一点！
* **备份 ESP 分区** — 如果计算机已经存在 Windows 或者其它的操作系统，我建议在安装 Linux 之前备份你的 ESP 分区。尽管 Linux *不应该* 损坏 ESP 分区已有的文件，但似乎这时不时发生。发生这种事情时备份会有很大用处。只需简单的文件级的备份（使用 cp，tar，或者 zip 类似的工具）就足够了。
* **以 EFI 模式启动** — 以 BIOS/CSM/legacy 模式引导 Linux 安装程序的意外非常容易发生，特别是当固件启用 CSM/legacy 选项时。下面一些提示可以帮助你避免此问题：
	+ 进入 Linux shell 环境执行 `ls /sys/firmware/efi` 验证当前是否处于 EFI 引导模式。如果你看到一系列文件和目录，表明你已经以 EFI 模式启动，而且可以忽略以下多余的提示；如果没有，表明你是以 BIOS 模式启动的，应当重新检查你的设置。
	+ 使用固件内置的引导管理器（你应该已经知道在哪；请参阅“了解如何使用固件”）使之以 EFI 模式启动。一般你会看到 CD-R 或 USB 闪存驱动器两个选项，其中一个选项包括 *EFI* 或 *UEFI* 字样的描述，另一个不包括。使用 EFI/UEFI 选项来启动介质。
	+ 禁用安全启动 - 即使你使用的发行版官方支持安全启动，有时它们也不能生效。在这种情况下，计算机会静默的转到下一个引导加载程序，它可能是启动介质的 BIOS 模式的引导加载程序，导致你以 BIOS 模式启动。请参阅我的[安全启动的相关文章](http://www.rodsbooks.com/efi-bootloaders/secureboot.html#disable)以得到禁用安全启动的相关提示。
	+ 如果 Linux 安装程序总是无法以 EFI 模式启动，试试用我的 [rEFInd 引导管理器](http://www.rodsbooks.com/refind/getting.html) 制作的 USB 闪存驱动器或 CD-R。如果 rEFInd 启动成功，那它保证是以 EFI 模式运行的，而且在基于 UEFI 的 PC 上，它只显示 EFI 模式的引导项，因此若您启动到 Linux 安装程序，则应处于 EFI 模式。（但是在 Mac 上，除了 EFI 模式选项之外，rEFInd 还显示 BIOS 模式的引导项。）
* **准备 ESP 分区** — 除了 Mac，EFI 使用 ESP 分区来保存引导加载程序。如果你的计算机已经预装了 Windows，那么 ESP 分区就已存在，可以在 Linux 上直接使用。如果不是这样，那么我建议创建一个大小为 550 MB 的 ESP 分区。（如果你已有的 ESP 分区比这小，别担心，直接用就行。）在此分区上创建一个 FAT32 文件系统。如果你使用 Gparted 或者 parted 准备 ESP 分区，记得给它一个“启动标记”。如果你使用 GPT fdisk（gdisk，cgdisk 或 sgdisk）准备 ESP 分区，记得给它一个名为 EF00 的类型码。有些安装程序会创建一个较小的 ESP 分区，并且设置为 FAT16 文件系统。尽管这样能正常工作，但如果你之后需要重装 Windows，安装程序会无法识别 FAT16 文件系统的 ESP 分区，所以你需要将其备份后转为 FAT32 文件系统。
* **使用 ESP 分区** — 不同发行版的安装程序以不同的方式辨识 ESP 分区。比如，Debian 和 Ubuntu 的某些版本把 ESP 分区称为“EFI boot partition”，而且不会明确显示它的挂载点（尽管它会在后台挂载）；但是有些发行版，像 Arch 或 Gentoo，需要你去手动挂载。尽管将 ESP 分区挂载到 /boot 进行相应配置后可以正常工作，特别是当你想使用 gummiboot 或 ELILO（译者注：gummiboot 和 ELILO 都是 EFI 引导工具）时，但是在 Linux 中最标准的 ESP 分区挂载点是 /boot/efi。某些发行版的 /boot 不能用 FAT 分区。因此，当你设置 ESP 分区挂载点时，请将其设置为 /boot/efi。除非 ESP 分区没有，否则*不要*为其新建文件系统 — 如果已经安装 Windows 或其它操作系统，它们的引导文件都在 ESP 分区里，新建文件系统会销毁这些文件。
* **设置引导程序的位置** — 某些发行版会询问将引导程序（GRUB）装到何处。如果 ESP 分区按上述内容正确标记，不必理会此问题，但有些发行版仍会询问。请尝试使用 ESP 分区。
* **其它分区** — 除了 ESP 分区，不再需要其它的特殊分区；你可以设置 根（/）分区，swap 分区，/home 分区，或者其它分区，就像你在 BIOS 模式下安装时一样。请注意 EFI 模式下*不需要设置*[BIOS 启动分区](https://en.wikipedia.org/wiki/BIOS_Boot_partition)，所以如果安装程序提示你需要它，意味着你可能意外的进入了 BIOS 模式。另一方面，如果你创建了 BIOS 启动分区，会更灵活，因为你可以安装 BIOS 模式下的 GRUB，然后以任意模式（EFI 模式 或 BIOS 模式）引导。
* **解决无显示问题** — 2013 年，许多人在 EFI 模式下经常遇到（之后出现的频率逐渐降低）无显示的问题。有时可以在命令行下通过给内核添加 `nomodeset` 参数解决这一问题。在 GRUB 界面按 `e` 键会打开一个简易文本编辑器。大多数情况下你需要搜索有关此问题的更多信息，因为此问题更多是由特定硬件引起的。


在某些情况下，你可能不得不以 BIOS 模式安装 Linux。但你可以手动安装 EFI 引导程序让 Linux 以 EFI 模式启动。请参阅《 [在 Linux 上管理 EFI 引导加载程序](http://www.rodsbooks.com/efi-bootloaders/)》 页面获取更多有关它们以及如何安装的可用信息。


### 解决安装后的问题


如果 Linux 无法在 EFI 模式下工作，但在 BIOS 模式下成功了，那么你可以完全放弃 EFI 模式。在只有 Linux 的计算机上这非常简单；安装 BIOS 引导程序即可（如果你是在 BIOS 模式下安装的，引导程序也应随之装好）。如果是和 EFI 下的 Windows 组成双系统，最简单的方法是安装我的 [rEFInd 引导管理器](http://www.rodsbooks.com/refind/)。在 Windows 上安装它，然后编辑 `refind.conf` 文件：取消注释 `scanfor` 一行，并确保拥有 `hdbios` 选项。这样 rEFInd 在引导时会重定向到 BIOS 模式的引导项。


如果重启后计算机直接进入了 Windows，很可能是 Linux 的引导程序或管理器安装不正确。（但是应当首先尝试禁用安全启动；之前提到过，它经常引发各种问题。）下面是关于此问题的几种可能的解决方案：


* **使用 efibootmgr** — 你可以以 *EFI 模式*引导一个 Linux 急救盘，使用 efibootmgr 实用工具尝试重新注册你的 Linux 引导程序，如[这里](http://www.rodsbooks.com/efi-bootloaders/installation.html)所述。
* **使用 Windows 上的 bcdedit** — 在 Windows 管理员命令提示符窗口中，输入 `bcdedit /set {bootmgr}path \EFI\fedora\grubx64.efi` 会用 ESP 分区的 `EFI/fedora/grubx64.efi` 文件作为默认的引导加载程序。根据需要更改此路径，指向你想设置的引导文件。如果你启用了安全启动，需要设置 `shim.efi`，`shimx64.efi` 或者 `PreLoader.efi`（不管有哪个）为引导而不是 `grubx64.efi`。
* **安装 rEFInd** — 有时候 rEFInd 可以解决这个问题。我推荐使用 [CD-R 或者 USB 闪存驱动器](http://www.rodsbooks.com/refind/getting.html)进行测试。如果 Linux 可以启动，就安装 Debian 软件包、RPM 程序，或者 .zip 文件包。（请注意，你需要在一个高亮的 Linux vmlinuz\* 选项按两次 `F2` 或 `Insert` 修改启动选项。如果你的启动分区是单独的，这就更有必要了，因为这种情况下，rEFInd 无法找到根（/）分区，也就无法传递参数给内核。）
* **使用修复引导程序** — Ubuntu 的[引导修复实用工具](https://help.ubuntu.com/community/Boot-Repair)可以自动修复一些问题；然而，我建议只在 Ubuntu 和 密切相关的发行版上使用，比如 Mint。有时候，有必要通过高级选项备份并替换 Windows 的引导。
* **劫持 Windows 引导程序** — 有些不完整的 EFI 引导只能引导 Windows，就是 ESP 分区上的 `EFI/Microsoft/Boot/bootmgfw.efi` 文件。因此，你可能需要将引导程序改名（我建议将其移动到上级目录 `EFI/Microsoft/bootmgfw.efi`），然后将首选引导程序复制到这里。（大多数发行版会在 EFI 的子目录放置 GRUB 的副本，例如 Ubuntu 的 EFI/ubuntu，Fedora 的 EFI/fedora。）请注意此方法是个丑陋的解决方法，有用户反映 Windows 会替换引导程序，所以这个办法不是 100% 有效。然而，这是在不完整的 EFI 上生效的唯一办法。在尝试之前，我建议你升级固件并重新注册自己的引导程序，Linux 上用 efibootmgr，Windows 上用 bcdedit。


有关引导程序的其它类型的问题 - 如果 GRUB（或者你的发行版默认的其它引导程序或引导管理器）没有引导操作系统，你必须修复这个问题。因为 GRUB 2 引导 Windows 时非常挑剔，所以 Windows 经常启动失败。在某些情况下，安全启动会加剧这个问题。请参阅[我的关于 GRUB 2 的页面](http://www.rodsbooks.com/efi-bootloaders/grub2.html)获取一个引导 Windows 的 GRUB 2 示例。还会有很多原因导致 Linux 引导出现问题，类似于 BIOS 模式下的情况，所以我没有全部写出来。


尽管 GRUB 2 使用很普遍，但我对它的评价却不高 - 它很复杂，而且难以配置和使用。因此，如果你在使用 GRUB 的时候遇到了问题，我的第一反应就是用别的东西代替。[我的用于 Linux 的 EFI 引导程序页面](http://www.rodsbooks.com/efi-bootloaders)有其它的选择。其中包括我的 [rEFInd 引导管理器](http://www.rodsbooks.com/refind/)，它除了能够让许多发行版上的 GRUB 2 工作，也更容易安装和维护 - 但是它还不能完全代替 GRUB 2。


除此之外，EFI 引导的问题可能很奇怪，所以你需要去论坛发帖求助。尽量将问题描述完整。[Boot Info Script](http://sourceforge.net/projects/bootinfoscript/) 可帮助你提供有用的信息 - 运行此脚本，将生成的名为 RESULTS.txt 的文件粘贴到论坛的帖子上。一定要将文本粘贴到 `[code]` 和 `[/code]` 之间；不然会遭人埋怨。或者将 RESULTS.txt 文件上传到 pastebin 网站上，比如 [pastebin.com](http://pastebin.com/)，然后将网站给你的 URL 地址发布到论坛。


### 哎呀：将传统模式下安装的系统转为 EFI 模式下引导


**警告：**这些指南主要用于基于 UEFI 的 PC。如果你的 Mac 已经安装了 BIOS 模式下的 Linux，但想以 EFI 模式启动 Linux，可以*在 OS X* 中安装引导程序。rEFInd（或者旧式的 rEFIt）是 Mac 上的常用选择，但 GRUB 可以做的更多。


论坛上有很多人看了错误的教程，在已经存在 EFI 模式的 Windows 的情况下，安装了 BIOS 引导的 Linux，这一问题在 2015 年初很普遍。这样配置效果很不好，因为大多数 EFI 很难在两种模式之间切换，而且 GRUB 也无法胜任这项工作。你可能会遇到不完善的 EFI 无法启动外部介质的情况，也可能遇到 EFI 模式下的显示问题，或者其它问题。


如前所述，在“解决安装后的问题”部分，解决办法之一就是*在 Windows* 上安装 rEFInd，将其配置为支持 BIOS 模式引导。然后可以引导 rEFInd 并链式引导到你的 BIOS 模式的 GRUB。在 Linux 上遇到 EFI 特定的问题时，例如无法使用显卡，我建议你使用这个办法修复。如果你没有这样的 EFI 特定的问题，在 Windows 中安装 rEFInd 和合适的 EFI 文件系统驱动可以让 Linux 直接以 EFI 模式启动。这个解决方案很完美，它和我下面描述的内容等同。


大多数情况下，最好将 Linux 配置为以 EFI 模式启动。有很多办法可以做到，但最好的是使用 Linux 的 EFI 引导模式（或者，可以想到，Windows，或者一个 EFI shell）注册到你首选的引导管理器。实现这一目标的方法如下：


1. 下载适用于 USB 闪存驱动器或 CD-R 的 [rEFInd 引导管理器](http://www.rodsbooks.com/refind/getting.html)。
2. 从下载的镜像文件生成安装介质。可以在任何计算机上准备，不管是 EFI 还是 BIOS 的计算机都可以（或者在其它平台上使用其它方法）。
3. 如果你还没有这样做，[请禁用安全启动](http://www.rodsbooks.com/efi-bootloaders/secureboot.html#disable)。因为 rEFInd CD-R 和 USB 镜像不支持安全启动，所以这很必要，你可以在以后重新启用它。
4. 在目标计算机上启动 rEFInd。如前所述，你可能需要调整固件设置，并使用内置引导管理器选择要引导的介质。你选择的那一项也许在其描述中包含 *UEFI* 这样的字符串。
5. 在 rEFInd 上测试引导项。你应该至少看到一个启动 Linux 内核的选项（名字含有 vmlinuz 这样的字符串）。有两种方法可以启动它：


	* 如果你*没有*独立的 `/boot` 分区，只需简单的选择内核并按回车键。Linux 就会启动。
	* 如果你*确定有*一个独立的 `/boot` 分区，按两次 `Insert` 或 `F2` 键。这样会打开一个行编辑器，你可以用它来编辑内核选项。增加一个 `root=` 格式以标识根（/）文件系统，如果根（/）分区在 `/dev/sda5` 上，就添加 `root=/dev/sda5`。如果不知道根文件系统在哪里，那你需要重启并尽可能想到办法。在一些罕见的情况下，你可能需要添加其它内核选项来代替或补充 `root=` 选项。比如配置了 LVM（LCTT 译注：Logical Volume Manager，逻辑卷管理）的 Gentoo 就需要 `dolvm` 选项。
6. Linux 一旦启动，安装你想要的引导程序。rEFInd 的安装很简单，可以通过 RPM、Debian 软件包、PPA，或从[rEFInd 下载页面](http://www.rodsbooks.com/refind/getting.html)下载的二进制 .zip 文件进行安装。在 Ubuntu 和相关的发行版上，引导修改程序可以相对简单地修复你的 GRUB 设置，但你要对它有信心可以正常工作。（它通常工作良好，但有时候会把事情搞得一团糟。）另外一些选项都在我的 《[在 Linux 上管理 EFI 引导加载程序](http://www.rodsbooks.com/efi-bootloaders/)》 页面上。
7. 如果你想在安全启动激活的情况下引导，只需重启并启用它。但是，请注意，可能需要额外的安装步骤才能将引导程序设置为使用安全启动。有关详细信息，请参阅[我关于这个主题的页面](http://www.rodsbooks.com/efi-bootloaders/secureboot.html)或你的引导程序有关安全启动的文档资料。


重启时，你可以看到刚才安装的引导程序。如果计算机进入了 BIOS 模式下的 GRUB，你应当进入固件禁用 BIOS/CSM/legacy 支持，或调整引导顺序。如果计算机直接进入了 Windows，那么你应当阅读前一部分，“解决安装后的问题”。


你可能想或需要调整你的配置。通常是为了看到额外的引导选项，或者隐藏某些选项。请参阅引导程序的文档资料，以了解如何进行这些更改。


### 参考和附加信息


* **信息网页**
	+ 我的 《[在 Linux 上管理 EFI 引导加载程序](http://www.rodsbooks.com/efi-bootloaders/)》 页面含有可用的 EFI 引导程序和引导管理器。
	+ [OS X's bless tool 的手册页](http://ss64.com/osx/bless.html) 页面在设置 OS X 平台上的引导程序或引导管理器时可能会很有用。
	+ [EFI 启动过程](http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/efi-boot-process.html) 描述了 EFI 启动时的大致框架。
	+ [Arch Linux UEFI wiki page](https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface) 有大量关于 UEFI 和 Linux 的详细信息。
	+ 亚当·威廉姆森写的一篇不错的 《[什么是 EFI，它是怎么工作的](https://www.happyassassin.net/2014/01/25/uefi-boot-how-does-that-actually-work-then/)》。
	+ [这个页面](http://www.eightforums.com/tutorials/20256-uefi-firmware-settings-boot-inside-windows-8-a.html) 描述了如何从 Windows 8 调整 EFI 的固件设置。
	+ 马修·J·加勒特是 Shim 引导程序的开发者，此程序支持安全启动，他维护的[博客](http://mjg59.dreamwidth.org/)经常更新有关 EFI 的问题。
	+ 如果你对 EFI 软件的开发感兴趣，我的 《[EFI 编程](http://www.rodsbooks.com/efi-programming/)》 页面可以为你起步助力。
* **附加程序**
	+ [rEFInd 官网](http://www.rodsbooks.com/refind/)
	+ [gummiboot 官网](http://freedesktop.org/wiki/Software/gummiboot)
	+ [ELILO 官网](http://elilo.sourceforge.net/)
	+ [GRUB 官网](http://www.gnu.org/software/grub/)
	+ [GPT fdisk 分区软件官网](http://www.rodsbooks.com/gdisk/)
	+ Ubuntu 的 [引导修复实用工具](https://help.ubuntu.com/community/Boot-Repair)可帮助解决一些引启动问题
* **交流**
	+ [Sourceforge 上的 rEFInd 交流论坛](https://sourceforge.net/p/refind/discussion/)是 rEFInd 用户互相交流或与我联系的一种方法。
	+ Pastebin 网站，比如 [http://pastebin.com](http://pastebin.com/)， 是在 Web 论坛上与其他用户交换大量文本的一种便捷的方法。


（题图：Pixabay，CC0）




---


via: <http://www.rodsbooks.com/linux-uefi/>


作者：[Roderick W. Smith](rodsmith@rodsbooks.com) 译者：[fuowang](https://github.com/fuowang) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
# Linux on UEFI:

A Quick Installation Guide

by Roderick W. Smith, [rodsmith@rodsbooks.com](mailto:rodsmith@rodsbooks.com)

Originally written: 10/19/2013; last modified: 3/16/2015

This Web page is provided free of charge and with no annoying outside ads; however, I did take time to prepare it, and Web hosting does cost money. If you find this Web page useful, please consider making a small donation to help keep this site up and running. Thanks!

Donate $1.00 |
Donate $2.50 |
Donate $5.00 |
Donate $10.00 |
Donate $20.00 |
Donate another value |

|
|
|
|
|
|



[
]## Introduction

For several years, a new firmware technology has been lurking in the wings, unknown to most ordinary users. Known as the [Extensible Firmware Interface (EFI),](https://en.wikipedia.org/wiki/Uefi) or more recently as the Unified EFI (UEFI, which is essentially EFI 2.*x*), this technology has begun replacing the older [Basic Input/Output System (BIOS)](https://en.wikipedia.org/wiki/BIOS) firmware with which most experienced computer users are at least somewhat familiar.

This page is a quick introduction to EFI for Linux users, including advice on getting started installing Linux to such a computer. Unfortunately, EFI is a dense topic; the EFI software itself is complex, and many implementations have system-specific quirks and even bugs. Thus, I cannot describe everything you'll need to know to install and use Linux on an EFI computer on this one page. It's my hope that you'll find this page a useful starting point, though, and links within each section and in the [References](#references) section at the end will point you toward additional documentation.

## Does Your Computer Use EFI?

EFI is a type of *firmware,* meaning that it's software built into the computer to handle low-level tasks. Most importantly, the firmware controls the computer's boot process, which in turn means that EFI-based computers boot differently than do BIOS-based computers. (A partial exception to this rule is described shortly.) This difference can greatly complicate the design of OS installation media, but it has little effect on the day-to-day operation of the computer, once everything is set up and running. Note that most manufacturers use the term "BIOS" to refer to their EFIs. I consider this usage confusing, so I avoid it; in my view, EFIs and BIOSes are two different types of firmware.

EFI has been used on Intel-based Macs since they were first introduced in 2006. Beginning in late 2012, most computers that ship with Windows 8 or later boot using UEFI by default, and in fact most PCs released since mid-2011 use UEFI, although they may not boot in EFI mode by default. A few PCs sold prior to 2011 also support EFI, although most such computers boot in BIOS mode by default.

If you're uncertain about your computer's EFI support status, you should check your firmware setup utility and your user manual for references to *EFI*, *UEFI*, or *legacy booting*. (Searching a PDF of your user manual can be a quick way to do this.) If you find no such references, your computer probably uses an old-style ("legacy") BIOS; but if you find references to these terms, it almost certainly uses EFI. You can also try booting a medium that contains *only* an EFI-mode boot loader. The USB flash drive or CD-R image of [rEFInd](http://www.rodsbooks.com/refind/getting.html) is a good choice for this test.

Before proceeding further, you should understand that most EFIs on *x*86 and *x*86-64 computers include a component known as the *Compatibility Support Module (CSM),* which enables the EFI to boot OSes using the older BIOS-style boot mechanisms. This can be a great convenience because it provides backwards compatibility; but it also creates complications because there's no standardization in the rules and user interfaces for controlling when a computer boots in EFI mode vs. when it boots in BIOS (aka CSM or legacy) mode. In particular, it's far too easy to accidentally boot your Linux installation medium in BIOS/CSM/legacy mode, which will result in a BIOS/CSM/legacy-mode installation of Linux. This can work fine if Linux is your only OS, but it complicates the boot process if you're dual-booting with Windows in EFI mode. (The opposite problem can also occur.) The following sections should help you boot your installer in the right mode. If you're reading this page after you've installed Linux in BIOS mode and want to switch boot modes, read the upcoming section, [Oops: Converting a Legacy-Mode Install to Boot in EFI Mode.](#oops)

One optional feature of UEFI deserves mention: *Secure Boot.* This feature is designed to minimize the risk of a computer becoming infected with a *boot kit,* which is a type of malware that infects the computer's boot loader. Boot kits can be particularly difficult to detect and remove, which makes blocking them a priority. Microsoft requires that all desktop and laptop computers that bear a Windows 8 logo ship with Secure Boot enabled. This type of configuration complicates Linux installation, although some distributions handle this problem better than do others. Do not confuse Secure Boot with EFI or UEFI, though; it's possible for an EFI computer to not support Secure Boot, and it's possible to disable Secure Boot even on *x*86-64 EFI computers that support it. Microsoft requires that users can disable Secure Boot for Windows 8 certification on *x*86 and *x*86-64 computers; however, this requirement is reversed for ARM computers—such computers that ship with Windows 8 must *not* permit the user to disable Secure Boot. Fortunately, ARM-based Windows 8 computers are currently rare. I recommend avoiding them.

## Does Your Distribution Support EFI?

Most Linux distributions have supported EFI for years. The quality of that support varies from one distribution to another, though. Most of the major distributions (Fedora, OpenSUSE, Ubuntu, and so on) provide good EFI support, including support for Secure Boot. Some more "do-it-yourself" distributions, such as Gentoo, have weaker EFI support, but their nature makes it easy to add EFI support to them. In fact, it's possible to add EFI support to *any* Linux distribution: You need to install it (even in BIOS mode) and then install an EFI boot loader on the computer. See the [Oops: Converting a Legacy-Mode Install to Boot in EFI Mode](#oops) section for information on how to do this.

You should check your distribution's feature list to determine if it supports EFI. You should also pay attention to your distribution's support for Secure Boot, particularly if you intend to dual-boot with Windows 8. Note that even distributions that officially support Secure Boot may require that this feature be disabled, since Linux Secure Boot support is often poor or creates complications.

## Preparing to Install Linux

A few preparatory steps will help make your Linux installation on an EFI-based computer go more smoothly:

**Upgrade your firmware**—Some EFIs are badly broken, but hardware manufacturers occasionally release updates to their firmware. Thus, I recommend upgrading your firmware to the latest version available. If you know from forum posts or the like that your EFI is problematic, you should do this before installing Linux, because some problems will require extra steps to correct if the firmware is upgraded after the installation. On the other hand, upgrading firmware is always a bit risky, so holding off on such an upgrade may be best if you've heard good things about your manufacturer's EFI support.
**Learn how to use your firmware**—You can usually enter a firmware setup utility by hitting the Del key or a function key early in the boot process. Check for prompts soon after you power on the computer or just try each function key. Similarly, the Esc key or a function key usually enters the firmware's built-in boot manager, which enables you to select which OS or external device to boot. Some manufacturers are making it hard to reach such settings. In some cases, you can do so from inside Windows 8, as described on [this page.](http://www.eightforums.com/tutorials/20256-uefi-firmware-settings-boot-inside-windows-8-a.html)
**Adjust the following firmware settings:**
**Fast boot**—This feature can speed up the boot process
by taking shortcuts in hardware initialization. Sometimes this is
fine, but sometimes it can leave USB hardware uninitialized, which
can make it impossible to boot from a USB flash drive or similar
device. Thus, disabling fast boot *may* be helpful, or even
required; but you can safely leave it active and deactivate it only
if you have trouble getting the Linux installer to boot. Note that
this feature sometimes goes by another name. In some cases, you
must *enable* USB support rather than *disable* a fast
boot feature.
**Secure Boot**—Fedora, OpenSUSE, Ubuntu, and some other
distributions officially support Secure Boot; but if you have
problems getting a boot loader or kernel to start, you might want
to disable this feature. Unfortunately, fully describing how to do
so is impossible because the settings vary from one computer to
another. See [my
Secure Boot page](http://www.rodsbooks.com/efi-bootloaders/secureboot.html#disable) for more on this topic.
**CSM/legacy options**—If you want to install in EFI mode,
set such options *off.* Some guides recommend enabling these
options, and in some cases they may be required—for instance,
they may be needed to enable the BIOS-mode firmware in some add-on
video cards. In most cases, though, enabling CSM/legacy support
simply increases the risk of inadvertently booting your Linux
installer in BIOS mode, which you do *not* want to do. Note
that Secure Boot and CSM/legacy options are sometimes intertwined,
so be sure to check each one after changing the other.

**Disable the Windows Fast Startup feature**—[This page](http://www.eightforums.com/tutorials/6320-fast-startup-turn-off-windows-8-a.html) describes how to disable this feature, which is almost certain to cause filesystem corruption if left enabled. Note that this feature is distinct from the firmware's fast boot feature.
**Check your partition table**—Using [GPT fdisk,](http://www.rodsbooks.com/gdisk/) `parted`, or any other partitioning tool, check your disk's partitions. Ideally, you should create a hardcopy that includes the exact start and end points (in sectors) of each partition. This will be a useful reference, particularly if you use a manual partitioning option in the installer. If Windows is already installed, be sure to identify your [EFI System Partition (ESP),](http://en.wikipedia.org/wiki/EFI_System_partition) which is a FAT partition with its "boot flag" set (in `parted` or GParted) or that has a type code of EF00 in `gdisk`.

## Installing Linux

Most Linux distributions provide adequate installation instructions; however, I've observed a few common stumbling blocks on EFI-mode installations:

**Ensure that you're using a distribution that's the right bit depth**—EFI runs boot loaders that are the same bit depth as the EFI itself. This is normally 64-bit for modern computers, although the first couple generations of Intel-based Macs, some modern tablets and convertibles, and a handful of obscure computers use 32-bit EFIs. I have yet to encounter a 32-bit Linux distribution that officially supports EFI, although it is possible to add a 32-bit EFI boot loader to 32-bit distributions. (My [Managing EFI Boot Loaders for Linux](http://www.rodsbooks.com/efi-bootloaders) covers boot loaders generally, and understanding those principles may enable you to modify a 32-bit distribution's installer, although that's not a task for a beginner.) Installing a 32-bit Linux distribution on a computer with a 64-bit EFI is difficult at best, and I don't describe the process here; you should use a 64-bit distribution on a computer with a 64-bit EFI.
**Properly prepare your boot medium**—Third-party tools for moving `.iso` images onto USB flash drives, such as `unetbootin`, often fail to create the proper EFI-mode boot entries. I recommend you follow whatever procedure your distribution maintainer suggests for creating USB flash drives. If no such recommendation is made, use the Linux `dd` utility, as in `dd if=image.iso of=/dev/sdc` to create an image on the USB flash drive on `/dev/sdc`. Ports of `dd` to Windows, such as [WinDD](https://sourceforge.net/projects/windd/) and `dd` for Windows, exist, but I've never tested them. Note that using tools that don't understand EFI to create your installation medium is one of the mistakes that leads people into the bigger mistake of installing in BIOS mode and then having to correct the ensuing problems, so don't ignore this point!
**Back up the ESP**—If you're installing to a computer that already boots Windows or some other OS, I recommend backing up your ESP before installing Linux. Although Linux *shouldn't* damage files that are already on the ESP, this does seem to happen from time to time. Having a backup will help in such cases. A simple file-level backup (using `cp`, `tar`, or `zip`, for example) should work fine.
**Booting in EFI mode**—It's too easy to accidentally boot your Linux installer in BIOS/CSM/legacy mode, particularly if you leave the CSM/legacy options enabled in your firmware. A few tips can help you to avoid this problem:
- You should verify an EFI-mode boot by dropping to a Linux shell and
typing
`ls /sys/firmware/efi`. If you see
a list of files and directories, you've booted in EFI mode and you
can ignore the following additional tips; if not, you've probably
booted in BIOS mode and should review your settings.
- Use your firmware's built-in boot manager (which you should have
located earlier; see
[Learn how to use
your firmware](#using_firmware)) to boot in EFI mode. Typically, you'll see two
options for a CD-R or USB flash drive, one of which includes the
string *EFI* or *UEFI* in its description, and one of
which does not. Use the EFI/UEFI option to boot your medium.
- Disable Secure Boot—Even if you're using a distribution that
officially supports Secure Boot, sometimes this doesn't work. In
this case, the computer will most likely silently move on to the
next boot loader, which could be your medium's BIOS-mode boot
loader, resulting in a BIOS-mode boot. See
[my
page on Secure Boot](http://www.rodsbooks.com/efi-bootloaders/secureboot.html#disable) for some tips on how to disable Secure
Boot.
- If you can't seem to get the Linux installer to boot in EFI mode,
try using a USB flash drive or CD-R version of my
[rEFInd boot
manager.](http://www.rodsbooks.com/refind/getting.html) If rEFInd boots, it's guaranteed to be running in EFI
mode, and on a UEFI-based PC, it will show only EFI-mode boot
options, so if you can then boot to the Linux installer, it should
be in EFI mode. (On Macs, though, rEFInd shows BIOS-mode boot
options in addition to EFI-mode options.)

**Preparing your ESP**—Except on Macs, EFIs use the ESP to hold boot loaders. If your computer came with Windows pre-installed, an ESP should already exist, and you can use it in Linux. If not, I recommend creating an ESP that's 550MiB in size. (If your existing ESP is smaller than this, go ahead and use it.) Create a FAT32 filesystem on it. If you use GParted or `parted` to prepare your disk, give the ESP a "boot flag." If you use GPT fdisk (`gdisk`, `cgdisk`, or `sgdisk`) to prepare the disk, give it a type code of EF00. Some installers create a smallish ESP and put a FAT16 filesystem on it. This usually works fine, although if you subsequently need to re-install Windows, its installer will become confused by the FAT16 ESP, so you may need to back it up and convert it to FAT32 form.
**Using the ESP**—Different distributions' installers have different ways of identifying the ESP. For instance, some versions of Debian and Ubuntu call the ESP the "EFI boot partition" and do not show you an explicit mount point (although it will mount it behind the scenes); but a distribution like Arch or Gentoo will require you to mount it. The closest thing to a standard ESP mount point in Linux is `/boot/efi`, although `/boot` works well with some configurations—particularly if you want to use gummiboot or ELILO. Some distributions won't let you use a FAT partition as `/boot`, though. Thus, if you're asked to set a mount point for the ESP, make it `/boot/efi`. Do *not* create a fresh filesystem on the ESP unless it doesn't already have one—if Windows or some other OS is already installed, its boot loader lives on the ESP, and creating a new filesystem will destroy that boot loader!
**Setting the boot loader location**—Some distributions may ask about the boot loader's (GRUB's) location. If you've properly flagged the ESP as such, this question should be unnecessary, but some distributions' installers still ask. Try telling it to use the ESP.
**Other partitions**—Other than the ESP, no other special partitions are required; you can set up root (`/`), swap, `/home`, or whatever else you like in the same way you would for a BIOS-mode installation. Note that you do *not* need a [BIOS Boot Partition](https://en.wikipedia.org/wiki/BIOS_Boot_partition) for an EFI-mode installation, so if your installer is telling you that you need one, this may be a sign that you've accidentally booted in BIOS mode. On the other hand, if you create a BIOS Boot Partition, that will give you some extra flexibility, since you'll be able to install a BIOS version of GRUB to boot in either mode (EFI or BIOS).
**Fixing blank displays**—A problem that many people had through much of 2013 (but with decreasing frequency since then) was blank displays when booted in EFI mode. Sometimes this problem can be fixed by adding `nomodeset` to the kernel's command line. You can do this by typing `e` to open a simple text editor in GRUB. In many cases, though, you'll need to research this problem in more detail, because it often has more hardware-specific causes.

In some cases, you may be forced to install Linux in BIOS mode. You can sometimes then manually install an EFI-mode boot loader for Linux to begin booting in EFI mode. See my [Managing EFI Boot Loaders for Linux](http://www.rodsbooks.com/efi-bootloaders/) page for information on available boot loaders and how to install them.

## Fixing Post-Installation Problems

If you can't seem to get an EFI-mode boot of Linux working but a BIOS-mode boot works, you can abandon EFI mode entirely. This is easiest on a Linux-only computer; just install a BIOS-mode boot loader (which the installer should have done if you installed in BIOS mode). If you're dual-booting with an EFI-mode Windows, though, the easiest solution is to install my [rEFInd boot manager.](http://www.rodsbooks.com/refind/) Install it from Windows and edit the `refind.conf` file: Uncomment the `scanfor` line and ensure that `hdbios` is among the options. This will enable rEFInd to redirect the boot process to a BIOS-mode boot loader. This solution works for many systems, but sometimes it fails for one reason or another.

If you reboot the computer and it boots straight into Windows, it's likely that your Linux boot loader or boot manager was not properly installed. (You should try disabling Secure Boot first, though; as I've said, it often causes problems.) There are several possible solutions to this problem:

**Use **`efibootmgr`—You can boot a Linux emergency disc *in EFI mode* and use the `efibootmgr` utility to re-register your Linux boot loader, as described [here.](http://www.rodsbooks.com/efi-bootloaders/installation.html)
**Use **`bcdedit` in Windows—In a Windows Administrator Command Prompt window, typing `bcdedit /set {bootmgr} path \EFI\fedora\grubx64.efi` will set the `EFI/fedora/grubx64.efi` file on the ESP as the default boot loader. Change that path as necessary to point to your desired boot loader. If you're booting with Secure Boot enabled, you should set `shim.efi`, `shimx64.efi`, or `PreLoader.efi` (whichever is present) as the boot program, rather than `grubx64.efi`.
**Install rEFInd**—Sometimes rEFInd can overcome this problem. I recommend testing by using the [CD-R or USB flash drive image.](http://www.rodsbooks.com/refind/getting.html) If it can boot Linux, install the Debian package, RPM, or `.zip` file package. (Note that you may need to edit your boot options by highlighting a Linux `vmlinuz*` option and hitting F2 or Insert twice. This is most likely to be required if you've got a separate `/boot` partition, since in this situation rEFInd can't locate the root (`/`) partition to pass to the kernel.)
**Use Boot Repair**—Ubuntu's [Boot Repair utility](https://help.ubuntu.com/community/Boot-Repair) can auto-repair some boot problems; however, I recommend using it only on Ubuntu and closely-related distributions, such as Mint. In some cases, it may be necessary to click the Advanced option and check the box to back up and replace the Windows boot loader.
**Hijack the Windows boot loader**—Some buggy EFIs boot only the Windows boot loader, which is called `EFI/Microsoft/Boot/bootmgfw.efi` on the ESP. Thus, you may need to rename this boot loader to something else (I recommend moving it down one level, to `EFI/Microsoft/bootmgfw.efi`) and putting a copy of your preferred boot loader in its place. (Most distributions put a copy of GRUB in a subdirectory of `EFI` named after themselves, such as `EFI/ubuntu` for Ubuntu or `EFI/fedora` for Fedora.) Note that this solution is an ugly hack, and some users have reported that Windows will replace its boot loader, so it may not even work 100% of the time. It is, however, the only solution that works on some badly broken EFIs. Before attempting this solution, I recommend upgrading your firmware and re-registering your own boot loader with `efibootmgr` in Linux or `bcdedit` in Windows.

Another class of problems relates to boot loader troubles—If you see GRUB (or whatever boot loader or boot manager your distribution uses by default) but it doesn't boot an OS, you must fix that problem. Windows often fails to boot because GRUB 2 is very finicky about booting Windows. This problem can be exacerbated by Secure Boot in some cases. See [my page on GRUB 2](http://www.rodsbooks.com/efi-bootloaders/grub2.html) for a sample GRUB 2 entry for booting Windows. Linux boot problems, once GRUB appears, can have a number of causes, and are likely to be similar to BIOS-mode Linux boot problems, so I don't cover them here.

Despite the fact that it's very common, my opinion of GRUB 2 is rather low—it's an immensely complex program that's difficult to configure and use. Thus, if you run into problems with GRUB, my initial response is to replace it with something else. [My Web page on EFI boot loaders for Linux](http://www.rodsbooks.com/efi-bootloaders) describes the options that are available. These include my own [rEFInd boot manager,](http://www.rodsbooks.com/refind/) which is much easier to install and maintain, aside from the fact that many distributions do manage to get GRUB 2 working—but if you're considering replacing GRUB 2 because of its problems, that's obviously not worked out for you!

Beyond these issues, EFI booting problems can be quite idiosyncratic, so you may need to post to a Web forum for help. Be sure to describe the problem as thoroughly as you can. The [Boot Info Script](http://sourceforge.net/projects/bootinfoscript/) can provide useful information—run it and it should produce a file called `RESULTS.txt` that you can paste into your forum post. Be sure to precede this pasted text with the string `[code]` and follow it with `[/code]`, though; otherwise people will complain. Alternatively, upload `RESULTS.txt` to a pastebin site, such as [pastebin.com,](http://pastebin.com) and post the URL that the site gives you.

[
]## Oops: Converting a Legacy-Mode Install to Boot in EFI Mode

As of early 2015, one very common problem I see in online forums is that people follow bad instructions and install Linux in BIOS mode to dual-boot with an existing EFI-mode Windows installation. This configuration works poorly because most EFIs make it difficult to switch between boot modes, and GRUB can't handle the task, either. You might also find yourself in this situation if you've got a very flaky EFI that simply won't boot an external medium in EFI mode, or if you have video or other problems with Linux when it's booted in EFI mode.

As noted earlier, in [Fixing Post-Installation Problems,](#troubleshooting) one possible solution to such problems is to install rEFInd *in Windows* and configure it to support BIOS-mode boots. You can then boot rEFInd and chainload to your BIOS-mode GRUB. I recommend this fix mainly when you have EFI-specific problems in Linux, such as a failure to use your video card. If you don't have such EFI-specific problems, installing rEFInd and a suitable EFI filesystem driver in Windows will enable you to boot Linux directly in EFI mode. This can be a perfectly good solution, and it will be equivalent to what I describe next.

In most cases, it's best to configure Linux to boot in EFI mode. There are many ways to do this, but the best way requires using an EFI-mode boot of Linux (or conceivably Windows or an EFI shell) to register an EFI-mode version of your preferred boot manager. One way to accomplish this goal is as follows:

- Download a USB flash drive or CD-R version of my
[rEFInd boot manager.](http://www.rodsbooks.com/refind/getting.html)
- Prepare a medium from the image file you've downloaded. You can do this from any computer, booted in either EFI or BIOS mode (or in other ways on other platforms).
- If you've not already done so,
[disable Secure Boot.](http://www.rodsbooks.com/efi-bootloaders/secureboot.html#disable) This is necessary because the rEFInd CD-R and USB images don't support Secure Boot. If you want to keep Secure Boot, you can re-enable it later.
- Boot rEFInd on your target computer. As described earlier, you may need to adjust your firmware settings and use the built-in boot manager to select your boot medium. The option you select may need to include the string
*UEFI* in its description.
- In rEFInd, examine the boot options. You should see at least one option for booting a Linux kernel (with a name that includes the string
`vmlinuz`). Boot it in one of two ways:
- If you do
*not* have a separate `/boot` partition,
simply highlight the kernel and press Enter. Linux should
boot.
- If you
*do* have a separate `/boot` partition, press
Insert or F2 twice. This action will open a line editor in which
you can edit your kernel options. Add a `root=`
specification to those options to identify your root (`/`)
filesystem, as in `root=/dev/sda5` if root (`/`) is
on `/dev/sda5`. If you don't know what your root filesystem
is, you should reboot in any way possible to figure it out.

In some rare cases, you may need to add other kernel options instead of or in addition to a `root=` option. Gentoo with an LVM configuration requires `dolvm`, for example.
- Once Linux is booted, install your desired boot program. rEFInd is usually pretty easy to install via the RPM, Debian package, PPA, or binary
`.zip` file referenced on the [rEFInd downloads page.](http://www.rodsbooks.com/refind/getting.html) On Ubuntu and similar distributions, Boot Repair can fix your GRUB setup relatively simply, but it will be a bit of a leap of faith that it will work correctly. (It usually works fine, but in some cases it will make a hash of things.) Other options are described on my [Managing EFI Boot Loaders for Linux](http://www.rodsbooks.com/efi-bootloaders/) page.
- If you want to boot with Secure Boot active, reboot and enable it. Note, however, that you may need to take extra installation steps to set up your boot program to use Secure Boot. Consult
[my page on the topic](http://www.rodsbooks.com/efi-bootloaders/secureboot.html) or your boot program's Secure Boot documentation for details.

When you reboot, you should see the boot program you just installed. If the computer instead boots into a BIOS-mode version of GRUB, you should enter your firmware and disable the BIOS/CSM/legacy support, or perhaps adjust your boot order options. If the computer boots straight to Windows, then you should read the preceding section, [Fixing Post-Installation Problems.](#troubleshooting)
You may want or need to tweak your configuration at this point. It's common to see extra boot options, or for an option you want to not be visible. Consult your boot program's documentation to learn how to make such changes.

[
]## References and Additional Information

**Informational Web pages**
**Additional programs**
**Communications**


copyright © 2013–2015 by Roderick W. Smith

If you have problems with or comments about this Web page, please e-mail me at [rodsmith@rodsbooks.com.](mailto:rodsmith@rodsbooks.com) Thanks.

[Return](http://www.rodsbooks.com/) to my main Web page.