I would like to display the grub
menu from the command line. Also to select a grub boot menu option and press Enter to see what pre-kernel drivers are loaded and the boot parameters passed when loading the kernel.
The reasons to do this from the command line:
- Rebooting to see the
grub
menu takes time. - It is awkward to take a picture of the
grub
menu and post the image on websites. It is easier grabbing a screen shot when Ubuntu is up and running. - To
edit
grub menu option withe
and take a picture is often difficult because screen is hard to read. With this function you could copy and paste instead. - It might be easier using this function to reveal all kernel versions rather than
apt list --installed | grep linux-image
orls /boot/vml*
. - To quickly see the grub menu number is valuable for
grub-reboot
andgrub-set-default
commands.
How can I paint the grub menu from the command line, see internal grub menu entry numbers and display the boot parameters for a given option?
Updated May 7, 2018
Developing the script: Bash script to clone Ubuntu to new partition for testing 18.04 LTS upgrade I discovered you get some ridiculously long menu options that causes the menu to malign:
This was fixed today by truncating lines longer than 68 characters.
Updated April 5, 2018
This update introduces
grub-menu.sh
a much superior version to previous answer (still available below). The new grub menu features:0
,1
,1>0
,1>1
...2
,3
(upstart)
and(recover mode)
submenu options can be set.short
orlong
to override default.short
orlong
setting.Color Screen shot (short version)
Text Screen shot (long version)
grub-menu.sh
bash scriptPrevious versions
grub-display.sh
andgrub-display-lite.sh
required many tweaking options in the code.grub-menu.sh
only has one option to tweak:Set the value to
true
orfalse
.The default format can be overridden when calling the script using:
or:
The code:
Previous versions (not recommended)
Below is the original answer where menu entry numbers followed the grub 1 format.
grub-display.sh
displays grub menu options and parametersWithout relying on third party applications you can use a bash script to display the
grub
menu and the boot parameters for any given option. The boot parameters are more than just thecat /proc/cmdline
values. They also include the drivers loaded before Linux is booted.grub-display.sh
bash scriptHere is the full program listing you can copy and paste:
Note to Ubuntu Server users
This bash script was designed for Ubuntu Desktop. For Ubuntu Server and other Linux Distros that do not have
dialog
package installed by default, a different script calledgrub-display-lite.sh
is included below. That version useswhiptail
instead ofdialog
.Reducing the menu size by 66%
To shorten the grub menu option list displayed you can remove the
(upstart)
and(recovery)
options. To do this uncomment these lines:Then apply comments to these lines:
Screenshots
Here's what it looks like when invoked from the command line. Unfortunately I was not able to copy and paste the menu and had to use Print Screen:
Turn off mouse support for copy & paste
When the default mouse support is enabled, you can't copy the screen to the clipboard but must use Print Screen for a graphical screen snapshot. In order to support copy & paste you need disable mouse support by searching for these lines:
The argument
--no-mouse
has been inserted below--default-item
. This means you loose mouse support but gain better resolution and copy to clipboard ability by highlighting text and pressing Ctrl+C.Display grub boot parameters
Use the navigation keys to highlight an option and press Enter to see the boot parameters for it:
Grub menu entry #94
Grub menu entry #96
grub-display-lite.sh
for Ubuntu ServerUbuntu Server and Lubuntu do not have
dialog
package installed by default like Ubuntu Desktop has. A different version has been written for these users based on thewhiptail
package which is included by default on most Linux Distributions.The disadvantage of
whiptail
is less functions but they aren't used in this case. Another disadvantage appears to be less colors but that can make it easier to read for some people. There are advantages towhiptail
overdialog
such as copy to clipboard, mouse scroll wheel support and probably faster processing.grub-display-lite.sh
bash scriptThe
grub-display-lite.sh
bash script is basically the same asgrub-display.sh
except there is no error message ifdialog
isn't installed. Also somewhiptail
arguments have different names.grub-display-lite.sh
screenshotsThe colour screen seems to be easier to read than
grub-display
which usesdialog
package:Here is the text based image which needs no modifications to copy to clipboard:
As mentioned above you can reduce the size of the grub menu displayed here by 66% when removing
(upstart)
and(recovery)
menu options. Such is the case here but as a consequence the detail lines get narrower and the headings don't line up perfectly. You can tweak the column headings by changing this line:to something like this:
Use Grub Customizer. a.k.a.
sudo apt install grub-customizer
.An alternative way to have a preview of grub menu (not so powerful as the most voted answer, but I think it may be useful to add this alternative) is to install the package grub-emu (it is available in Ubuntu repository) by running in a terminal the command:
sudo apt-get install grub-emu
According to https://packages.ubuntu.com this package is for sure available since Ubuntu 16.04, and still available now that I'm running Ubuntu 20.04.
One remark: in order to navigate the menu with the keyboard, you need to have the window terminal from where you run grub-emu in foreground.
See the image: keeping the terminal in foreground, you can use the arrows and Enter buttons the check every item in the list. To close grub-emu you can press 'c' and then write 'exit'. I use it to check my color settings (when I'm tired of them and I want to change them) and to check the timeouts (for item activation when no iem is selected)