Manually adding/removing entries to Grub 2 Menu

This post was written by admin on November 9, 2009
Posted Under: General

Grub 2 Menu entries can be added to grub.cfg automatically or manually,and grub.cfg is updated when update-grub is run.
Manually adding entries to Grub 2

Entries to grub.cfg can be manually inserted by creating a file in the /etc/grub.d folder.

  • The name of the file determines the order in the menu. 30_os-prober entries will be placed before 40_custom entries, which will be placed before 50_my-sample entries.
  • Any created file must be made executable. This can be done as root by running “sudo chmod +x /etc/grub.d/filename“.
  • The files in the /etc/grub.d folder will be read and the contents included in grub.cfg when the “update-grub2” command is executed as root.

A sample entry. This file creates a menu item for running the SystemRescueCD (previously installed) from a partition created on sda10. Folders and files must have been copied to the correct location in accordance with the SystemRescueCD if you wish to actually use this entry.

Quote:

#!/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.
echo "Adding SystemRescueCD" >&2
menuentry "System Rescue CD" {
set root=(hd0,10)
linux   /sysrcd/rescuecd subdir=sysrcd setkmap=us
initrd  /sysrcd/initram.igz
}

Tip: If you want to have your custom entries at the top of the menu (say you want custom titles), create a new file and name it “07_xxxx”. Since the files in /etc/grub.d/ are read sequentially, those in “07_custom” will be placed before those of “10_linux”. I recommend not naming a custom menu file lower than 06 so that any theme run from 05_debian_theme is allowed to run before any custom menu is created. After creating the file, run sudo update-grub and then check the value of “DEFAULT” in /etc/default/grub. If it doesn’t point to the correct menuentry, change the value of DEFAULT to the correct menuentry value.
Removing entries
* To remove a user-created menu entry, remove the applicable file from the /etc/grub.d folder.
* If a custom file contains multiple entries, individual items may be removed and others retained.
* Once the file has been removed or edited, run “update-grub2″ to update grub.cfg.

Read: Original text

Related posts:

  1. New Grub Customizer with default OS/background/menu colors/resolution support
  2. Clean up Ubuntu old grub boot menu after upgrades
  3. How to setup Boot password protection for Grub2 Entries
  4. Boot up ubuntu directly without loading grub menu
  5. Change the Grub menu timeout in ubuntu

    Tags:

    Reader Comments

    That’s a good example on manually adding an entry for another linux system. How would I add a manual entry for a windows partition? Right now grub2 has found 2 entries, –> Windows Vista Bootloader (and) Linux Mint. I have to go into the WV Bootloader to get to Win XP. How can I manually add an entry to grub2 to load Win XP? Thanks.

    [Reply]

    #1 
    Written By Frank Furt on November 28th, 2010 @ 8:14 pm

    Great example, except for one tiny thing:

    In Ubuntu 10.04, they’ve changed what goes where – for example there is no longer a 10_linux entry.

    IMHO, whoever came up with the absolutely *BRILLIANT* idea of using a BETA boot loader for Ubuntu, should be the first against the wall when the revolution comes!

    Grub2 resurrects everything that was universally hated and despised in LILO.

    What say ye?

    Jim

    [Reply]

    #2 
    Written By Jim (JR) on March 16th, 2011 @ 9:14 am

    Add a Comment

    required, use real name
    required, will not be published
    optional, your blog address