How To Add Grub Entries Ubuntu 24.04
In Ubuntu 24.04, Grub2 is the default bootloader.
To add custom entries, you’ll need to modify the /etc/default/grub file and the scripts in the /etc/grub.d/ directory.
Here’s a step-by-step guide:
Backup important files:
Before making changes, backup /etc/default/grub and /etc/grub.d/* files using sudo cp /etc/default/grub /etc/grub.d/* /path/to/backup/directory.
Edit /etc/default/grub:
Open the file with a text editor (e.g., sudo nano /etc/default/grub) and add the following lines at the end:
GRUB_CUSTOM_MENUENTRY="Your Custom Menu Entry"
GRUB_DEFAULT="0" # Set the default entry to the new custom one
Replace “Your Custom Menu Entry” with the desired name and description for your custom entry.
Create a new script in /etc/grub.d/: Create a new file (e.g., sudo nano /etc/grub.d/40_custom) and add the following contents:
#!/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 "Your Custom Menu Entry" {
insmod part_msdos
insmod ext2
set root='hd0,msdos1'
linux /boot/vmlinuz-6.8.0-41-generic root=/dev/sda1 ro
initrd /boot/initrd.img-6.8.0-41-generic
}
Replace the kernel and initrd versions with the ones you want to use.
Adjust the set root line to match your partition layout.
Make the script executable: Run sudo chmod +x /etc/grub.d/40_custom to make the script executable.
Update Grub configuration: Run sudo update-grub to rebuild the Grub configuration file (/boot/grub/grub.cfg).
Verify the custom entry: Reboot your system and check the Grub menu to ensure your custom entry is present and functional.
Remember to be cautious when editing system files, and make sure to backup important files before making changes. If you encounter issues, you can restore the original files from your backup directory.