Skip to content

Instantly share code, notes, and snippets.

@drmalex07
Last active February 5, 2023 10:24
Show Gist options
  • Save drmalex07/e9c44b9760b19c6211bc to your computer and use it in GitHub Desktop.
Save drmalex07/e9c44b9760b19c6211bc to your computer and use it in GitHub Desktop.
Create custom GRUB2 menu entries. #grub #grub2 #linux

The auto-generated (during OS installation) menu entries are placed at /boot/grub/grub.cfg. These entries can be used as a starting point for creating new menu entries. Roughly, the process is as follows:

Edit /etc/grub.d/40_custom and provide your menu entries. For example, say we want to provide an alternative way to initialize our debian system via systemd:

#!/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 'Debian GNU/Linux, with Linux 3.2.0-4-amd64 (systemd)' {
	load_video
	insmod gzio
	insmod part_msdos
	insmod ext2
	set root='(/dev/sda,msdos1)'
	search --no-floppy --fs-uuid --set=root b1ef2365-c1c9-4887-8f1e-2a7334b7d8cd
	echo	'Loading Linux 3.2.0-4-amd64 ...'
	linux	/boot/vmlinuz-3.2.0-4-amd64 root=UUID=b1ef2365-c1c9-4887-8f1e-2a7334b7d8cd ro init=/bin/systemd
	echo	'Loading initial ramdisk ...'
	initrd	/boot/initrd.img-3.2.0-4-amd64
}

Now, we must update (re-generate) our /boot/grub/grub.cfg file:

update-grub

Install grub to target device (usually the MBR of our 1st disk), say /dev/sda:

grub-install /dev/sda

Reboot!

Find more detailed info at https://help.ubuntu.com/community/Grub2/CustomMenus

@quant61
Copy link

quant61 commented Feb 5, 2023

Is it possible to reuse default config and add some params instead of writing everything manually?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment