66

So basically I have a pretty flooded Grub bootloader, with older linux versions, 3 operating systems and memtests. What I want is to leave the operating systems only. I need to know how to do it manually, and I need someone to tell me what should I be aware of when a new kernel is released. Thanks in advance.

8 Answers 8

35

Use grub-customizer: https://launchpad.net/grub-customizer

sudo add-apt-repository ppa:danielrichter2007/grub-customizer
sudo apt-get update
sudo apt-get install grub-customizer

This is a GUI that will allow you to hide unwanted grub entries.

This is how the grub-customizer looks like enter image description here

4
  • 2
    Actually this is the tool I started using and am still using it. Gives me all the functionality needed. Changed this to best answer! Sep 17, 2016 at 7:41
  • 2
    Bada bing bada boom! Sep 17, 2016 at 20:11
  • If I am in the unfortunate situation, that I can't boot into my Ubuntu (only getting as far as the grub prompt, presumably for messed up grub entries) - is there a bootable .iso-Image around anbd should I boot from there?
    – Frank N
    May 4, 2018 at 13:18
  • 1
    @FrankNocke I think you want to make a bootable USB and do a grub restore, or something like that. Nov 7, 2018 at 1:19
28

The blog post GRUB2 revisited will provide you with a blow-by-blow set of instructions on how to manually edit GRUB2's configuration files. If you check the other postings in the series (by filtering on Category = GRUB) you will also find information on removing old kernels and what happens when a new kernel arrives as an update. The postings include references to a number of related web sites.

0
21

Rather than edit the grub file directly, you should clean up the kernels you don't want.

Start with this:

dpkg -l | grep linux-image

The update-grub script just makes entries for everything it finds in /boot, as far as I'm aware, so removing old linux-image (and linux-headers) packages via apt-get remove will clean up /boot and therefore clean up your grub config.

This is the "proper" way to do it and hence will require no special action when newer kernels are released in the future, you'll just have to clean up again at some point probably :)

6

Configuring GRUB v2

The configuration file is /boot/grub/grub.cfg, but you shouldn't edit it directly. This file is generated by grub v2's update-grub(8), based on:

The script snippets in /etc/grub.d/

The configuration file /etc/default/grub

To configure grub "v2", you should edit /etc/default/grub, then run update-grub. Advanced configuration are achieved by modifying the snippets in /etc/grub.d/.

taken from Debian configuration.

2
  • 7
    In my opinion, this is not a helpful answer. It doesn't really contain any steps on how to hide/rename/move GRUB menu entries...
    – Byte Commander
    Feb 25, 2016 at 8:21
  • Not an answer to how to edit entries but only where is the file to edit. Apr 29, 2020 at 6:43
5

Run sudo update-grub in terminal so as to include any "forgotten" boot options.

If you don't like command lines, you can open terminal, run sudo nautilus and use your file explorer as root. ;)

Then, still in terminal, goto the folder where the grub configuration file is stored. Usually sudo cd /boot/grub should do the trick, otherwise find your grub configuration file by searching for grub.cfg and change the folder.

GUI: click on DEVICES->COMPUTER->boot->grub or search DEVICES->COMPUTER for file.

Once you have located the folder and opened it, run sudo cp grub.cfg grubOldXX.cfg where XX is a serial numeral of your choice.

GUI: copy paste grub.cfg

Then, run sudo gedit grub.cfg

GUI: right click grub.cfg and choose EDIT

Edit out the entries that you don't want and change your boot order and default boot option as desired (it is straightforward enough). Every menu entry is conveniently preceded by the term menuentry. Delete everything from menuentry all the way up to and including the first closing curly bracket }.

SAVE YOUR FILE and EXIT GEDIT.

IMPORTANT: Messing with grub is an activity which has an enormous possibility of going catastrophically wrong. If your configuration file is messed up your computer simply might not boot.

Always have a DVD with a version of Ubuntu handy (no matter what version). You can always boot from your DVD or other removable media in case you run into problems and, since you saved a copy of your original (working) version, you rename your files reinstating grubOldXX.cfg as grub.cfg.

0

Depending on your grub version, you could use the StartUpManager application to maintain your grub menu. Its Advanced Tab settings allow selecting / deselecting a Memtest / Recovery boot entry and also the number of kernel versions. With grub2, "the Appearance and Advanced tabs contain fewer entries at present, and the Security tab does not exist with Grub 2 fully-installed." (see here, "Grub 2 Note").

enter image description here

3
0

You can boot into the UEFI Shell and issue:

Shell> bcfg boot dump -v
Shell> bcfg boot rm 3
Shell> exit

Source: https://wiki.archlinux.org/title/Unified_Extensible_Firmware_Interface#efibootmgr

-2

Using gedit, edit the grub.cfg file located at /boot/grub.

Remove the one which is not working. For example there are two entries located on different partitions /dev/sda3 and /dev/sda4. You would have to delete from menuentry to } (which means close).

Then press save and voila.

### BEGIN /etc/grub.d/30_os-prober ###
menuentry 'Windows 7 (loader) (on /dev/sda4)' --class windows --class os $menuentry_id_option 'osprober-chain-BABCA4EEBCA4A67B' {
    insmod part_msdos
    insmod ntfs
    set root='hd0,msdos4'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos4 --hint-efi=hd0,msdos4 --hint-baremetal=ahci0,msdos4  BABCA4EEBCA4A67B
    else
      search --no-floppy --fs-uuid --set=root BABCA4EEBCA4A67B
    fi
    chainloader +1
}
menuentry 'Windows 7 (loader) (on /dev/sda3)' --class windows --class os $menuentry_id_option 'osprober-chain-BABCA4EEBCA4A67B' {
    insmod part_msdos
    insmod ntfs
    set root='hd0,msdos4'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos4 --hint-efi=hd0,msdos4 --hint-baremetal=ahci0,msdos4  BABCA4EEBCA4A67B
    else
      search --no-floppy --fs-uuid --set=root BABCA4EEBCA4A67B
    fi
    chainloader +1
}
### END /etc/grub.d/30_os-prober ###

I delete /dev/sda3, after deletion it will look like this

### BEGIN /etc/grub.d/30_os-prober ###
menuentry 'Windows 7 (loader) (on /dev/sda4)' --class windows --class os $menuentry_id_option 'osprober-chain-BABCA4EEBCA4A67B' {
    insmod part_msdos
    insmod ntfs
    set root='hd0,msdos4'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos4 --hint-efi=hd0,msdos4 --hint-baremetal=ahci0,msdos4  BABCA4EEBCA4A67B
    else
      search --no-floppy --fs-uuid --set=root BABCA4EEBCA4A67B
    fi
    chainloader +1
}
### END /etc/grub.d/30_os-prober ###
1
  • 3
    The file is automatically created with each upgrade of the kernel or when running update-grub, why should you edit it manually?
    – Braiam
    Mar 23, 2014 at 14:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .