38

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

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

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

  • Actually this is the tool I started using and am still using it. Gives me all the functionality needed. Changed this to best answer! – Shahe Tajiryan Sep 17 '16 at 7:41
  • Bada bing bada boom! – wordsforthewise Sep 17 '16 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 Nocke May 4 '18 at 13:18
  • @FrankNocke I think you want to make a bootable USB and do a grub restore, or something like that. – wordsforthewise Nov 7 '18 at 1:19
25

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.

  • 1
    This is exactly what I needed. Thanks mate. – Shahe Tajiryan Nov 22 '11 at 17:59
17

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 :)

3

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.

  • 3
    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 '16 at 8:21
3

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.

1

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

-1

I install Kali on my Mac and using rEfind as a grub loader.But mounting grub to the wrong /dev/sdaX, so in the end I got 2 grub entry and 1 is not working, led me to the grub rescue.

After trying all commands to remove it unsuccessfully, I go to the Mac utility manager to delete the biogrub partition which is not working. Vola, now only left the workable one.

May need to go terminal to type update-grub.

-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 ###
  • 2
    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 '14 at 14:02

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.