如何访问虚拟机中的 GRUB 菜单
虚拟机 GRUB
![](/data/attachment/album/202308/02/112939auzwfwyghswuoq6z.jpg)



> 
> 需要在虚拟机中访问 GRUB 菜单吗？以下是做法。
> 
> 
> 


大多数现代虚拟机都配置为跳过 [GRUB 引导加载程序](https://itsfoss.com/what-is-grub/) 以获得无缝体验。


但是，你有时可能需要访问 GRUB 菜单。例如，如果你想切换回旧内核或进入恢复模式以 [重置密码](https://itsfoss.com/how-to-hack-ubuntu-password/)。



> 
> ? TLDR：重启虚拟机并在再次启动时按住 `Shift` 键。这将为你提供 GRUB 菜单。
> 
> 
> 


在这篇简短的文章中，我将向你展示两种访问虚拟机中运行的 Linux 中的 GRUB 菜单的方法：


* 临时方案（当你需要访问 GRUB 一两次时）
* 永久方案（每次启动时都会显示 GRUB）


由于大多数用户不会每天与 GRUB 交互，因此我将从一个临时解决方案开始，你可以无需任何调整即可访问 GRUB。



> 
> ? 我在此处的教程中使用了 Ubuntu，但这些步骤也适用于其他 Linux 发行版。
> 
> 
> 


### 在虚拟机中访问 GRUB 引导加载程序（快速方式）


如果你偶尔想访问 GRUB，这应该是最好的方法，因为它不需要任何配置。


只需重新启动系统并按住 `shift` 键即可。


就是这样！


你将拥有没有任何时间限制的 GRUB 菜单：


![Accessing grub menu in VM using shift key](/data/attachment/album/202308/02/113020o12puzbvou8hxbvo.gif)


很简单的方法。不是吗？


但它仅适用于特定的启动。那么如果你想在每次启动时都进入 GRUB 该怎么办呢？ 请参考下面的方法。


### 永久在虚拟机中启用 GRUB 菜单（如果你愿意）



> 
> ? 此方法需要在命令行中更改 GRUB 配置文件。请确保你能够轻松地在终端中进行编辑。
> 
> 
> 


如果你需要处理 GRUB 菜单来访问其他操作系统或经常更改 [从旧内核启动](https://itsfoss.com/boot-older-kernel-default/)，那么此方法非常适合你。


要使 GRUB 在每次引导时都可访问，你必须在配置文件中进行更改。


首先，使用以下命令打开 GRUB 配置文件：



```
sudo nano /etc/default/grub

```

在这里，将 `GRUB_TIMEOUT_STYLE=hidden` 更改为 `GRUB_TIMEOUT_STYLE=menu`：


![change grub timeout style](/data/attachment/album/202308/02/113108a66646xbslr0xqz0.jpg)


接下来，在同一个配置文件中，指定你希望 GRUB 显示的秒数。


我建议 5 秒，因为它似乎在太长和太短之间取得了平衡（是的，非常相关）：



```
GRUB_TIMEOUT=5

```

![configure grub timeout in ubuntu](/data/attachment/album/202308/02/113115q6ybvgmv9bvmnztn.jpg)


最后，你可以 [保存更改并退出 nano](https://linuxhandbook.com/nano-save-exit/) 编辑器。


要激活对配置文件所做的更改，请使用以下命令更新 GRUB：



```
sudo update-grub

```

就是这样。重启系统，GRUB 应该会显示 5 秒钟。


### 将 GRUB 主题化如何？


大多数 Linux 发行版都会使用 GRUB 引导加载程序，因为它的配置非常简单，而且能完成工作。


但在默认情况下，除了黑色背景和纯文本外，它没什么样式。因此，我们制作了一份指南，教你如何让它看起来更漂亮：



> 
> **[定制 GRUB 以获得更好的体验](https://itsfoss.com/customize-grub-linux/)**
> 
> 
> 


希望本指南对你有所帮助，如果你有任何疑问，请在评论中告诉我。


*（题图：MJ/f75daf37-20c2-4bae-8a68-dc6a82ad0d61）*




---


via: <https://itsfoss.com/access-grub-virtual-machine/>


作者：[Sagar Sharma](https://itsfoss.com/author/sagar/) 选题：[lkxed](https://github.com/lkxed/) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


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


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

Most modern VMs are configured to skip the [GRUB bootloader](https://itsfoss.com/what-is-grub/) for a seamless experience.

However, you might need to access the GRUB menu at times. For example, if you want to switch back to the older kernel or get into recovery mode for [resetting the password](https://itsfoss.com/how-to-hack-ubuntu-password/).

Reboot your VM and keep the Shift key pressed when it is booting up again. This should give you the GRUB menu.

In this quick article, I will be showing you two ways to access the GRUB menu in Linux running in a virtual machine:

- A temporary solution (when you have to access GRUB once or twice)
- A permanent solution (will show GRUB at every boot)

As most of the users are not going to interact with the grub on a daily basis, I will start with a temporary solution in which you can access the grub without any tweaks.

I have used Ubuntu in the tutorial here but the steps should be valid for other Linux distributions as well.

## Access the GRUB bootloader in VM (Quick way)

If you want to access the GRUB occasionally, this is supposed to be the best way as it does not require any configuration.

Just reboot your system and keep the `shift`

key pressed.

That's it!

You will have your grub menu without any time limit:

![Accessing grub menu in VM using shift key](https://itsfoss.com/content/images/2023/07/access-GRUB-in-Ubuntu-VM.gif)

Pretty simple way. Isn't it?

But it will work for that specific boot only. So what if you want to have the grub on every boot? Refer to the given method.

## Enable Grub menu in virtual machines permanently (if you want to)

This method requires changing Grub config file in the command line. Please ensure that you are comfortable doing the edits in the terminal.

If you have to deal with the grub menu to access the other operating systems or change[ boot from the older kernels](https://itsfoss.com/boot-older-kernel-default/) often, this method is just for you.

To make the grub accessible at every boot, you must make changes in the configuration file.

First, open the grub config file using the following command:

`sudo nano /etc/default/grub`


Here, change the `GRUB_TIMEOUT_STYLE=hidden`

to the `GRUB_TIMEOUT_STYLE=menu`

:

![change grub timeout style](https://itsfoss.com/content/images/2023/07/change-grub-style.webp)

Next, in the same config file, specify for how many seconds you want the grub to be displayed.

I would recommend 5 seconds as it seems to balance between not too long and short (yep, quite relatable):

`GRUB_TIMEOUT=5`


![configure grub timeout in ubuntu](https://itsfoss.com/content/images/2023/07/configure-grub-timeout-in-ubuntu.webp)

And finally, you can [save the changes and exit from the nano](https://linuxhandbook.com/nano-save-exit/) text editor.

To activate the changes you made to the config file, update the grub using the following command:

`sudo update-grub`


That's it. Reboot your system and the grub should be there for 5 seconds.

## How about theming GRUB?

You will get the grub bootloader in most of the Linux distros as it is quite simple to configure and gets the job done.

But by default, it's nothing apart from the black background and plain text. So we made a guide on how you can make it look dope:

[Customize Grub to Get a Better Experience With LinuxCouple of Grub configuration tweaks to get better experience with multi-boot Linux system using Grub Customizer GUI tool.](https://itsfoss.com/customize-grub-linux/)![](https://itsfoss.com/content/images/wordpress/2016/02/customize-grub.png)


![](https://itsfoss.com/content/images/wordpress/2016/02/customize-grub.png)

I hope you will find this guide helpful and if you have any queries, let me know in the comments.