grub2-install: 错误: /boot/efi 在全新的 Gentoo 安装中看起来不像 EFI 分区

jww*_*jww 7 linux gentoo partitioning grub2

我需要一台 Gentoo 13 机器来测试平台上的一些软件。我不是 Gentoo 的常客,所以我正在忍受他们的安装过程。我正在 配置引导加载程序 | 安装 GRUB2,它失败了:

# grub2-install --target=x86_64-efi --efi-directory=/boot
Installing for x86_64-efi platform.
grub2-install: error: /boot doesn't look like an EFI partition.
Run Code Online (Sandbox Code Playgroud)

我回溯到准备磁盘 | 默认值:使用 parted 对磁盘进行分区,看来我已按照说明进行了设置:

(chroot) Gentoo-2012 / # parted
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit mb                                                          
(parted) print                                                            
Model: ATA VMware Virtual I (scsi)
Disk /dev/sda: 21475MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End      Size     File system     Name    Flags
 1      1.05MB  3.15MB   2.10MB                   grub    bios_grub
 2      3.15MB  131MB    128MB    ext2            boot    boot, esp
 3      131MB   2572MB   2441MB   linux-swap(v1)  swap    msftdata
 4      2572MB  21474MB  18902MB  ext4            rootfs  msftdata
Run Code Online (Sandbox Code Playgroud)

以上结果来自手册的同一章,将文件系统应用于分区激活交换分区部分

我也跟着评论EFI directory should not be /boot but /boot/efi from Bootloader questions and questions on the Gentoo forum,但它导致了同样的错误:

(chroot) Gentoo-2012 / # mkdir /boot/efi
(chroot) Gentoo-2012 / # grub2-install --target=x86_64-efi --boot-directory=/boot --efi-directory=/boot/efi
Installing for x86_64-efi platform.
grub2-install: error: /boot/efi doesn't look like an EFI partition.
Run Code Online (Sandbox Code Playgroud)

有什么问题,我该如何解决?


这是上面fdisk提供的信息的相应视图gparted

(chroot) Gentoo-2012 / # fdisk -l
Disk /dev/loop0: 3.3 GiB, 3567640576 bytes, 6968048 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes    

Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 52F5571A-808B-XXXX-XXXX-XXXXXXXX

Device       Start      End  Sectors  Size Type
/dev/sda1     2048     6143     4096    2M BIOS boot
/dev/sda2     6144   255999   249856  122M EFI System
/dev/sda3   256000  5023743  4767744  2.3G Microsoft basic data
/dev/sda4  5023744 41940991 36917248 17.6G Microsoft basic data
Run Code Online (Sandbox Code Playgroud)

我还验证了该软件包sys-boot/grub支持 EFI:

(chroot) Gentoo-2012 / # cat /etc/portage/make.conf | grep GRUB
GRUB_PLATFORMS="emu efi-32 efi-64 pc"
Run Code Online (Sandbox Code Playgroud)

然后我执行了emerge --ask --newuse sys-boot/grub, emerge -pv sys-boot/grub,然后重建grub.

Tom*_*Yan 15

答案很简单。EFI 系统分区 (ESP) 应该是 FAT32(FAT16 甚至 FAT12 也适用于最合适的 UEFI;它们主要vfat在 Linux 中显示)而不是 ext2:

mkfs.fat -F32 /dev/sda2
Run Code Online (Sandbox Code Playgroud)

FWIW,如果您不打算安装 grub i386-pc(用于 BIOS/CSM 引导),则不需要“BIOS 引导”分区。只有GPT 上的grub i386-pc(而不是 grubx86_64-efii386-efi)需要它。

您是否将 ESP 用于/boot. 如果你这样做,你应该运行:

grub2-install --efi-directory /boot
Run Code Online (Sandbox Code Playgroud)

如果你安装它/boot/efi,那么你应该运行:

grub2-install --efi-directory /boot/efi
Run Code Online (Sandbox Code Playgroud)

--boot-directory /boot是隐含的(即默认);无论/boot是 ESP、另一个单独的分区还是/文件系统上的目录都无关紧要。

您甚至可能不需要再次 chroot 来执行grub2-install;例如,您安装了sda4,您的分区用于/, on /mnt; 然后,mounted sda2,你的 ESP,on /mnt/boot/efi,然后你可以简单地运行:

grub2-install --boot-directory /mnt/boot --efi-directory /mnt/boot/efi
Run Code Online (Sandbox Code Playgroud)

虽然grub2-mkconfig需要在 chroot AFAIK 中运行。但是,如果您打算grub.cfg自己编写一个简单而干净的程序(这是使用 grub2 的唯一优雅方式),那么您就不必担心了。


jww*_*jww 3

问题似乎出在 BIOS、EFI、MBR 和 GPT 的混合和匹配上。我尝试遵循指南并使用 GPT,但有一些依赖项我无法解决,因为我太缺乏经验了。我什至不清楚内核是使用 GPT 支持构建的(通过配置选项CONFIG_EFI_PARTITION)。

当我放弃 GPT 和 EFI 并切换到纯 BIOS 和 MBR 时,我能够启动最终的机器。BIOS 和 GPT 应该是一个有效的组合,但我想知道它在实践中是否有效(例如,参见Bootloader Options)。

这是我能够运行机器的配置:

$ parted
GNU Parted 3.2
Using /dev/sda
(parted) print                                                            
Model: ATA VMware Virtual I (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system     Flags
 1      1049kB  135MB   134MB   primary  ext2            boot
 2      135MB   19.5GB  19.3GB  primary  ext4
 3      19.5GB  21.5GB  2012MB  primary  linux-swap(v1)
Run Code Online (Sandbox Code Playgroud)

分区 1 是/boot,分区 2 是/,分区 3 是swap