Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
getting grub to show current boot menu [SOLVED]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
mjbjr
Apprentice
Apprentice


Joined: 02 Mar 2003
Posts: 223

PostPosted: Sat Dec 31, 2016 10:24 am    Post subject: getting grub to show current boot menu [SOLVED] Reply with quote

Grub is working fine and I don't have any boot problems.

Currently, grub is working automatically and finding various kernels
that I have available and showing them to me in the boot menu, all using
its default configurations.

My issue is that I want to do some boot menu customizations, but I
don't want to start messing around with custom configurations until
I understand the what/when/how of the boot menu it's currently generating.

Is there a way to get grub, or some other program, to generate a
representation of the current boot menu list using the current grub
configuration files. A list that I can cursor up and down through to get
the properties of each boot menu item? A boot menu browser if you will.

All of this without rebooting into the real grub boot menu.

This would be useful for validating a customization before actually
committing to it to stone.

Looking around the web on this issue I've noticed that ubuntu has a
program call grub-customizer, a gui app for viewing and customizing grub.
That sounds real nice, but I could make do with just viewing/validating at
this point.

Any ideas?

Thanks.
.


Last edited by mjbjr on Wed Jan 04, 2017 1:02 am; edited 1 time in total
Back to top
View user's profile Send private message
Roman_Gruber
Advocate
Advocate


Joined: 03 Oct 2006
Posts: 3806
Location: Austro Bavaria

PostPosted: Sat Dec 31, 2016 12:14 pm    Post subject: Reply with quote

I use an older grub.

The config file i always edit is: /boot/grub/grub.cfg


there is a value for the default section to load.

and every boot entry starts with title

there are many examples on the net for different grub background and such. just reuse what you find.

Just keep sysrescue-cd handy, and how to chroot in your installation when you mess up. and make backup of that confg file when you edit it

--

https://gpo.zugaina.org/Search?search=grub


kde-misc/kgrubeditor
A KDE utility that edits GRUB configuration files
app-admin/grubconfig
Simple Tool to configure Grub-Bootloader
Back to top
View user's profile Send private message
dufeu
l33t
l33t


Joined: 30 Aug 2002
Posts: 874
Location: US-FL-EST

PostPosted: Sat Dec 31, 2016 12:25 pm    Post subject: Reply with quote

The grub menu you see is generated from scripts in /etc/grub.d. On my current system:
Code:
-rwxr-xr-x 1 root root  8684 Dec 14 23:55 00_header
-rwxr-xr-x 1 root root  9454 Dec 14 23:55 10_linux
-rwxr-xr-x 1 root root 10451 Dec 14 23:55 20_linux_xen
-rwxr-xr-x 1 root root 11301 Dec 14 23:55 30_os-prober
-rwxr-xr-x 1 root root  1624 Aug  8 10:46 39_memtest86+
-rwxr-xr-x 1 root root   472 Nov 28  2015 40_custom
-rwxr-xr-x 1 root root   216 Dec 14 23:55 41_custom
-rw-r--r-- 1 root root   483 Dec 14 23:55 README

When I want to see the generated menu entries, I execute:
grep menuentry /boot/grub/grub.cfg:
if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
  menuentry_id_option=""
