[gentoo-user] UEFI 安装指导

143 views
Skip to first unread message

microcai

unread,
Jul 6, 2014, 10:14:43 AM7/6/14
to gentoo...@googlegroups.com
UEFI 的主板现在非常普遍了吧,不过很多人还在使用 BIOS 模式安装系统吧。
下面给点 UEFI 模式使用 Gentoo 的 tips

关于引导程序:
UEFI 模式下能使用的引导程序非常非常多, UEFI 本身就是一个非常好用的引导程序。不过各个主板参差不齐,而且并没有通用的引导管理器。这个主板下的一套经验换个主板就得重新看说明书,不好不好。 so,还是选择独立的引导管理器比较好。

1) grub-efi
grub-efi 是 grub1 的 EFI 补丁版,我从 fedora 的仓库里提取出来的。EFI 补丁并没有合并到上游,因为上游搞 grub2 去了。 在 gentoo-zh overlay 里, 就有 sys-boot/grub-efi 这个包。安装了即可。安装好后, 拷贝 /usr/lib/grub/grub.efi 到 ESP 然后配置 UEFI (后面讲)。

2) grub2
grub2 也有 EFI 支持,不过要设定好 USE, 要这样安装 GRUB_PLATFORMS="efi-64" emerge grub。安装好了就可以使用 grub2-install 命令进行安装。不过我从来没有成功过,所以一直用的 grub1 的 EFI 补丁版


3) gummiboot
gummiboot 是我强烈推荐的一个引导管理器。因为 gummiboot 是目前唯一一个实现了 systemd 规定的 BootLoaderSpec 的引导管理器。可以实现 systemd 的一些高级功能。后面讲。


UEFI 的启动。
和BIOS 不一样, UEFI 支持从文件启动。BIOS 只是把启动过程交给了启动设备上的第一个扇区里的引导程序,而 UEFI 却做到了,支持文件系统。 UEFI 可以访问硬盘上一个特殊分区(ESP),可以从这个分区直接加载 EFI 格式的可执行程序。扩展名 .efi。就像操作系统加载可执行文件一样。

许多UEFI主板都提供了设置,可以设定启动用的 .efi 文件名。不过,多数主板都不支持在主板设置界面修改,只是默认加载 EFI\Boot\Bootx64.efi 而已。不过可以在系统里通过 efibootmgr 设定。

ESP 是个特殊分区, 用 gdisk 分区一个类型是 EF00 的分区,然后格式化成 FAT 格式即可。如果有好几个 ESP 分区, UEFI 只会认一个。别建好多个哦!

手工设定:

创建好 ESP 后,挂载到 /boot 。然后拷贝 kernel 和 bootloader 过去。以 grub-efi 为例,是建立一个 EFI/Boot 文件夹,然后把 grub.efi 拷贝到 /boost/EFI/Boot/bootx64.efi , 当然, grub.conf 也得拷贝到 /boost/EFI/Boot/bootx64.conf 才行。这样就设定好了,重启系统,进入主板的 Boot 设置项里,就可以看到 UEFI OS(xxx) 这样的选项了。xxxx 这里应该是分区的 GUID。不同的主板应该大同小异。把该选项设为默认启动项就可以了。

efibootmgr 设定:(emerge efibootmgr)

创建好 ESP 后,挂载到 /boot 。然后拷贝 kernel 和 bootloader 过去。以 grub-efi 为例, 拷贝到 /boot/grub.efi 即可。然后使用 efibootmgr -c -L "GRUB" -l \\grub.efi 即可创建了。

如果 ESP 还不是第一个分区(强烈建议是第一个分区啊!)得使用 -p 参数。

UEFI 里路径是 ESP 为根路径的,切记哈。ESP 分区可能是挂载到 /boot 目录的。记得设定的时候去掉 /boot ,呵呵。 也有一些发行版是将 ESP 挂载到 /boot/EFI , 然后 /boot 又搞个 ext2 分区。 比如说redhat.... 不过我是建议直接搞个 ESP 挂到 /boot 即可。

gummiboot 设定:

gummiboot 要求 ESP 挂载到 /boot 呢!

emerge gummiboot
gummiboot install
就完成安装了,会自动创建 /EFI/Boot/Bootx64.efi 了。

gummiboot 的配置比较另类,使用文件夹配置,而不是配置文件。按照 gummiboot 的要求把 ESP 挂载到 /boot
因为 linux 内核里 make install 默认就会创建 /boot/vmlinuz 文件了,所以 我们这里创建一个默认的 gummiboot 配置文件,启动 vmlinuz 文件

文件 /boot/loader.conf
default vmlinuz


文件 /boot/loader/entries/vmlinuz.conf
title Latest VMLINUZ kernel EFI image
linux /vmlinuz
options net.ifnames=0 quiet ro root=PARTUUID=76CCEF12-46FB-4CA3-8D84-FBB68AE93385 rootfstype=ext4

这样就配置好了。呵呵。


关于 BootLoaderSpec

systemd 提出了一个标准, BootLoaderSpec , 在这个标准下, systemd 能实现额外的功能,像 systemd-analyze 能显示额外的时间信息,但是这个不是重点,重点是, systemd 能在 没有 fstab 文件的情况下挂载 / 和 /boot /home 分区!

需要使用 gdisk 为磁盘分区的时候,为分区设定好分区类型 ID , 按照 systemd 的要求设定好分区类型,指定的分区就会自动挂载到对应的目录。
如果 bootloader 不支持 BootLoaderSpec , 就算你设定好了, systemd 还是不会自动挂载的哦!

至于哪种类型挂载到哪个目录,下面给个表格
好吧,有点乱,各位到 man systemd-gpt-auto-generator 下看吧。


Table 1. Partition Type GUIDs
┌─────────────────────────────────────┬─────────────────────────────┬──────────────────────────────┐
│Partition Type GUID │ Name │ Explanation │
├─────────────────────────────────────┼─────────────────────────────┼──────────────────────────────┤
│44479540-f297-41b2-9af7-d131d5f0458a │ Root Partition (x86) │ On 32-bit x86 systems, the │
│ │ │ first x86 root partition on │
│ │ │ the disk the EFI ESP is │
│ │ │ located on is mounted to the │
│ │ │ root directory /. │
├─────────────────────────────────────┼─────────────────────────────┼──────────────────────────────┤
│4f68bce3-e8cd-4db1-96e7-fbcaf984b709 │ Root Partition (x86-64) │ On 64-bit x86 systems, the │
│ │ │ first x86-64 root partition │
│ │ │ on the disk the EFI ESP is │
│ │ │ located on is mounted to the │
│ │ │ root directory /. │
├─────────────────────────────────────┼─────────────────────────────┼──────────────────────────────┤
│69dad710-2ce4-4e3c-b16c-21a1d49abed3 │ Root Partition (32-bit ARM) │ On 32-bit ARM systems, the │
│ │ │ first ARM root partition on │
│ │ │ the disk the EFI ESP is │
│ │ │ located on is mounted to the │
│ │ │ root directory /. │
├─────────────────────────────────────┼─────────────────────────────┼──────────────────────────────┤
│b921b045-1df0-41c3-af44-4c6f280d3fae │ Root Partition (64-bit ARM) │ On 64-bit ARM systems, the │
│ │ │ first ARM root partition on │
│ │ │ the disk the EFI ESP is │
│ │ │ located on is mounted to the │
│ │ │ root directory /. │
├─────────────────────────────────────┼─────────────────────────────┼──────────────────────────────┤
│933ac7e1-2eb4-4f13-b844-0e14e2aef915 │ Home Partition │ The first home partition on │
│ │ │ the disk the root partition │
│ │ │ is located on is mounted to │
│ │ │ /home. │
├─────────────────────────────────────┼─────────────────────────────┼──────────────────────────────┤
│3b8f8425-20e0-4f3b-907f-1a25a76f98e8 │ Server Data Partition │ The first server data │
│ │ │ partition on the disk the │
│ │ │ root partition is located on │
│ │ │ is mounted to /srv. │
├─────────────────────────────────────┼─────────────────────────────┼──────────────────────────────┤
│0657fd6d-a4ab-43c4-84e5-0933c84b4f4f │ Swap │ All swap partitions located │
│ │ │ on the disk the root │
│ │ │ partition is located on are │
│ │ │ enabled. │
└─────────────────────────────────────┴─────────────────────────────┴──────────────────────────────┘

如果已经分区好了,可以
gdisk /dev/sda
然后使用 t 命令修改即可。

================================================================================================================================v

关于内核和 efibootmgr

内核要在 EFI 下启动,必须开启
CONFIG_EFI_PARTITION=y
CONFIG_EFI=y
但是,要想 efibootmgr 能用,还得开启
CONFIG_EFI_VARS=y
而且这个选项也是 systemd 的 EFI 下扩增的一些功能发挥的前提,所以这个选项不建议关闭。

那么
CONFIG_EFI_PARTITION=y
CONFIG_EFI=y
CONFIG_EFI_VARS=y
这三个选项基本上属于必须开启的咯。

要想 UEFI 直接能启动内核而不需要引导程序,就得开启
CONFIG_EFI_STUB=y
如果使用 gummiboot 这个也必须开启。


安装 gentoo 的时候,如果 liveCD 不是 EFI 模式启动的,那么是无法使用 efibootmgr 的。可以参考上面,手工创建 EFI/Boot/Bootx64.efi 即可。
有了 efibootmgr 就对 引导程序所在的文件夹和文件名没要求了,自己随意设定了。呵呵。


刘洋

unread,
Jul 6, 2014, 10:36:43 AM7/6/14
to gentoo...@googlegroups.com
很好,正在纠结要不要迁移到UEFI呢,我还在用grub1……

Tolbkni Kao

unread,
Jul 7, 2014, 12:08:34 AM7/7/14
to gentoo...@googlegroups.com
真及时,看起来我被 GRUB2 坑了一个周末……

Tolbkni Kao

unread,
Jul 7, 2014, 9:49:42 PM7/7/14
to gentoo...@googlegroups.com
GRUB2 跑起来了,是被 genkernel 坑了,还是自己 build kernel 靠谱


在 2014年7月7日 下午12:08,Tolbkni Kao <tol...@gmail.com>写道:
真及时,看起来我被 GRUB2 坑了一个周末……

tlze

unread,
Jul 7, 2014, 10:35:26 PM7/7/14
to gentoo...@googlegroups.com
如果liveCD不是EFI模式启动的,grub2-install是安装不成功,已经试过了,不过手工复制文件也能启动。
> --
> 发帖: gentoo...@googlegroups.com
> 退订: gentoo-china...@googlegroups.com
> 论坛: http://forums.gentoo.org/viewforum-f-50.html

Tolbkni Kao

unread,
Jul 7, 2014, 10:47:57 PM7/7/14
to gentoo...@googlegroups.com
嗯,通过检查 /sys/firmware/efi 目录能确认是否是 EFI 模式启动

Yang Year

unread,
Jan 5, 2015, 5:57:21 AM1/5/15
to gentoo...@googlegroups.com
文件 /boot/loader/entries/vmlinuz.conf中
PARTUUID应该怎么填?是对应下面表格中Partition Type GUID 栏的内容吗?

Tolbkni Kao

unread,
Jan 6, 2015, 8:47:29 AM1/6/15
to gentoo...@googlegroups.com
是的

在 2015年1月5日 下午6:57,Yang Year <yyrd...@gmail.com>写道:
文件 /boot/loader/entries/vmlinuz.conf中
PARTUUID应该怎么填?是对应下面表格中Partition Type GUID 栏的内容吗?
Reply all
Reply to author
Forward
0 new messages