问题描述
我想知道如何从ubuntu的源代码构建grub 2引导程序,并使用qemu模拟器对其进行测试.
I want to know how to build grub 2 bootloader from it's source in ubuntu and test it with qemu emulator.
我还想在新版本中更改grub2引导程序的默认背景图像吗?
I would also like to change the default background image of grub2 bootloader in the new build?
这可能吗?如果是,怎么办?
Is this possible? If yes, how ?
推荐答案
当然可以.
如 GRUB网站所示,grub源代码可从git.savannah.gnu.org通过git获得.
As shown on the GRUB website, the grub source code is available via git from git.savannah.gnu.org.
那么从理论上讲这只是一个问题
Then it is theoretically just a question of
$ ./autogen.sh
$ ./configure
$ make
$ sudo make install
但是,取决于您的平台,grub的默认目标平台可能不是您想要的.因此,您需要确定要在QEMU中使用的固件平台,具体取决于您的体系结构,
However, depending on your platform, grub's default target platform may or may not be what you want. So you will need to decide which firmware platform you want to use in QEMU, which depending on your architecture can be something like
- (pc)BIOS
- coreboot
- (U)EFI
- ieee1275(开放式固件)
- u-boot
您提到的Ubuntu至少匹配上述三个选项,但我会很无聊,并假设您的意思是x86_64/amd64.由于您将在QEMU下运行GRUB,因此物理计算机正在运行的两个可能平台("pc"或"efi")中的哪个并不重要.因此,让我们活一点,然后选择(U)EFI变体.
Your mentioning of Ubuntu matches at least 3 possible options from the above, but I'm going to be boring and assume you mean x86_64/amd64. Since you will be running GRUB under QEMU, it does not really matter which of the two likely platforms ("pc" or "efi") your physical computer is running. So let's live a little and go for the (U)EFI variant.
在配置和构建之前,您需要先安装一些先决条件,所以
You will need some prerequisites installed before configuring and building, so
$ sudo apt-get install build-essential autoconf automake
$ sudo apt-get build-dep grub-efi-amd64
因此,实际的构建可能看起来像这样:
So a practical build may look a bit like this:
$ # Next command is optionnal (languages):
$ ./linguas.sh
$ ./autogen.sh
$ # Next parameters are optionnal:
$ ./configure --prefix=$HOME/local --platform=efi
$ make
$ # Next command is optionnal:
$ make check
$ make install
获取正常运行的GRUB映像的最简单方法可能是使用grub-mkstandalone
命令:
The easiest way to get a functioning GRUB image is probably with the grub-mkstandalone
command:
$ $HOME/local/bin/grub-mkstandalone -O x86_64-efi -o mygrub.efi
注意:要在/dev/sda
磁盘(而不是QEMU)上安装grub,请使用:
Note: To install grub on /dev/sda
disk (instead of QEMU), use:
$ sudo grub-install /dev/sda
注意:如果在启动时没有看到GRUB菜单,请检查此问题.它涉及在引导或编辑/etc/default/grub
来注释GRUB_HIDDEN_TIMEOUT
时按.
Note: If you don't see GRUB menu when booting, check this question. It involves pressing when booting or editing /etc/default/grub
to comment GRUB_HIDDEN_TIMEOUT
.
然后,您需要某种UEFI映像才能在您的QEMU下运行. x86的默认选择称为OVMF,它是 Tianocore EDK2 的一部分-实际上是该版本的开源实现UEFI.由于有关重新分配FAT文件系统驱动程序的法律技术问题,许多Linux发行版(包括Ubuntu)不包括预构建的发行版.但是不用担心,自己打造一个人很简单.
Then you need some kind of UEFI image to run under your QEMU. The default choice for x86 is called OVMF and is part of Tianocore EDK2 - the de facto open source implementation of UEFI. Due to legal technicalities with regards to redistribution of the FAT filesystem driver, many Linux distributions (including Ubuntu) do not include a pre-built one. But have no fear, it is pretty straightforward to build one yourself.
但是,我不会把这个答案超出我已经拥有的范围,所以我要说的是通读 OVMF自述文件,然后浏览一个或两个仅略微过时的博客文章
However, I am not going to take this answer further off-topic than I already have, so all I am going to say is have a read through the OVMF README and look through one or two only slightly outdated blog posts about it.
这篇关于如何从源代码构建grub2引导程序并使用qemu模拟器对其进行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!