export menuentry_id_option
menuentry 'Gentoo GNU/Linux' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-ed1790a7-87e6-466c-a68c-e375303fd99f' {
submenu 'Advanced options for Gentoo GNU/Linux' $menuentry_id_option 'gnulinux-advanced-ed1790a7-87e6-466c-a68c-e375303fd99f' {
        menuentry 'Gentoo GNU/Linux, with Linux 4.8.15-gentoo' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.8.15-gentoo-advanced-ed1790a7-87e6-466c-a68c-e375303fd99f' {
        menuentry 'Gentoo GNU/Linux, with Linux 4.8.15-gentoo (recovery mode)' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.8.15-gentoo-recovery-ed1790a7-87e6-466c-a68c-e375303fd99f' {
        menuentry 'Gentoo GNU/Linux, with Linux 4.8.9-gentoo' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.8.9-gentoo-advanced-ed1790a7-87e6-466c-a68c-e375303fd99f' {
        menuentry 'Gentoo GNU/Linux, with Linux 4.8.9-gentoo (recovery mode)' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.8.9-gentoo-recovery-ed1790a7-87e6-466c-a68c-e375303fd99f' {
        menuentry 'Memtest86+' {
        menuentry 'Memtest86+ (netbsd)' {
menuentry "System Rescue CD iso" {

You get a little extra noise but all the generated menu entries are there.

The 'System Rescue CD' entry you see comes from the local changes made to /etc/grub.d/40-custom. Whenever I do an install, I set aside a small partition to hold a copy of the systemrescuecd iso I used for the install. Unless the hard drive is trashed, I can always boot the systemrescuecd if I need to.

The /etc/grub.d/39-memtest86+ is installed by the 'memtest86+' package.

All else is default. You can see from the dates that which scripts you don't want to modify. The last update to grub I did was Dec 14. ;)

In /boot, whenever I update my kernel, I keep the last previous known good kernel in addition to the newly generated kernel. I generally keep my kernel pretty up-to-date {about once a month}. This is because I'm a heavy user of btrfs and I've found it helpful to always keep btrfs functionality as is reasonably {for me} current as possible. Note that grub-mkconfig will create an entry for each kernel it finds in /boot. The generated menu entries for these are always newest kernel first. The first generated menu entry is always your default. You can change this behavior by modifying the related script /etc/grub.d/10-linux.

For these reasons, I don't edit /boot/grub/grub.cfg. Instead, after adding the newest kernel and cleaning out 3rd gen kernel{s}, I simply run
grub-mkconfig -o /boot/grub/grub.cfg:
Generating grub configuration file ...
Found linux image: /boot/kernel-4.8.15-gentoo
Found initrd image: /boot/initramfs-genkernel-x86_64-4.8.15-gentoo
Found linux image: /boot/kernel-4.8.9-gentoo
Found initrd image: /boot/initramfs-genkernel-x86_64-4.8.9-gentoo
Found memtest image: /boot/memtest86plus/memtest
Found memtest image: /boot/memtest86plus/memtest.netbsd
done

The message to tell me that it's built an entry for System Rescue CD doesn't display because I forgot to include one in the 40-custom script. But the 'grep' tells me it's there.

No muss. No fuss. This is simplest and works for me. YMMV and all that. ;)
_________________
People whom think M$ is mediocre, don't know the half of it.
Back to top
View user's profile Send private message
mjbjr
Apprentice
Apprentice


Joined: 02 Mar 2003
Posts: 223

PostPosted: Sat Dec 31, 2016 8:29 pm    Post subject: Reply with quote

dufeu wrote:

When I want to see the generated menu entries, I execute:[code="grep menuentry /boot/grub/grub.cfg"]
...

You get a little extra noise but all the generated menu entries are there.

The 'System Rescue CD' entry you see comes from the local changes made to /etc/grub.d/40-custom. Whenever I do an install, I set aside a small partition to hold a copy of the systemrescuecd iso I used for the install. Unless the hard drive is trashed, I can always boot the systemrescuecd if I need to.

The /etc/grub.d/39-memtest86+ is installed by the 'memtest86+' package.

All else is default. You can see from the dates that which scripts you don't want to modify. The last update to grub I did was Dec 14. ;)

In /boot, whenever I update my kernel, I keep the last previous known good kernel in addition to the newly generated kernel. I generally keep my kernel pretty up-to-date {about once a month}. This is because I'm a heavy user of btrfs and I've found it helpful to always keep btrfs functionality as is reasonably {for me} current as possible. Note that grub-mkconfig will create an entry for each kernel it finds in /boot. The generated menu entries for these are always newest kernel first. The first generated menu entry is always your default. You can change this behavior by modifying the related script /etc/grub.d/10-linux.

For these reasons, I don't edit /boot/grub/grub.cfg. Instead, after adding the newest kernel and cleaning out 3rd gen kernel{s}, I simply run[code="grub-mkconfig -o /boot/grub/grub.cfg"]Generating grub configuration file ...
Found linux image: /boot/kernel-4.8.15-gentoo
Found initrd image: /boot/initramfs-genkernel-x86_64-4.8.15-gentoo
Found linux image: /boot/kernel-4.8.9-gentoo
Found initrd image: /boot/initramfs-genkernel-x86_64-4.8.9-gentoo
Found memtest image: /boot/memtest86plus/memtest
Found memtest image: /boot/memtest86plus/memtest.netbsd
done[/code]
The message to tell me that it's built an entry for System Rescue CD doesn't display because I forgot to include one in the 40-custom script. But the 'grep' tells me it's there.

No muss. No fuss. This is simplest and works for me. YMMV and all that. ;)


All good stuff thanks, especially the command to generate the menu.

One thing missing is not seeing the drive/file_path to the kernels.
Any way to get that?

Thanks

Have a safe New Year's celebration.

- Martin -
Back to top
View user's profile Send private message
goldfinch
n00b
n00b


Joined: 16 Oct 2015
Posts: 11

PostPosted: Sat Dec 31, 2016 8:39 pm    Post subject: Reply with quote

There's grub-emu.

You can set GRUB_PLATFORMS in make.conf to include emu.

For example:

Code:
GRUB_PLATFORMS="pc emu"


Code:
emerge -av grub


Run grub-emu in a terminal (as root). That will show you the exact same menu that grub.cfg produces when you boot.

Code:
# grub-emu


Edit: You can get out of the menu interface by pressing 'c' for a grub command-line and typing 'exit' at the prompt.
Back to top
View user's profile Send private message
mjbjr
Apprentice
Apprentice


Joined: 02 Mar 2003
Posts: 223

PostPosted: Sun Jan 01, 2017 7:18 am    Post subject: Reply with quote

goldfinch wrote:
There's grub-emu.

You can set GRUB_PLATFORMS in make.conf to include emu.

For example:

Code:
GRUB_PLATFORMS="pc emu"


Code:
emerge -av grub


Run grub-emu in a terminal (as root). That will show you the exact same menu that grub.cfg produces when you boot.

Code:
# grub-emu


Edit: You can get out of the menu interface by pressing 'c' for a grub command-line and typing 'exit' at the prompt.


.

I had high hopes for this. I followed your instructions and the grub boot menu did pop-up in another terminal window,
but it would not accept any keyboard input, after the timeout period it auto-selected the default, but that caused it
to display errors that it couldn't find the drive (?) with the UUID-xxxxx..., eventually, after timing out, it went back to
the default menu page, but it wouldn't accept keyboard input ('c') and I had to 'kill -9 pid' to clear it.

Tried it again with the same result.

The error about not finding the UUID drive had me scared that the system got screwed up and might not reboot,
but it rebooted fine.

Thanks for your suggestion.
Back to top
View user's profile Send private message
dufeu
l33t
l33t


Joined: 30 Aug 2002
Posts: 874
Location: US-FL-EST

PostPosted: Sun Jan 01, 2017 9:41 pm    Post subject: Reply with quote

mjbjr wrote:
One thing missing is not seeing the drive/file_path to the kernels.
Any way to get that?
Sure. Another grep of /boot/grub/grub.cfg will list all the places where grub expects to find some kind of boot executable:
grep 'root=' /boot/grub/grub.cfg :
set root='hd0,gpt5'
        set root='hd0,gpt2'
        linux   /kernel-4.8.15-gentoo root=UUID=ed1790a7-87e6-466c-a68c-e375303fd99f ro 
                set root='hd0,gpt2'
                linux   /kernel-4.8.15-gentoo root=UUID=ed1790a7-87e6-466c-a68c-e375303fd99f ro 
                set root='hd0,gpt2'
                linux   /kernel-4.8.15-gentoo root=UUID=ed1790a7-87e6-466c-a68c-e375303fd99f ro single
                set root='hd0,gpt2'
                linux   /kernel-4.8.9-gentoo root=UUID=ed1790a7-87e6-466c-a68c-e375303fd99f ro 
                set root='hd0,gpt2'
                linux   /kernel-4.8.9-gentoo root=UUID=ed1790a7-87e6-466c-a68c-e375303fd99f ro single
                set root='hd0,gpt2'
                set root='hd0,gpt2'
        set root='hd0,gpt4

Note that a boot executable doesn't have to be a linux kernel. It can be an program like memtest86, a Windows boot sector, a grub mounted ISO image as well.

For most people taking a more or less default approach to grub, there will always be at least 3 entries. The first entry is your normal default boot. The second and thrid entries will be your sub-menu entries for those times you choose to not let grub proceed with your normal defautl boot. I have five kernel entries because I always have two kernels in /boot. My remaining three entries point to two instances of memtest86 and the last to my System Rescue CD ISO.

I'm assuming you're interested in what path and which kernels grub is seeing and this grep command will do it for you.

BTW - Do not let yourself get confused by the two completely different uses of 'root=' that you see. The
Code:
set root=
sets an internal script variable while
Code:
root=UUUID={text string}
is a boot path string being passed grub showing grub the way to your kernel. It's the latter instance of 'root=' that you're interested in.
_________________
People whom think M$ is mediocre, don't know the half of it.
Back to top
View user's profile Send private message
mjbjr
Apprentice
Apprentice


Joined: 02 Mar 2003
Posts: 223

PostPosted: Mon Jan 02, 2017 6:38 am    Post subject: Reply with quote

dufeu wrote:
mjbjr wrote:
One thing missing is not seeing the drive/file_path to the kernels.
Any way to get that?
Sure. Another grep of /boot/grub/grub.cfg will list all the places where grub expects to find some kind of boot executable
Note that a boot executable doesn't have to be a linux kernel. It can be an program like memtest86, a Windows boot sector, a grub mounted ISO image as well.

For most people taking a more or less default approach to grub, there will always be at least 3 entries. The first entry is your normal default boot. The second and thrid entries will be your sub-menu entries for those times you choose to not let grub proceed with your normal defautl boot. I have five kernel entries because I always have two kernels in /boot. My remaining three entries point to two instances of memtest86 and the last to my System Rescue CD ISO.

I'm assuming you're interested in what path and which kernels grub is seeing and this grep command will do it for you.

BTW - Do not let yourself get confused by the two completely different uses of 'root=' that you see. The
Code:
set root=
sets an internal script variable while
Code:
root=UUUID={text string}
is a boot path string being passed grub showing grub the way to your kernel. It's the latter instance of 'root=' that you're interested in.


Thanks for all the help, I appreciate it.
.
Back to top
View user's profile Send private message
dufeu
l33t
l33t


Joined: 30 Aug 2002
Posts: 874
Location: US-FL-EST

PostPosted: Mon Jan 02, 2017 1:12 pm    Post subject: Reply with quote

mjbjr wrote:
Thanks for all the help, I appreciate it.

No problem. I rely on people here for a hand myself from time to time. I give back when I can. ;)

You should probably mark the thread as [Solved] {edit the subject line of your first post}.

BTW - I'm a big believer in "simple". That's why I do a lot using the CMI. It's avoids loading yet another GUI based package {and all of that packages' dependencies}, is usually easier to explain to others and generally works. This is especially true for admin type tasks. I will use GUI based packages for certain admin tasks, but I feel they really have to offer something beyond whatever I can do 'by hand'.

Glad this helped.
_________________
People whom think M$ is mediocre, don't know the half of it.
Back to top
View user's profile Send private message
goldfinch
n00b
n00b


Joined: 16 Oct 2015
Posts: 11

PostPosted: Mon Jan 02, 2017 6:39 pm    Post subject: Reply with quote

mjbjr wrote:
goldfinch wrote:
There's grub-emu.


I had high hopes for this. I followed your instructions and the grub boot menu did pop-up in another terminal window,
but it would not accept any keyboard input, after the timeout period it auto-selected the default, but that caused it
to display errors that it couldn't find the drive (?) with the UUID-xxxxx..., eventually, after timing out, it went back to
the default menu page, but it wouldn't accept keyboard input ('c') and I had to 'kill -9 pid' to clear it.

Tried it again with the same result.

The error about not finding the UUID drive had me scared that the system got screwed up and might not reboot,
but it rebooted fine.

Thanks for your suggestion.


That's unfortunate that it didn't work out. It "just worked" for me but then my grub configuration is fairly simple. Perhaps the emu feature is still a work in progress and it doesn't work so well for more complex situations.

I noticed in the Bootloader section of the Gentoo Handbook that they recommend using the --update and --newuse options after GRUB_PLATFORMS has been modified.

Code:
emerge --ask --update --newuse --verbose sys-boot/grub:2


After rebuilding, you can also reinstall grub using the instructions in the Handbook for your situation (BIOS or UEFI). Having said that, grub-emu still might not work and it may not be worth the risk of your system becoming unbootable just to have grub-emu. Like I said, it worked for me but I can certainly understand if you'd rather not play around with this any longer. Using less, grep, and so on is guaranteed to be safe. ;)


Last edited by goldfinch on Tue Jan 03, 2017 5:20 pm; edited 1 time in total
Back to top
View user's profile Send private message
Logicien
Veteran
Veteran


Joined: 16 Sep 2005
Posts: 1324
Location: Montréal

PostPosted: Mon Jan 02, 2017 7:33 pm    Post subject: Reply with quote

With Grub installed in the Mbr of a Dos partitions table, I can see it's menu and can use the keyboard with Qemu. Here Grub2 have been installed in the Mbr of /dev/sda from the root partition /dev/sda2 without any boot partition. So Grub2 is looking for it's file in /dev/sda2
Code:
qemu-system-x86_64 -boot c -drive file=/dev/sda,format=raw,if=scsi,index=0,media=disk

I see the Grub menu the same way as I would see it in real, I can highlight and move in the menu, edit an entry with the e key and go to the Grub2 shell with the c key.

A big warning, do not set any timeout for the default entry to be execute and do not execute any entry manually otherwise, you can corrupt your data.

I think that virtual computing can allow to see how the Grub2 menu look like using it's configuration file /boot/grub/grub.cfg with Grub2 in a virtual machine, live cd/dvd/sd/usb and virtual Linux installation.
_________________
Paul
Back to top
View user's profile Send private message
ak2766
n00b
n00b


Joined: 05 Nov 2017
Posts: 1
Location: Melbourne

PostPosted: Sun Nov 05, 2017 6:17 am    Post subject: Reply with quote

mjbjr wrote:


I had high hopes for this.
...


Apologies on reviving a dead post but I think this post needs a solution for closure.

According to this post on Launchpad [0], input on the grub-emu screen is taken from the terminal window which launched grub-emu - not at all intuitive, unfortunately.

So, for grub-emu to accept your input, you'll need to make sure that the terminal you launched it from has focus.

[0]: https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/759956/comments/7
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum