Is it possible to edit grub.cfg?
I wish to change a menu entry in grub.cfg, for example:
From
### BEGIN /etc/grub.d/10_linux ###
menuentry 'Ubuntu is wonderful'
To
### BEGIN /etc/grub.d/10_linux ###
menuentry 'Ubuntu is world famous'
Solution 1:
Edit /etc/grub.d/10_linux
instead and run sudo update-grub
when you are done. This is a more reliable method, otherwise every time you upgrade to a new kernel your /boot/grub/grub.cfg
will be overwritten and you will lose your changes.
Or you can use Grub Customizer. To install it:
sudo add-apt-repository ppa:danielrichter2007/grub-customizer
sudo apt-get update
sudo apt-get install grub-customizer
Solution 2:
How to do it from an emulator to learn how GRUB works, without the risk of breaking anything.
create a Multiboot hello world
main.elf
file. GRUB knows how to boot those files (GRUB also knows how to boot the Linux kernel, even though it is not Multiboot)-
create a
iso/boot/grub/grub.cfg
file containing:menuentry "main" { multiboot /boot/main.elf }
Place
main.elf
underiso/boot/
-
Generate an image and run it:
grub-mkrescue -o main.img iso qemu-system-x86_64 -hda main.img
This will boot into GRUB, and you will see an entry called main
.
Now edit grub.cfg
like menuentry "newmain"
, and upon a reboot the new option name is newmain
. So your change would work.
I have posted the exact code for this example at: https://github.com/cirosantilli/x86-bare-metal-examples/tree/d217b180be4220a0b4a453f31275d38e697a99e0/multiboot/hello-world
As others said, don't do it in practice, since that is normally an output file and will get overwritten on update-grub
.