Page 3 of 4

Re: How do you edit the grub menu by hand?

Posted: Tue Dec 03, 2024 11:24 pm
by asqwerth
If your custom.cfg entries are at the end of normal grub entries, did you remember to renumber 41_custom?

Re: How do you edit the grub menu by hand?

Posted: Wed Dec 04, 2024 9:24 am
by siamhie
asqwerth wrote: Tue Dec 03, 2024 11:17 pm No. No update grub needed. EVER. The custom.cfg file is just a list of grub entries. No scripting bits.

I mean, I gave you the whole contents of the custom.cfg for you to copy and paste quite a few posts ago.

I had gotten that but cleaned up the menuentries.

Code: Select all

menuentry 'fluxbox, with Linux 6.6.63-x64v3-xanmod1 (systemd)'
to

Code: Select all

menuentry 'Fluxbox-6.6'

Re: How do you edit the grub menu by hand?

Posted: Wed Dec 04, 2024 9:44 am
by siamhie
asqwerth wrote: Tue Dec 03, 2024 11:24 pm If your custom.cfg entries are at the end of normal grub entries, did you remember to renumber 41_custom?

@asqwerth I had actually created a /boot/grub/custom.cfg file with those three entries and let 41_custom do it's thing.

Code: Select all

#!/bin/sh
cat <<EOF
if [ -f  \${config_directory}/custom.cfg ]; then
  source \${config_directory}/custom.cfg
elif [ -z "\${config_directory}" -a -f  \$prefix/custom.cfg ]; then
  source \$prefix/custom.cfg;
fi
EOF
I still end up with the new entries at the bottom of the grub screen.
new-grub-menu.jpg

I have now copied the contents of /boot/grub/custom.cfg to /etc/grub.d/40_custom and deleted the /boot/grub/custom.cfg file.


One thing I did notice is that MX Boot Options never picked up on the /boot/grub/custom.cfg file but since I transferred those entries to 40_custom, MXBO picks them up.
mxbo.jpg


I will now try your earlier suggestion to rename 40_custom to 09_custom and it should put my entries at the beginning.

Re: How do you edit the grub menu by hand?

Posted: Wed Dec 04, 2024 9:54 am
by asqwerth
If you copy the menu items to 40_custom, then you NEED to update-grub every time you change the contents of 40_custom. It just doesn't work the same way as 41_custom + the custom.cfg file.

Script numbers 40 and 41 do things differently.

Things in custom.cfg won't be picked up by grub or MX boot options because it's not part of grub.cfg. It's just a separate list of custom entries from grub.cfg, that 41_custom script can detect and tag on to the grub menu. If you renumber 41 to 09, then the script adds it before the grub.cfg entries, otherwise the custom.cfg entries are tagged on after the grub.cfg entries.

40_custom is different. For this script, you are SUPPOSED to add the custom entries to ths 40_custom file itself, and then update-grub. That way, it is seen together with grub.cfg. I guess you can try renumbering it as 09 and see what happens.

I don't use 40_custom on my system because I don't want to update-grub all the time

Re: How do you edit the grub menu by hand?

Posted: Wed Dec 04, 2024 10:09 am
by siamhie
asqwerth wrote: Wed Dec 04, 2024 9:54 am If you copy the menu items to 40_custom, then you NEED to update-grub every time you change the contents of 40_custom. It just doesn't work the same way as 41_custom + the custom.cfg file.

Script numbers 40 and 41 do things differently.

Things in custom.cfg won't be picked up by grub or MX boot options because it's not part of grub.cfg. It's just a separate list of custom entries from grub.cfg, that 41_custom script can detect and tag on to the grub menu. If you renumber 41 to 09, then the script adds it before the grub.cfg entries, otherwise the custom.cfg entries are tagged on after the grub.cfg entries.

40_custom is different. For this script, you are SUPPOSED to add the custom entries to ths 40_custom file itself, and then update-grub. That way, it is seen together with grub.cfg. I guess you can try renumbering it as 09 and see what happens.

I don't use 40_custom on my system because I don't want to update-grub all the time

I only update grub when Xanmod releases a new 6.6 LTS kernel they have grabbed from the archives.
Debian's 6.1 LTS kernel doesn't get updated often which is my backup kernel for fluxbox and main kernel for XFCE.

So the only entry I would have to edit the most is this one.

Code: Select all

menuentry 'Fluxbox-6.6' --class fluxbox --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-6.6.63-x64v3-xanmod1-init-systemd-20cfcd8f-3e81-49d4-a5f4-35784be52c3f' {
	load_video
	insmod gzio
	if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
	insmod part_gpt
	insmod ext2
	search --no-floppy --fs-uuid --set=root 20cfcd8f-3e81-49d4-a5f4-35784be52c3f
	echo	'Loading Linux 6.6.63-x64v3-xanmod1 ...'
	linux	/boot/vmlinuz-6.6.63-x64v3-xanmod1 root=UUID=20cfcd8f-3e81-49d4-a5f4-35784be52c3f ro  quiet init=/lib/systemd/systemd
	echo	'Loading initial ramdisk ...'
	initrd	/boot/initrd.img-6.6.63-x64v3-xanmod1
}

Re: How do you edit the grub menu by hand?

Posted: Wed Dec 04, 2024 11:35 am
by siamhie
I suppose this will be as close to a custom grub menu with only three entries showing as I will get.
At least they are at the top now.

close-to-three.jpg

Re: How do you edit the grub menu by hand?

Posted: Wed Dec 04, 2024 2:13 pm
by fehlix
To be honest, not only did the title of the topic lead to confusing
assumptions right from the start, but now the adjustments you have made
are causing even more confusion (at least for me).

May I suggest the following: Just rephrase what you are trying to
accomplish, and post all the relevant changes you have made so far, I
mean the files you have customized. Otherwise, I don't think I can give
any more tips without fear of adding to the confusion.

Re: How do you edit the grub menu by hand?  [Solved]

Posted: Wed Dec 04, 2024 4:30 pm
by siamhie
fehlix wrote: Wed Dec 04, 2024 2:13 pm To be honest, not only did the title of the topic lead to confusing
assumptions right from the start, but now the adjustments you have made
are causing even more confusion (at least for me).

I apologize for the confusion the thread has turned into. The title of the thread was editing grub by hand and this is what I started my post with.
siamhie wrote: Tue Dec 03, 2024 12:50 am (I don't want to go back to Grub Customizer)

I have the menu set up in flat mode currently and (through this forum) found how to edit the names of the entries to make it easier to find them.


What I would like to do is have just three entries showing in this order.

Fluxbox-6.6
(this menuentry 'fluxbox, with Linux 6.6.63-x64v3-xanmod1 (systemd))

XFCE-6.1
(this menuentry 'XFCE, with Linux 6.1.0-28-amd64 (systemd))

Fluxbox-6.1
(this fluxbox, with Linux 6.1.0-28-amd64 (systemd))

So to sum up what I have done is this.

1. copied the contents of /boot/grub/custom.cfg to /etc/grub.d/40_custom and saved the 40_custom file as 09_custom

Code: Select all

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
menuentry 'Fluxbox-6.6' --class fluxbox --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-6.6.63-x64v3-xanmod1-init-systemd-20cfcd8f-3e81-49d4-a5f4-35784be52c3f' {
	load_video
	insmod gzio
	if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
	insmod part_gpt
	insmod ext2
	search --no-floppy --fs-uuid --set=root 20cfcd8f-3e81-49d4-a5f4-35784be52c3f
	echo	'Loading Linux 6.6.63-x64v3-xanmod1 ...'
	linux	/boot/vmlinuz-6.6.63-x64v3-xanmod1 root=UUID=20cfcd8f-3e81-49d4-a5f4-35784be52c3f ro  quiet init=/lib/systemd/systemd
	echo	'Loading initial ramdisk ...'
	initrd	/boot/initrd.img-6.6.63-x64v3-xanmod1
}
menuentry 'XFCE-6.1' --class gnu-linux --class gnu --class os $menuentry_id_option 'osprober-gnulinux-/boot/vmlinuz-6.1.0-28-amd64--471fd16c-b914-4193-8af6-42bc4fed4954' {
		insmod part_gpt
		insmod ext2
		search --no-floppy --fs-uuid --set=root 471fd16c-b914-4193-8af6-42bc4fed4954
		linux /boot/vmlinuz-6.1.0-28-amd64 root=UUID=471fd16c-b914-4193-8af6-42bc4fed4954 ro quiet splash init=/lib/systemd/systemd
		initrd /boot/initrd.img-6.1.0-28-amd64
}
menuentry 'Fluxbox-6.1' --class fluxbox --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-6.1.0-28-amd64-init-systemd-20cfcd8f-3e81-49d4-a5f4-35784be52c3f' {
	load_video
	insmod gzio
	if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
	insmod part_gpt
	insmod ext2
	search --no-floppy --fs-uuid --set=root 20cfcd8f-3e81-49d4-a5f4-35784be52c3f
	echo	'Loading Linux 6.1.0-28-amd64 ...'
	linux	/boot/vmlinuz-6.1.0-28-amd64 root=UUID=20cfcd8f-3e81-49d4-a5f4-35784be52c3f ro  quiet init=/lib/systemd/systemd
	echo	'Loading initial ramdisk ...'
	initrd	/boot/initrd.img-6.1.0-28-amd64
}

2. deleted /boot/grub/custom.cfg
3. updated grub and my three custom entries were now at the top of every thing else

The next steps I did might not be right or correct but it worked (for my scenario)

4. removed the executable permissions from 10_linux, 20_linux_xen, 20_memtest86+,
30_os-prober, 30_uefi-firmware, 40_custom and 41_custom
5. updated grub


Now I have just the three entries I wanted showing and I can choose which one to be default in MX Boot Options.

My newly generated grub.cfg file

Code: Select all

#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  set have_grubenv=true
  load_env
fi
if [ "${next_entry}" ] ; then
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
else
   set default="0"
fi

if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
fi

export menuentry_id_option

if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}
function load_video {
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
}

if [ x$feature_default_font_path = xy ] ; then
   font=unicode
else
insmod part_gpt
insmod ext2
search --no-floppy --fs-uuid --set=root 20cfcd8f-3e81-49d4-a5f4-35784be52c3f
    font="/usr/share/grub/unicode.pf2"
fi

if loadfont $font ; then
  set gfxmode=1024x768
  load_video
  insmod gfxterm
  set locale_dir=$prefix/locale
  set lang=en_US
  insmod gettext
fi
terminal_output gfxterm
insmod part_gpt
insmod ext2
search --no-floppy --fs-uuid --set=root 20cfcd8f-3e81-49d4-a5f4-35784be52c3f
insmod gfxmenu
loadfont ($root)/boot/grub/themes/mx_logo_ribbon/DejaVuSans-Bold14.pf2
loadfont ($root)/boot/grub/themes/mx_logo_ribbon/DejaVuSans10.pf2
loadfont ($root)/boot/grub/themes/mx_logo_ribbon/DejaVuSans12.pf2
loadfont ($root)/boot/grub/themes/mx_logo_ribbon/ascii.pf2
insmod png
set theme=($root)/boot/grub/themes/mx_logo_ribbon/theme.txt
export theme
if [ "${recordfail}" = 1 ] ; then
  set timeout=30
else
  if [ x$feature_timeout_style = xy ] ; then
    set timeout_style=menu
    set timeout=3
  # Fallback normal timeout code in case the timeout_style feature is
  # unavailable.
  else
    set timeout=3
  fi
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/05_debian_theme ###
set menu_color_normal=cyan/blue
set menu_color_highlight=white/blue
### END /etc/grub.d/05_debian_theme ###

### BEGIN /etc/grub.d/09_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
menuentry 'Fluxbox-6.6' --class fluxbox --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-6.6.63-x64v3-xanmod1-init-systemd-20cfcd8f-3e81-49d4-a5f4-35784be52c3f' {
	load_video
	insmod gzio
	if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
	insmod part_gpt
	insmod ext2
	search --no-floppy --fs-uuid --set=root 20cfcd8f-3e81-49d4-a5f4-35784be52c3f
	echo	'Loading Linux 6.6.63-x64v3-xanmod1 ...'
	linux	/boot/vmlinuz-6.6.63-x64v3-xanmod1 root=UUID=20cfcd8f-3e81-49d4-a5f4-35784be52c3f ro  quiet init=/lib/systemd/systemd
	echo	'Loading initial ramdisk ...'
	initrd	/boot/initrd.img-6.6.63-x64v3-xanmod1
}
menuentry 'XFCE-6.1' --class gnu-linux --class gnu --class os $menuentry_id_option 'osprober-gnulinux-/boot/vmlinuz-6.1.0-28-amd64--471fd16c-b914-4193-8af6-42bc4fed4954' {
		insmod part_gpt
		insmod ext2
		search --no-floppy --fs-uuid --set=root 471fd16c-b914-4193-8af6-42bc4fed4954
		linux /boot/vmlinuz-6.1.0-28-amd64 root=UUID=471fd16c-b914-4193-8af6-42bc4fed4954 ro quiet splash init=/lib/systemd/systemd
		initrd /boot/initrd.img-6.1.0-28-amd64
}
menuentry 'Fluxbox-6.1' --class fluxbox --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-6.1.0-28-amd64-init-systemd-20cfcd8f-3e81-49d4-a5f4-35784be52c3f' {
	load_video
	insmod gzio
	if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
	insmod part_gpt
	insmod ext2
	search --no-floppy --fs-uuid --set=root 20cfcd8f-3e81-49d4-a5f4-35784be52c3f
	echo	'Loading Linux 6.1.0-28-amd64 ...'
	linux	/boot/vmlinuz-6.1.0-28-amd64 root=UUID=20cfcd8f-3e81-49d4-a5f4-35784be52c3f ro  quiet init=/lib/systemd/systemd
	echo	'Loading initial ramdisk ...'
	initrd	/boot/initrd.img-6.1.0-28-amd64
}
### END /etc/grub.d/09_custom ###

MX Boot Options
simple.png

Grub Screen
simpler.jpg

Re: How do you edit the grub menu by hand?

Posted: Wed Dec 04, 2024 4:45 pm
by fehlix
OK, thanks.
The picture got now a bit clearer.
So what you want, is disable generation of grub menu entries, and have your own. OK fine.
And you would need manually adjust the grub menu after every kernel upgrade, or removal
Probably one way to go, but that not what I would recommend in general to do.
Anyway, good luck.

Re: How do you edit the grub menu by hand?

Posted: Wed Dec 04, 2024 5:16 pm
by fehlix
siamhie wrote: Wed Dec 04, 2024 4:30 pm

Code: Select all

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
menuentry 'Fluxbox-6.6' --class fluxbox --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-6.6.63-x64v3-xanmod1-init-systemd-20cfcd8f-3e81-49d4-a5f4-35784be52c3f' {
	load_video
	insmod gzio
	if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
	insmod part_gpt
	insmod ext2
	search --no-floppy --fs-uuid --set=root 20cfcd8f-3e81-49d4-a5f4-35784be52c3f
	echo	'Loading Linux 6.6.63-x64v3-xanmod1 ...'
	linux	/boot/vmlinuz-6.6.63-x64v3-xanmod1 root=UUID=20cfcd8f-3e81-49d4-a5f4-35784be52c3f ro  quiet init=/lib/systemd/systemd
	echo	'Loading initial ramdisk ...'
	initrd	/boot/initrd.img-6.6.63-x64v3-xanmod1
}
menuentry 'XFCE-6.1' --class gnu-linux --class gnu --class os $menuentry_id_option 'osprober-gnulinux-/boot/vmlinuz-6.1.0-28-amd64--471fd16c-b914-4193-8af6-42bc4fed4954' {
		insmod part_gpt
		insmod ext2
		search --no-floppy --fs-uuid --set=root 471fd16c-b914-4193-8af6-42bc4fed4954
		linux /boot/vmlinuz-6.1.0-28-amd64 root=UUID=471fd16c-b914-4193-8af6-42bc4fed4954 ro quiet splash init=/lib/systemd/systemd
		initrd /boot/initrd.img-6.1.0-28-amd64
}
menuentry 'Fluxbox-6.1' --class fluxbox --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-6.1.0-28-amd64-init-systemd-20cfcd8f-3e81-49d4-a5f4-35784be52c3f' {
	load_video
	insmod gzio
	if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
	insmod part_gpt
	insmod ext2
	search --no-floppy --fs-uuid --set=root 20cfcd8f-3e81-49d4-a5f4-35784be52c3f
	echo	'Loading Linux 6.1.0-28-amd64 ...'
	linux	/boot/vmlinuz-6.1.0-28-amd64 root=UUID=20cfcd8f-3e81-49d4-a5f4-35784be52c3f ro  quiet init=/lib/systemd/systemd
	echo	'Loading initial ramdisk ...'
	initrd	/boot/initrd.img-6.1.0-28-amd64
}
To avoid a potential issue, with booting into latest installed kernel,
e.g. just after kernel upgrade, and you missed manually adjusting the grub menu:
You may try this menuentry, potentially to be put on top,
e.g. as an example for fluxbox:

Code: Select all

menuentry 'Fluxbox latest kernel installed' --class fluxbox --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-latest-installed-init-systemd-20cfcd8f-3e81-49d4-a5f4-35784be52c3f' {
	load_video
	insmod gzio
	if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
	insmod part_gpt
	insmod ext2
	search --no-floppy --fs-uuid --set=root 20cfcd8f-3e81-49d4-a5f4-35784be52c3f
	echo	'Loading Linux latest installed ...'
	linux	/vmlinuz root=UUID=20cfcd8f-3e81-49d4-a5f4-35784be52c3f ro  quiet init=/lib/systemd/systemd
	echo	'Loading initial ramdisk ...'
	initrd	/initrd.img
}
The difference is , latest kernel installation creates alway two symlinks /vmlinuz and /initrd.img:
E.g in the example above as:

Code: Select all

/vmlinux  -> boot/vmlinuz-6.6.63-x64v3-xanmod1
/initrd.img -> boot/initrd.img-6.6.63-x64v3-xanmod1
As those symlinks are relative symlinks, you can use it as booting into latest installed.
Similar would be, /vmlinuz.old and /initrd.img.old pointing to the one which was previous the latest.